public TypeSerializationInfo(Type type, IEnumerable <PropertyInfo> properties) { Type = type; TypeName = TypeHelper.FormatBinary(Type); IsAttribute = TypeHelper.IsXmlAttribute(Type); if (IsAttribute) { Serialazer = TypeHelper.GetValueSerializer(type); return; } if (!Type.IsInterface) { Constructor = EmitInvoker.Initialize(type, Type.EmptyTypes); } IsList = TypeHelper.IsList(type); if (IsList) { IsNamedList = TypeHelper.IsInterface(type, typeof(INamedList)); ListItemType = TypeHelper.GetItemType(type); ListDefaulType = ListItemType != typeof(object) && !ListItemType.IsInterface && !type.IsGenericType && !type.IsArray && !TypeHelper.IsInterface(type, typeof(ISortable)); ListItemIsAttribute = TypeHelper.IsXmlAttribute(ListItemType); ListConstructor = EmitInvoker.Initialize(type, new[] { typeof(int) }); } IsDictionary = TypeHelper.IsDictionary(type); Properties = new NamedList <PropertySerializationInfo>(); Properties.Indexes.Add(PropertySaveInfoIsAttributeInvoker.Instance); foreach (var property in properties) { if (TypeHelper.IsNonSerialize(property)) { var exist = GetProperty(property.Name); if (exist != null) { Properties.Remove(exist); } continue; } var info = new PropertySerializationInfo(property); { var exist = GetProperty(info.Name); if (exist != null) { Properties.Remove(exist); } Properties.Add(info); } } }
public TypeSerializationInfo(Type type, IEnumerable <PropertyInfo> properties) { Type = type; TypeName = TypeHelper.FormatBinary(Type); IsAttribute = TypeHelper.IsSerializeAttribute(Type); if (IsAttribute) { Serialazer = TypeHelper.GetValueSerializer(type); return; } if (!Type.IsInterface && !Type.IsAbstract) { Constructor = EmitInvoker.Initialize(type, Type.EmptyTypes); } IsList = TypeHelper.IsList(type); if (IsList) { IsNamedList = TypeHelper.IsInterface(type, typeof(INamedList)); ListItemType = TypeHelper.GetItemType(type); ListDefaulType = ListItemType != typeof(object) && !ListItemType.IsInterface && !type.IsGenericType && !type.IsArray && !TypeHelper.IsInterface(type, typeof(ISortable)); ListItemIsAttribute = TypeHelper.IsSerializeAttribute(ListItemType); ListConstructor = EmitInvoker.Initialize(type, new[] { typeof(int) }); } IsDictionary = TypeHelper.IsDictionary(type); Properties = new NamedList <PropertySerializationInfo>(6, (ListIndex <PropertySerializationInfo, string>)PropertySerializationInfo.NameInvoker.Instance.CreateIndex(false)); Properties.Indexes.Add(PropertySerializationInfo.IsAttributeInvoker.Instance); int order = 0; foreach (var property in properties) { var exist = GetProperty(property.Name); if (TypeHelper.IsNonSerialize(property)) { if (exist != null) { Properties.Remove(exist); } continue; } //var method = property.GetGetMethod() ?? property.GetSetMethod(); if (exist != null)// && method.Equals(method.GetBaseDefinition()) { Properties.Remove(exist); } Properties.Add(new PropertySerializationInfo(property, ++order)); } Properties.ApplySortInternal(PropertySerializationInfo.OrderInvoker.Instance.CreateComparer <PropertySerializationInfo>()); }
public override string ConvertToString(object value, IValueSerializerContext context) => TypeHelper.FormatBinary((Type)value);