Esempio n. 1
0
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
     foreach (var argumentType in Type.GetGenericArguments())
     {
         context.BuildConstants(argumentType);
     }
 }
Esempio n. 2
0
        public IntPtr BuildWriter(Type type, bool ignoreCustomSerialization)
        {
            var constantsBuilder = module.DefineType(type.Name + "_GroBufWriter_" + Guid.NewGuid(), TypeAttributes.Class | TypeAttributes.Public);

            constantsBuilder.DefineField("pointers", typeof(IntPtr[]), FieldAttributes.Private | FieldAttributes.Static);
            constantsBuilder.DefineField("delegates", typeof(Delegate[]), FieldAttributes.Private | FieldAttributes.Static);
            var constantsBuilderContext = new WriterConstantsBuilderContext(groBufWriter, constantsBuilder, writerCollection, dataMembersExtractor);

            constantsBuilderContext.BuildConstants(type, true, ignoreCustomSerialization);
            var constantsType = constantsBuilder.CreateTypeInfo();
            var fields        = constantsBuilderContext.GetFields().ToDictionary(pair => pair.Key, pair => pair.Value.Select(constantsType.GetField).ToArray());
            var context       = new WriterTypeBuilderContext(groBufWriter, module, constantsType, fields, writerCollection, dataMembersExtractor);
            var writer        = context.GetWriter(type, true, ignoreCustomSerialization);

            var initializer = BuildInitializer(constantsType.GetField("pointers", BindingFlags.Static | BindingFlags.NonPublic), constantsType.GetField("delegates", BindingFlags.Static | BindingFlags.NonPublic));

            var compiledDynamicMethods = context.GetMethods();
            var pointers  = new IntPtr[compiledDynamicMethods.Length];
            var delegates = new Delegate[compiledDynamicMethods.Length];

            foreach (var pair in compiledDynamicMethods)
            {
                var compiledDynamicMethod = pair.Value;
                var index = compiledDynamicMethod.Index;
                pointers[index]  = compiledDynamicMethod.Pointer;
                delegates[index] = compiledDynamicMethod.Delegate;
                if (compiledDynamicMethod.Pointer != writer.Pointer)
                {
                    groBufWriter.writersWithCustomSerialization[pair.Key] = (IntPtr?)compiledDynamicMethod.Pointer;
                }
            }
            initializer(pointers, delegates, context.GetFieldInitializers());
            return(writer.Pointer);
        }
Esempio n. 3
0
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
     context.SetFields(Type, new[]
     {
         new KeyValuePair <string, Type>("hashCodes_" + Type.Name + "_" + Guid.NewGuid(), typeof(ulong[])),
         new KeyValuePair <string, Type>("values_" + Type.Name + "_" + Guid.NewGuid(), typeof(int[])),
     });
 }
Esempio n. 4
0
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
     context.SetFields(Type, new[]
     {
         new KeyValuePair <string, Type>("writers_" + Type.Name + "_" + Guid.NewGuid(), typeof(IntPtr[])),
         new KeyValuePair <string, Type>("delegates_" + Type.Name + "_" + Guid.NewGuid(), typeof(Delegate[])),    // This field is needed only to save references to the dynamic methods. Otherwise GC will destroy them
     });
     Array.ForEach(GroBufHelpers.LeafTypes.Where(type => type != null).ToArray(), type => context.BuildConstants(type));
 }
Esempio n. 5
0
        protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
        {
            foreach (var member in context.GetDataMembers(Type))
            {
                Type memberType;
                switch (member.Member.MemberType)
                {
                case MemberTypes.Property:
                    memberType = ((PropertyInfo)member.Member).PropertyType;
                    break;

                case MemberTypes.Field:
                    memberType = ((FieldInfo)member.Member).FieldType;
                    break;

                default:
                    throw new NotSupportedException("Data member of type " + member.Member.MemberType + " is not supported");
                }
                context.BuildConstants(memberType);
            }
        }
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
     context.BuildConstants(elementType);
 }
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
     context.SetFields(Type, new[] { new KeyValuePair <string, Type>("customSerializer_" + Type.Name + "_" + Guid.NewGuid(), typeof(IGroBufCustomSerializer)) });
 }
Esempio n. 8
0
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
     context.BuildConstants(keyType);
     context.BuildConstants(valueType);
 }
Esempio n. 9
0
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
 }
Esempio n. 10
0
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
     context.BuildConstants(typeof(long));
 }
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
     context.BuildConstants(typeof(DateTime));
     context.BuildConstants(typeof(short));
 }
Esempio n. 12
0
 protected override void BuildConstantsInternal(WriterConstantsBuilderContext context)
 {
     context.BuildConstants(Type.GetGenericArguments()[0]);
 }
Esempio n. 13
0
 protected abstract void BuildConstantsInternal(WriterConstantsBuilderContext context);
Esempio n. 14
0
 public void BuildConstants(WriterConstantsBuilderContext context)
 {
     context.SetFields(Type, new KeyValuePair <string, Type> [0]);
     BuildConstantsInternal(context);
 }