src/Misc/EFTools/XmlCore/Model/DefaultableValue.cs
/// <summary>
///     This method converts the contents of the XAttribute into an object of the passed
///     in type.  This is mainly done using the casting capabilities of the XAttribute class.
/// </summary>
/// <param name="attrValue">The string passed here should be decoded as needed.</param>
/// <param name="attribute">The XAttribute to read</param>
/// <param name="objectType">The type of object to return</param>
/// <returns></returns>
This method converts the contents of the XAttribute into an object of the passed
in type.  This is mainly done using the casting capabilities of the XAttribute class.
This method converts the contents of the XAttribute into an object of the passed in type . This is mainly done using the casting capabilities of the XAttribute class .
protected static object ConvertToType(string stringVal, XAttribute attribute, Type objectType)
        {
            object result = null;
            if (objectType == typeof(int))
            {
                result = (int)attribute;
            }
            else if (objectType == typeof(uint))
            {
                result = (uint)attribute;
            }
            else if (objectType == typeof(uint?))
            {
                result = (uint?)attribute;
            }
            else if (objectType == typeof(double))
            {
                result = (double)attribute;
            }
            else if (objectType == typeof(float))
            {
                result = (float)attribute;
            }
            else if (objectType == typeof(decimal))
            {
                if (stringVal == UnboundedString)
                {
                    result = UnboundedDecimal;
                }
                else
                {
                    result = (decimal)attribute;
                }
            }
            else if (objectType == typeof(bool))
            {
                result = (bool)attribute;
            }
            else if (objectType == typeof(bool?))
            {
                result = (bool?)attribute;
            }
            else if (typeof(Enum).IsAssignableFrom(objectType))
            {
                foreach (var enumVal in Enum.GetValues(objectType))
                {
                    if (string.Compare(stringVal, Enum.GetName(objectType, enumVal), StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        result = enumVal;
                        break;
                    }
                }
            }
            else if (objectType == typeof(XNamespace))
            {
                XNamespace ns = null;
                if (stringVal != null)
                {
                    ns = XNamespace.Get(stringVal);
                }
                return ns;
            }
            else
            {
                result = stringVal;
            }
            return result;
        }
protected static object ConvertToType ( string stringVal , XAttribute attribute , Type objectType ) { object result = null ; if ( objectType == typeof ( int ) ) { result = ( int ) attribute ; } else if ( objectType == typeof ( uint ) ) { result = ( uint ) attribute ; } else if ( objectType == typeof ( uint ? ) ) { result = ( uint ? ) attribute ; } else if ( objectType == typeof ( double ) ) { result = ( double ) attribute ; } else if ( objectType == typeof ( float ) ) { result = ( float ) attribute ; } else if ( objectType == typeof ( decimal ) ) { if ( stringVal == UnboundedString ) { result = UnboundedDecimal ; } else { result = ( decimal ) attribute ; } } else if ( objectType == typeof ( bool ) ) { result = ( bool ) attribute ; } else if ( objectType == typeof ( bool ? ) ) { result = ( bool ? ) attribute ; } else if ( typeof ( Enum ) . IsAssignableFrom ( objectType ) ) { foreach ( var enumVal in Enum . GetValues ( objectType ) ) { if ( string . Compare ( stringVal , Enum . GetName ( objectType , enumVal ) , StringComparison . OrdinalIgnoreCase ) == 0 ) { result = enumVal ; break ; } } } else if ( objectType == typeof ( XNamespace ) ) { XNamespace ns = null ; if ( stringVal != null ) { ns = XNamespace . Get ( stringVal ) ; } return ns ; } else { result = stringVal ; } return result ; }
This method converts the contents of the XAttribute into an object of the passed
in type.
This method converts the contents of the XAttribute into an object of the passed in type .
None
stringVal
string
attribute
XAttribute
The XAttribute to read
The XAttribute to read
objectType
Type
The type of object to return
The type of object to return
attrValue
The string passed here should be decoded as needed.
The string passed here should be decoded as needed .