public GroBufCustomSerializerI1(Func <Type, IGroBufCustomSerializer> factory, IGroBufCustomSerializer baseSerializer) { this.factory = factory; this.baseSerializer = baseSerializer; }
public DateGroBufCustomSerializer(IGroBufCustomSerializer baseSerializer) { this.baseSerializer = baseSerializer; }
public CustomWriterBuilder(Type type, IGroBufCustomSerializer customSerializer) : base(type) { this.customSerializer = customSerializer; }
public IGroBufCustomSerializer Get(Type declaredType, Func <Type, IGroBufCustomSerializer> factory, IGroBufCustomSerializer baseSerializer) { if (declaredType == typeof(I1)) { return(new GroBufCustomSerializerI1(factory, baseSerializer)); } if (declaredType == typeof(Date2)) { return(new DateGroBufCustomSerializer(baseSerializer)); } return(null); }
public IGroBufCustomSerializer Get(Type declaredType, Func <Type, IGroBufCustomSerializer> factory, IGroBufCustomSerializer baseSerializer) { if (declaredType.IsGenericType && declaredType.GetGenericTypeDefinition() == typeof(I1 <>)) { return(new GroBufCustomSerializer(declaredType, factory, baseSerializer)); } return(null); }
public IGroBufCustomSerializer Get(Type declaredType, Func <Type, IGroBufCustomSerializer> factory, IGroBufCustomSerializer baseSerializer) { if (typeof(B) == (declaredType)) { return(new GroBufCustomSerializer(factory, baseSerializer)); } return(null); }
public GroBufCustomSerializer(Type declaredType, Func <Type, IGroBufCustomSerializer> factory, IGroBufCustomSerializer baseSerializer) { argumentType = declaredType.GetGenericArguments()[0]; this.factory = factory; this.baseSerializer = baseSerializer; }
public IGroBufCustomSerializer Get(Type declaredType, Func <Type, IGroBufCustomSerializer> factory, IGroBufCustomSerializer baseSerializer) { return(null); }
public IGroBufCustomSerializer Get(Type declaredType, Func <Type, IGroBufCustomSerializer> factory, IGroBufCustomSerializer baseSerializer) { var attribute = declaredType.GetCustomAttributes(typeof(GroBufCustomSerializationAttribute), false).FirstOrDefault() as GroBufCustomSerializationAttribute; if (attribute == null) { return(null); } Type customSerializerType = attribute.CustomSerializerType ?? declaredType; MethodInfo customSizeCounter = GroBufHelpers.GetMethod <GroBufSizeCounterAttribute>(customSerializerType); if (customSizeCounter == null) { throw new MissingMethodException("Missing grobuf custom size counter for type '" + customSerializerType + "'"); } MethodInfo writer = GroBufHelpers.GetMethod <GroBufWriterAttribute>(customSerializerType); if (writer == null) { throw new MissingMethodException("Missing grobuf custom writer for type '" + customSerializerType + "'"); } MethodInfo reader = GroBufHelpers.GetMethod <GroBufReaderAttribute>(customSerializerType); if (reader == null) { throw new MissingMethodException("Missing grobuf custom reader for type '" + customSerializerType + "'"); } var sizeCounterDelegate = (SizeCounterDelegate)customSizeCounter.Invoke( null, new object[] { (Func <Type, SizeCounterDelegate>)(type => ((o, empty, context) => factory(type).CountSize(o, empty, context))), (SizeCounterDelegate)(baseSerializer.CountSize) }); var writerDelegate = (WriterDelegate)writer.Invoke( null, new object[] { (Func <Type, WriterDelegate>)(type => ((object o, bool empty, IntPtr result, ref int index, WriterContext context) => factory(type).Write(o, empty, result, ref index, context))), (WriterDelegate)(baseSerializer.Write) }); var readerDelegate = (ReaderDelegate)reader.Invoke( null, new object[] { (Func <Type, ReaderDelegate>)(type => ((IntPtr data, ref int index, ref object result, ReaderContext context) => factory(type).Read(data, ref index, ref result, context))), (ReaderDelegate)(baseSerializer.Read) }); return(new GroBufCustomSerializerByAttribute(sizeCounterDelegate, writerDelegate, readerDelegate)); }
private IReaderBuilder GetReaderBuilderInternal(Type type, bool ignoreCustomSerialization) { IReaderBuilder readerBuilder; IGroBufCustomSerializer customSerializer = null; if (!ignoreCustomSerialization) { customSerializer = customSerializerCollection.Get(type, factory, baseFactory(type)); } if (customSerializer != null) { readerBuilder = new CustomReaderBuilder(type, customSerializer); } else if (type == typeof(string)) { readerBuilder = new StringReaderBuilder(); } else if (type == typeof(DateTime)) { readerBuilder = new DateTimeReaderBuilder(); } else if (type == typeof(Guid)) { readerBuilder = new GuidReaderBuilder(); } else if (type == typeof(IPAddress)) { readerBuilder = new IPAddressReaderBuilder(); } else if (type == typeof(TimeSpan)) { readerBuilder = new TimeSpanReaderBuilder(); } else if (type == typeof(DateTimeOffset)) { readerBuilder = new DateTimeOffsetReaderBuilder(); } else if (type.IsEnum) { readerBuilder = new EnumReaderBuilder(type); } else if (type.IsPrimitive || type == typeof(decimal)) { readerBuilder = new PrimitivesReaderBuilder(type, module); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { readerBuilder = new NullableReaderBuilder(type); } else if (type.IsArray) { readerBuilder = type.GetElementType().IsPrimitive ? (IReaderBuilder) new PrimitivesArrayReaderBuilder(type) : new ArrayReaderBuilder(type); } else if (type == typeof(Hashtable)) { readerBuilder = new HashtableReaderBuilder(); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>)) { readerBuilder = new DictionaryReaderBuilder(type); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(HashSet <>)) { readerBuilder = type.GetGenericArguments()[0].IsPrimitive ? (IReaderBuilder) new PrimitivesHashSetReaderBuilder(type) : new HashSetReaderBuilder(type); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ArraySegment <>)) { readerBuilder = type.GetGenericArguments()[0].IsPrimitive ? (IReaderBuilder) new PrimitivesArraySegmentReaderBuilder(type) : new ArraySegmentReaderBuilder(type); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>)) { readerBuilder = type.GetGenericArguments()[0].IsPrimitive ? (IReaderBuilder) new PrimitivesListReaderBuilder(type) : new ListReaderBuilder(type); } else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Lazy <>)) { readerBuilder = new LazyReaderBuilder(type, module); } else if (type.IsTuple()) { readerBuilder = new TupleReaderBuilder(type); } else if (type == typeof(object)) { readerBuilder = new ObjectReaderBuilder(); } else { readerBuilder = new ClassReaderBuilder(type); } return(readerBuilder); }
public IGroBufCustomSerializer Get(Type declaredType, Func <Type, IGroBufCustomSerializer> factory, IGroBufCustomSerializer baseSerializer) { bool isAbstractMultiLanguageText = (declaredType == typeof(MultiLanguageTextBase) || declaredType.IsSubclassOf(typeof(MultiLanguageTextBase))) && declaredType.IsAbstract; return(defaultCollection.Get(isAbstractMultiLanguageText ? typeof(MultiLanguageTextSerializer) : declaredType, factory, baseSerializer)); }