private object DeserializePropertyValue(XmlReader reader, PropertyDefinition propertyDefinition)
        {
            Type valueType = propertyDefinition == null?DeserializeCustomValueType(reader) : propertyDefinition.PropertyType;

            reader.ReadStartElement("Property");

            object value;

            if (reader.IsStartElement("null"))
            {
                reader.ReadStartElement("null"); // no end element for null
                value = null;
            }
            else if (ExtensibleEnumUtility.IsExtensibleEnumType(valueType))
            {
                string idString = reader.ReadContentAsString();
                value = ExtensibleEnumUtility.GetDefinition(valueType).GetValueInfoByID(idString).Value;
            }
            else if (IsObjectID(valueType))
            {
                string objectIDString = reader.ReadContentAsString();
                value = ObjectID.Parse(objectIDString);
            }
            else
            {
                var valueDeserializer = new XmlSerializer(valueType);
                value = valueDeserializer.Deserialize(reader);
            }
            reader.ReadEndElement();
            return(value);
        }
Beispiel #2
0
 private IEnumerable <XElement> GetValues(Type type)
 {
     return(ExtensibleEnumUtility.GetDefinition(type).GetValueInfos().Select(
                info => new XElement(
                    Constants.Namespace + "value",
                    new XAttribute("name", info.Value.ValueName),
                    new XAttribute("columnValue", info.Value.ID))));
 }
        public TypeConverter CreateTypeConverterOrDefault(Type type)
        {
            ArgumentUtility.CheckNotNull("type", type);

            if (ExtensibleEnumUtility.IsExtensibleEnumType(type))
            {
                return(new ExtensibleEnumConverter(type));
            }
            return(null);
        }
        public ExtensibleEnumerationProperty(Parameters parameters)
            : base(parameters)
        {
            _definition = ExtensibleEnumUtility.GetDefinition(PropertyType);

            var filterProvider = new EnumValueFilterProvider <DisableExtensibleEnumValuesAttribute> (
                PropertyInfo,
                t => _definition.GetCustomAttributes <DisableExtensibleEnumValuesAttribute> ());

            _enumerationValueFilter = filterProvider.GetEnumerationValueFilter();
        }
