Exemple #1
0
        /// <summary>Materializes an enum value. No op or non-primitive values.</summary>
        /// <param name="type">The clr Type of value to set.</param>
        /// <param name="wireTypeName">The Type name from the payload.</param>
        /// <param name="enumValueStr">The string of enum value.</param>
        /// <param name="throwOnNullMessage">The exception message if the value is null.</param>
        /// <param name="materializedValue">The materialized value.</param>
        private void MaterializeODataEnumValue(Type type, string wireTypeName, string enumValueStr, Func <string> throwOnNullMessage, out object materializedValue)
        {
            Debug.Assert(type != null, "type != null");
            Type underlyingType = Nullable.GetUnderlyingType(type) ?? type;
            ClientTypeAnnotation elementTypeAnnotation = this.context.ResolveTypeForMaterialization(underlyingType, wireTypeName);

            Debug.Assert(elementTypeAnnotation != null, "elementTypeAnnotation != null");

            // TODO: Find better way to parse Enum
            Type enumClrType = elementTypeAnnotation.ElementType;

            enumValueStr = enumValueStr.Trim();
            if (!Enum.IsDefined(enumClrType, enumValueStr))
            {
                materializedValue = Enum.Parse(enumClrType, ClientTypeUtil.GetClientMemberName(enumClrType, enumValueStr), false);
            }
            else
            {
                materializedValue = Enum.Parse(enumClrType, enumValueStr, false);
            }
        }
Exemple #2
0
        /// <summary>Materializes an enum value. No op or non-primitive values.</summary>
        /// <param name="enumType">The clr Type of value to set.</param>
        /// <param name="enumValue">The value of enum.</param>
        /// <returns>The materialized value.</returns>
        internal static object MaterializeODataEnumValue(Type enumType, ODataEnumValue enumValue)
        {
            object tmpValue;

            if (enumValue == null)
            {
                tmpValue = null;
            }
            else
            {
                // TODO: Find better way to parse Enum
                string enumValueStr = enumValue.Value.Trim();
                if (!Enum.IsDefined(enumType, enumValueStr))
                {
                    tmpValue = Enum.Parse(enumType, ClientTypeUtil.GetClientMemberName(enumType, enumValueStr), false);
                }
                else
                {
                    tmpValue = Enum.Parse(enumType, enumValueStr, false);
                }
            }

            return(tmpValue);
        }