コード例 #1
0
        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));
        }
コード例 #2
0
 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));
 }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public FastTextObjectSerializer(PropertyTypeSerializerCache typeSerializerCache)
 {
     _objectSerializer = new ObjectSerializer <T>(typeSerializerCache);
     _properties       = _objectSerializer.Properties;
 }
コード例 #6
0
 public PropertySerializerCache(PropertyTypeSerializerCache typeSerializerCache)
     : base(GetPropertySerializers(typeSerializerCache))
 {
     _each  = this.OrderBy(x => x.Name).ToArray();
     _count = _each.Length;
 }