private static PropertySerializer <T> CreatePropertySerializer(PropertyInfo property, PropertyTypeSerializerCache typeSerializerCache) { var genericTypes = new[] { typeof(T), property.PropertyType }; var args = new object[] { property, typeSerializerCache }; return((PropertySerializer <T>)FastActivator.Create(typeof(PropertySerializer <,>), genericTypes, args)); }
private static Dictionary <string, PropertySerializer <T> > GetPropertySerializers( PropertyTypeSerializerCache typeSerializerCache) { return(typeof(T).GetAllProperties() .Where(x => x.GetGetMethod() != null) .Where(x => x.GetSetMethod(true) != null || typeof(T).IsInterface) .Select(x => new { x.Name, Serializer = CreatePropertySerializer(x, typeSerializerCache) }) .ToDictionary(x => x.Name, x => x.Serializer)); }
public FastTextTypeSerializerCache(TypeSerializerCache typeSerializerCache) { _propertyTypeSerializerCache = new FastTextPropertyTypeSerializerCache(this); _serializers = new Cache <Type, FastTextTypeSerializer>(CreateSerializerFor); typeSerializerCache.Each((type, serializer) => _serializers.Add(type, CreateSerializerFor(type, serializer))); _serializers[typeof(string)] = new FastTextTypeSerializer <string>(new FastTextStringSerializer()); _serializers[typeof(Type)] = new FastTextTypeSerializer <Type>(new FastTextSystemTypeSerializer()); }
public ObjectSerializer(PropertyTypeSerializerCache typeSerializerCache) { ObjectType = typeof(T); if (!ObjectType.IsClass && !ObjectType.IsInterface) { throw new ArgumentException("Only classes and interfaces can be serialized by an object serializer, not: " + ObjectType.FullName); } _properties = new PropertySerializerCache <T>(typeSerializerCache); }
public FastTextObjectSerializer(PropertyTypeSerializerCache typeSerializerCache) { _objectSerializer = new ObjectSerializer <T>(typeSerializerCache); _properties = _objectSerializer.Properties; }
public PropertySerializerCache(PropertyTypeSerializerCache typeSerializerCache) : base(GetPropertySerializers(typeSerializerCache)) { _each = this.OrderBy(x => x.Name).ToArray(); _count = _each.Length; }