Beispiel #5
0
        public void CollectPropertyType(PropertyDefinition propertyDefinition)
        {
            ArgumentUtility.CheckNotNull("propertyDefinition", propertyDefinition);

            var propertyType = propertyDefinition.PropertyType;

            if (ExtensibleEnumUtility.IsExtensibleEnumType(propertyType))
            {
                _enumTypes.Add(propertyType);
            }
            else
            {
                _enumSerializer.CollectPropertyType(propertyDefinition);
            }
        }
        private void SerializePropertyValue(XmlWriter writer, PropertyDefinition propertyDefinition, object value)
        {
            Type valueType = propertyDefinition == null?SerializeCustomValueType(writer, value) : propertyDefinition.PropertyType;

            if (value == null)
            {
                writer.WriteElementString("null", "");
            }
            else if (IsObjectID(valueType))
            {
                writer.WriteString(value.ToString());
            }
            else if (ExtensibleEnumUtility.IsExtensibleEnumType(valueType))
            {
                writer.WriteString(((IExtensibleEnum)value).ID);
            }
            else
            {
                var valueSerializer = new XmlSerializer(valueType);
                valueSerializer.Serialize(writer, value);
            }
        }
 public void GetDefinition()
 {
     Assert.That(ExtensibleEnumUtility.GetDefinition(typeof(Color)), Is.SameAs(Color.Values));
 }
 public void IsExtensibleEnumType_FromITypeInformation_False_BaseType()
 {
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(TypeAdapter.Create(typeof(ExtensibleEnum <>))), Is.False);
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(TypeAdapter.Create(typeof(ExtensibleEnum <Color>))), Is.False);
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(TypeAdapter.Create(typeof(IExtensibleEnum))), Is.False);
 }
 public void IsExtensibleEnumType_FromITypeInformation_False()
 {
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(TypeAdapter.Create(typeof(object))), Is.False);
 }
 public void IsExtensibleEnumType_FromITypeInformation_True()
 {
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(TypeAdapter.Create(typeof(Color))), Is.True);
 }
 public void IsExtensibleEnumType_False_BaseType()
 {
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(typeof(ExtensibleEnum <>)), Is.False);
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(typeof(ExtensibleEnum <Color>)), Is.False);
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(typeof(IExtensibleEnum)), Is.False);
 }
 public void IsExtensibleEnumType_False()
 {
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(typeof(object)), Is.False);
 }
 private int GetColumnWidthForExtensibleEnum(Type extensibleEnumType)
 {
     return(ExtensibleEnumUtility.GetDefinition(extensibleEnumType).GetValueInfos().Max(info => info.Value.ID.Length));
 }
        private StorageTypeInformation GetStorageType(Type dotNetType, int?maxLength, bool isNullableInDatabase)
        {
            var underlyingTypeOfNullable = Nullable.GetUnderlyingType(dotNetType);

            if (underlyingTypeOfNullable != null)
            {
                return(GetStorageTypeForNullableValueType(dotNetType, underlyingTypeOfNullable, maxLength, isNullableInDatabase));
            }

            if (dotNetType.IsEnum)
            {
                return(GetStorageTypeForEnumType(dotNetType, maxLength, isNullableInDatabase));
            }

            if (ExtensibleEnumUtility.IsExtensibleEnumType(dotNetType))
            {
                return(GetStorageTypeForExtensibleEnumType(dotNetType, isNullableInDatabase));
            }

            if (ReflectionUtility.IsStringPropertyValueType(dotNetType))
            {
                string storageTypeName = GetStorageTypeStringForVarType("nvarchar", maxLength);
                return(new StorageTypeInformation(typeof(string), storageTypeName, DbType.String, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }

            if (ReflectionUtility.IsBinaryPropertyValueType(dotNetType))
            {
                string storageTypeName = GetStorageTypeStringForVarType("varbinary", maxLength);
                return(new StorageTypeInformation(typeof(byte[]), storageTypeName, DbType.Binary, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }

            if (dotNetType == typeof(Boolean))
            {
                return(new StorageTypeInformation(typeof(Boolean), "bit", DbType.Boolean, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }
            if (dotNetType == typeof(Byte))
            {
                return(new StorageTypeInformation(typeof(Byte), "tinyint", DbType.Byte, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }
            if (dotNetType == typeof(DateTime))
            {
                return(new StorageTypeInformation(typeof(DateTime), "datetime", DbType.DateTime, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }
            if (dotNetType == typeof(Decimal))
            {
                return(new StorageTypeInformation(typeof(Decimal), "decimal (38, 3)", DbType.Decimal, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }
            if (dotNetType == typeof(Double))
            {
                return(new StorageTypeInformation(typeof(Double), "float", DbType.Double, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }
            if (dotNetType == typeof(Guid))
            {
                return(new StorageTypeInformation(typeof(Guid), "uniqueidentifier", DbType.Guid, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }
            if (dotNetType == typeof(Int16))
            {
                return(new StorageTypeInformation(typeof(Int16), "smallint", DbType.Int16, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }
            if (dotNetType == typeof(Int32))
            {
                return(new StorageTypeInformation(typeof(Int32), "int", DbType.Int32, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }
            if (dotNetType == typeof(Int64))
            {
                return(new StorageTypeInformation(typeof(Int64), "bigint", DbType.Int64, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }
            if (dotNetType == typeof(Single))
            {
                return(new StorageTypeInformation(typeof(Single), "real", DbType.Single, isNullableInDatabase, dotNetType, new DefaultConverter(dotNetType)));
            }

            return(null);
        }
 public void GetDefinition_InvalidType()
 {
     ExtensibleEnumUtility.GetDefinition(typeof(object));
 }
 public void IsExtensibleEnumType_True()
 {
     Assert.That(ExtensibleEnumUtility.IsExtensibleEnumType(typeof(Color)), Is.True);
 }
 /// <remarks>Only temporary solution until type resulition is refactored.</remarks>
 internal static bool IsExtensibleEnumPropertyValueType(Type propertyType)
 {
     ArgumentUtility.CheckNotNull("propertyType", propertyType);
     return(ExtensibleEnumUtility.IsExtensibleEnumType(propertyType));
 }