public static SerializerFactory CreateDefault(params SerializationRule[] additionalRules)
        {
            var ans = new SerializerFactory();

            foreach (var serializationRule in additionalRules)
            {
                ans.AddRule(serializationRule);
            }
            ans.AddRule(SerializationRule.Create(new ByteArraySerializer()));
            ans.AddRule(SerializationRule.Create(new ByteEnumerableSerializer()));
            ans.AddRule(SerializationRule.Create(new UnicodeSerializer()));
            ans.AddRule(SerializationRule.Create(new UTCFileTimeSerializer()));
            ans.AddRule(SerializationRule.Create(new UTCFileTimeAndOffsetSerializer()));
            ans.AddRule(new SerializationRule(t => t.GetTypeInfo().IsDefined(typeof(ProtoBuf.ProtoContractAttribute)), CreateProtoSerializer));
            ans.AddRule(new SerializationRule(t => t.GetTypeInfo().IsArray, CreateArraySerializer));
            ans.AddRule(new SerializationRule(t => t.GetTypeInfo().IsEnum, CreateEnumSerializer));
            ans.AddRule(new SerializationRule(PresentationHelper.IsNulable, CreateDotNetNullableSerializer));
            ans.AddRule(new SerializationRule(t => t.GetTypeInfo().IsValueType, CreateDotNetValueTypeSerializer));
            return(ans);
        }
Exemple #2
0
        public static ISerializer CreateArraySerializer(Type arrayType, SerializerFactory factory)
        {
            var gt = typeof(ArraySerializer <>).MakeGenericType(arrayType);

            return(Activator.CreateInstance(gt, factory) as ISerializer);
        }
 public ISerializer GetSerializer(Type type, SerializerFactory factory)
 {
     return(_serializerLocator(type, factory));
 }