diff --git a/src/Spring/Spring.Core/Core/MethodGenericArgumentsCountCriteria.cs b/src/Spring/Spring.Core/Core/MethodGenericArgumentsCountCriteria.cs index 3cd57932..4f686b18 100644 --- a/src/Spring/Spring.Core/Core/MethodGenericArgumentsCountCriteria.cs +++ b/src/Spring/Spring.Core/Core/MethodGenericArgumentsCountCriteria.cs @@ -69,8 +69,8 @@ namespace Spring.Core /// The number of generic arguments that a /// must have to satisfy this criteria. /// - /// - /// If the supplied is less + /// + /// If the supplied is less /// than zero. /// public MethodGenericArgumentsCountCriteria(int expectedGenericArgumentCount) diff --git a/src/Spring/Spring.Core/Objects/Factory/Config/VariableAccessor.cs b/src/Spring/Spring.Core/Objects/Factory/Config/VariableAccessor.cs index bacc5174..f4d5829f 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Config/VariableAccessor.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Config/VariableAccessor.cs @@ -1,791 +1,791 @@ -#region Licence - -/* - * Copyright © 2002-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#endregion - -#region Imports - -using System; -using System.Globalization; -using Spring.Objects.Factory.Config; -using Spring.Util; - -#endregion - -namespace Spring.Objects.Factory.Config -{ - /// - /// Provides methods for type-safe accessing s. - /// - /// Erich Eichinger - public class VariableAccessor - { - private readonly IVariableSource variableSource; - - /// - /// Initialize a new instance of an - /// - /// The underlying to read values from. - public VariableAccessor(IVariableSource variableSource) - { - this.variableSource = variableSource; - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public float GetFloat(string name, float defaultValue) - { - return GetFloat(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public float GetFloat(string name, float defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return float.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public double GetDouble(string name, double defaultValue) - { - return GetDouble(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public double GetDouble(string name, double defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return double.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public decimal GetDecimal(string name, decimal defaultValue) - { - return GetDecimal(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public decimal GetDecimal(string name, decimal defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return decimal.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public long GetInt64(string name, long defaultValue) - { - return GetInt64(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public long GetInt64(string name, long defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return Int64.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public ulong GetUInt64(string name, ulong defaultValue) - { - return GetUInt64(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public ulong GetUInt64(string name, ulong defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return UInt64.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public int GetInt32(string name, int defaultValue) - { - return GetInt32(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public int GetInt32(string name, int defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return Int32.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public uint GetUInt32(string name, uint defaultValue) - { - return GetUInt32(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public uint GetUInt32(string name, uint defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return UInt32.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public short GetInt16(string name, short defaultValue) - { - return GetInt16(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public short GetInt16(string name, short defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return Int16.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public ushort GetUInt16(string name, ushort defaultValue) - { - return GetUInt16(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public ushort GetUInt16(string name, ushort defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return UInt16.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public byte GetByte(string name, byte defaultValue) - { - return GetByte(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public byte GetByte(string name, byte defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return byte.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public Guid GetGuid(string name, Guid defaultValue) - { - return GetGuid(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public Guid GetGuid(string name, Guid defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return new Guid(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The expected format of the variable's value - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public DateTime GetDateTime(string name, string format, DateTime defaultValue) - { - return GetDateTime(name, format, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The expected format of the variable's value - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public DateTime GetDateTime(string name, string format, DateTime defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - if (format == null) - { - return DateTime.Parse(text); - } - else - { - return DateTime.ParseExact(text, format, CultureInfo.InvariantCulture); - } - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public char GetChar(string name, char defaultValue) - { - return GetChar(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public char GetChar(string name, char defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - if (text.Length != 1) - { - throw new ArgumentException("string '{0}' can't be converted to char", text); - } - return text[0]; - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public bool GetBoolean(string name, bool defaultValue) - { - return GetBoolean(name, defaultValue, true); - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// A that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public bool GetBoolean(string name, bool defaultValue, bool throwOnInvalidValue) - { - try - { - string text = GetString(name, defaultValue.ToString()); - return bool.Parse(text); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns an of type that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// An of type that contains the value of the specified variable - /// or , if returns null. - /// - public Enum GetEnum(string name, Enum defaultValue) - { - return GetEnum(name, defaultValue, true); - } - - /// - /// Returns an of type that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns null. - /// - /// If false, suppresses exceptions if the result - /// of cannot be parsed - /// and returns instead. - /// - /// An of type that contains the value of the specified variable - /// or , if cannot be parsed. - /// - public Enum GetEnum(string name, Enum defaultValue, bool throwOnInvalidValue) - { - try - { - return (Enum)Enum.Parse(defaultValue.GetType(), GetString(name, defaultValue.ToString()), true); - } - catch - { - if (throwOnInvalidValue) - { - throw; - } - else - { - return defaultValue; - } - } - } - - /// - /// Returns a that contains the value of the specified variable. - /// - /// The name of the variable to be read. - /// The value to be returned if returns or . - /// - /// A that contains the value of the specified variable - /// or , if returns null. - /// - public string GetString(string name, string defaultValue) - { - string value = null; - if (variableSource != null && variableSource.CanResolveVariable(name)) +#region Licence + +/* + * Copyright © 2002-2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +#region Imports + +using System; +using System.Globalization; +using Spring.Objects.Factory.Config; +using Spring.Util; + +#endregion + +namespace Spring.Objects.Factory.Config +{ + /// + /// Provides methods for type-safe accessing s. + /// + /// Erich Eichinger + public class VariableAccessor + { + private readonly IVariableSource variableSource; + + /// + /// Initialize a new instance of an + /// + /// The underlying to read values from. + public VariableAccessor(IVariableSource variableSource) + { + this.variableSource = variableSource; + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public float GetFloat(string name, float defaultValue) + { + return GetFloat(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public float GetFloat(string name, float defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return float.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public double GetDouble(string name, double defaultValue) + { + return GetDouble(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public double GetDouble(string name, double defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return double.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public decimal GetDecimal(string name, decimal defaultValue) + { + return GetDecimal(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public decimal GetDecimal(string name, decimal defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return decimal.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public long GetInt64(string name, long defaultValue) + { + return GetInt64(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public long GetInt64(string name, long defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return Int64.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public ulong GetUInt64(string name, ulong defaultValue) + { + return GetUInt64(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public ulong GetUInt64(string name, ulong defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return UInt64.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public int GetInt32(string name, int defaultValue) + { + return GetInt32(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public int GetInt32(string name, int defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return Int32.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public uint GetUInt32(string name, uint defaultValue) + { + return GetUInt32(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public uint GetUInt32(string name, uint defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return UInt32.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public short GetInt16(string name, short defaultValue) + { + return GetInt16(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public short GetInt16(string name, short defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return Int16.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public ushort GetUInt16(string name, ushort defaultValue) + { + return GetUInt16(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public ushort GetUInt16(string name, ushort defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return UInt16.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public byte GetByte(string name, byte defaultValue) + { + return GetByte(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public byte GetByte(string name, byte defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return byte.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public Guid GetGuid(string name, Guid defaultValue) + { + return GetGuid(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public Guid GetGuid(string name, Guid defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return new Guid(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The expected format of the variable's value + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public DateTime GetDateTime(string name, string format, DateTime defaultValue) + { + return GetDateTime(name, format, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The expected format of the variable's value + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public DateTime GetDateTime(string name, string format, DateTime defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + if (format == null) + { + return DateTime.Parse(text); + } + else + { + return DateTime.ParseExact(text, format, CultureInfo.InvariantCulture); + } + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public char GetChar(string name, char defaultValue) + { + return GetChar(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public char GetChar(string name, char defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + if (text.Length != 1) + { + throw new ArgumentException("string '{0}' can't be converted to char", text); + } + return text[0]; + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public bool GetBoolean(string name, bool defaultValue) + { + return GetBoolean(name, defaultValue, true); + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// A that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public bool GetBoolean(string name, bool defaultValue, bool throwOnInvalidValue) + { + try + { + string text = GetString(name, defaultValue.ToString()); + return bool.Parse(text); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns an of 's type that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// An of 's type that contains the value of the specified variable + /// or , if returns null. + /// + public Enum GetEnum(string name, Enum defaultValue) + { + return GetEnum(name, defaultValue, true); + } + + /// + /// Returns an of 's type that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns null. + /// + /// If false, suppresses exceptions if the result + /// of cannot be parsed + /// and returns instead. + /// + /// An of 's type that contains the value of the specified variable + /// or , if cannot be parsed. + /// + public Enum GetEnum(string name, Enum defaultValue, bool throwOnInvalidValue) + { + try + { + return (Enum)Enum.Parse(defaultValue.GetType(), GetString(name, defaultValue.ToString()), true); + } + catch + { + if (throwOnInvalidValue) + { + throw; + } + else + { + return defaultValue; + } + } + } + + /// + /// Returns a that contains the value of the specified variable. + /// + /// The name of the variable to be read. + /// The value to be returned if returns or . + /// + /// A that contains the value of the specified variable + /// or , if returns null. + /// + public string GetString(string name, string defaultValue) + { + string value = null; + if (variableSource != null && variableSource.CanResolveVariable(name)) { value = variableSource.ResolveVariable(name); - } - - if (!StringUtils.HasLength(value)) - { - return defaultValue; - } - - return value; - } - } + } + + if (!StringUtils.HasLength(value)) + { + return defaultValue; + } + + return value; + } + } } \ No newline at end of file diff --git a/src/Spring/Spring.Web/DataBinding/DataSourceItemFormatter.cs b/src/Spring/Spring.Web/DataBinding/DataSourceItemFormatter.cs index ad80c4c9..b3053c44 100644 --- a/src/Spring/Spring.Web/DataBinding/DataSourceItemFormatter.cs +++ b/src/Spring/Spring.Web/DataBinding/DataSourceItemFormatter.cs @@ -107,7 +107,7 @@ namespace Spring.DataBinding /// Return the object with the specified key from the datasource. /// /// The key of the object. - /// Parsed . + /// Parsed . public object Parse(string key) { object item = this._dataItemsByKey[key]; diff --git a/src/Spring/Spring.Web/Web/Support/Result.cs b/src/Spring/Spring.Web/Web/Support/Result.cs index 39e036b7..4f5b9648 100644 --- a/src/Spring/Spring.Web/Web/Support/Result.cs +++ b/src/Spring/Spring.Web/Web/Support/Result.cs @@ -146,7 +146,7 @@ namespace Spring.Web.Support ///

/// See both the class documentation () /// and the reference documentation for the Spring.Web library for a - /// discussion and examples of what values the supplied + /// discussion and examples of what values the supplied /// can have. ///

///