public static DateTimeConversionMethod DetermineDateTimeConversionMethod(
            SerializationContext context,
            DateTimeMemberConversionMethod dateTimeMemberConversionMethod
            )
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            switch (dateTimeMemberConversionMethod)
            {
            case DateTimeMemberConversionMethod.Native:
            {
                return(DateTimeConversionMethod.Native);
            }

            case DateTimeMemberConversionMethod.UnixEpoc:
            {
                return(DateTimeConversionMethod.UnixEpoc);
            }

            default:
            {
                return(context.DefaultDateTimeConversionMethod);
            }
            }
        }
		public static DateTimeConversionMethod DetermineDateTimeConversionMethod(
			SerializationContext context,
			DateTimeMemberConversionMethod dateTimeMemberConversionMethod 
		)
		{
			if ( context == null )
			{
				throw new ArgumentNullException( "context" );
			}

			switch ( dateTimeMemberConversionMethod )
			{
				case DateTimeMemberConversionMethod.Native:
				{
					return DateTimeConversionMethod.Native;
				}
				case DateTimeMemberConversionMethod.UnixEpoc:
				{
					return DateTimeConversionMethod.UnixEpoc;
				}
				default:
				{
					return context.DefaultDateTimeConversionMethod;
				}
			}
		}
        /// <summary>
        ///		Regisgters <see cref="MessagePackSerializer{T}"/> of target type usage to the current emitting session.
        /// </summary>
        /// <param name="targetType">The type of the member to be serialized/deserialized.</param>
        /// <param name="enumMemberSerializationMethod">The enum serialization method of the member to be serialized/deserialized.</param>
        /// <param name="dateTimeConversionMethod">The date time conversion method of the member to be serialized/deserialized.</param>
        /// <param name="polymorphismSchema">The schema for polymorphism support.</param>
        /// <param name="schemaRegenerationCodeProvider">The delegate to provide constructs to emit schema regeneration codes.</param>
        /// <returns><see cref="FieldBuilder"/>.</returns>
        public FieldBuilder RegisterSerializer(
            Type targetType,
            EnumMemberSerializationMethod enumMemberSerializationMethod,
            DateTimeMemberConversionMethod dateTimeConversionMethod,
            PolymorphismSchema polymorphismSchema,
            Func <IEnumerable <ILConstruct> > schemaRegenerationCodeProvider
            )
        {
            var key = new SerializerFieldKey(targetType, enumMemberSerializationMethod, dateTimeConversionMethod, polymorphismSchema);

            SerializerFieldInfo result;

            if (!this._serializers.TryGetValue(key, out result))
            {
                result =
                    new SerializerFieldInfo(
                        this.DefineInitonlyField(
                            "_serializer" + this._serializers.Count,
                            typeof(MessagePackSerializer <>).MakeGenericType(targetType)
                            ),
                        il =>
                {
                    foreach (var construct in schemaRegenerationCodeProvider())
                    {
                        construct.Evaluate(il);
                    }
                }
                        );

                this._serializers.Add(key, result);
            }

            return(result.Field);
        }
Exemplo n.º 4
0
 public SerializerFieldKey(Type targetType, EnumMemberSerializationMethod enumMemberSerializationMethod, DateTimeMemberConversionMethod dateTimeConversionMethod, PolymorphismSchema polymorphismSchema)
 {
     this.TypeHandle = targetType.TypeHandle;
     this.EnumSerializationMethod  = enumMemberSerializationMethod;
     this.DateTimeConversionMethod = dateTimeConversionMethod;
     this._schema = new ComparablePolymorphismSchema(polymorphismSchema);
 }
Exemplo n.º 5
0
 /// <summary>
 ///		Regisgters <see cref="MessagePackSerializer{T}"/> of target type usage to the current emitting session.
 /// </summary>
 /// <param name="targetType">The type of the member to be serialized/deserialized.</param>
 /// <param name="enumMemberSerializationMethod">The enum serialization method of the member to be serialized/deserialized.</param>
 /// <param name="dateTimeConversionMethod">The date time conversion method of the member to be serialized/deserialized.</param>
 /// <param name="polymorphismSchema">The schema for polymorphism support.</param>
 /// <param name="schemaRegenerationCodeProvider">The delegate to provide constructs to emit schema regeneration codes.</param>
 /// <returns>
 ///		<see cref=" Action{T1,T2}"/> to emit serializer retrieval instructions.
 ///		The 1st argument should be <see cref="TracingILGenerator"/> to emit instructions.
 ///		The 2nd argument should be argument index of the serializer holder, normally 0 (this pointer).
 ///		This value will not be <c>null</c>.
 /// </returns>
 public abstract Action <TracingILGenerator, int> RegisterSerializer(
     Type targetType,
     EnumMemberSerializationMethod enumMemberSerializationMethod,
     DateTimeMemberConversionMethod dateTimeConversionMethod,
     PolymorphismSchema polymorphismSchema,
     Func <IEnumerable <ILConstruct> > schemaRegenerationCodeProvider
     );
Exemplo n.º 6
0
 /// <summary>
 ///		Regisgters <see cref="MessagePackSerializer{T}"/> of target type usage to the current emitting session.
 /// </summary>
 /// <param name="targetType">The type of the member to be serialized/deserialized.</param>
 /// <param name="enumMemberSerializationMethod">The enum serialization method of the member to be serialized/deserialized.</param>
 /// <param name="dateTimeConversionMethod">The date time conversion method of the member to be serialized/deserialized.</param>
 /// <param name="polymorphismSchema">The schema for polymorphism support.</param>
 /// <param name="schemaRegenerationCodeProvider">The delegate to provide constructs to emit schema regeneration codes.</param>
 /// <returns>
 ///		<see cref=" Action{T1,T2}"/> to emit serializer retrieval instructions.
 ///		The 1st argument should be <see cref="TracingILGenerator"/> to emit instructions.
 ///		The 2nd argument should be argument index of the serializer holder, normally 0 (this pointer).
 ///		This value will not be <c>null</c>.
 /// </returns>
 public override Action <TracingILGenerator, int> RegisterSerializer(
     Type targetType,
     EnumMemberSerializationMethod enumMemberSerializationMethod,
     DateTimeMemberConversionMethod dateTimeConversionMethod,
     PolymorphismSchema polymorphismSchema,
     Func <IEnumerable <ILConstruct> > schemaRegenerationCodeProvider
     )
 {
     // This return value should not be used.
     return((g, i) => { throw new NotImplementedException(); });
 }
Exemplo n.º 7
0
 public override Action <TracingILGenerator, int> RegisterSerializer(
     Type targetType,
     EnumMemberSerializationMethod enumMemberSerializationMethod,
     DateTimeMemberConversionMethod dateTimeConversionMethod,
     PolymorphismSchema polymorphismSchema,
     Func <IEnumerable <ILConstruct> > schemaRegenerationCodeProvider
     )
 {
     Contract.Requires(targetType != null);
     Contract.Requires(Enum.IsDefined(typeof(EnumMemberSerializationMethod), enumMemberSerializationMethod));
     Contract.Requires(Enum.IsDefined(typeof(DateTimeMemberConversionMethod), dateTimeConversionMethod));
     Contract.Ensures(Contract.Result <Action <TracingILGenerator, int> >() != null);
     return(null);
 }
        /// <summary>
        ///		Regisgters <see cref="MessagePackSerializer{T}"/> of target type usage to the current emitting session.
        /// </summary>
        /// <param name="targetType">The type of the member to be serialized/deserialized.</param>
        /// <param name="enumMemberSerializationMethod">The enum serialization method of the member to be serialized/deserialized.</param>
        /// <param name="dateTimeConversionMethod">The date time conversion method of the member to be serialized/deserialized.</param>
        /// <param name="polymorphismSchema">The schema for polymorphism support.</param>
        /// <param name="schemaRegenerationCodeProvider">The delegate to provide constructs to emit schema regeneration codes.</param>
        /// <returns>
        ///		<see cref=" Action{T1,T2}"/> to emit serializer retrieval instructions.
        ///		The 1st argument should be <see cref="TracingILGenerator"/> to emit instructions.
        ///		The 2nd argument should be argument index of the serializer holder, normally 0 (this pointer).
        ///		This value will not be <c>null</c>.
        /// </returns>
        public override Action <TracingILGenerator, int> RegisterSerializer(
            Type targetType,
            EnumMemberSerializationMethod enumMemberSerializationMethod,
            DateTimeMemberConversionMethod dateTimeConversionMethod,
            PolymorphismSchema polymorphismSchema,
            Func <IEnumerable <ILConstruct> > schemaRegenerationCodeProvider
            )
        {
            if (this._typeBuilder.IsCreated())
            {
                throw new InvalidOperationException("Type is already built.");
            }

            var key = new SerializerFieldKey(targetType, enumMemberSerializationMethod, dateTimeConversionMethod, polymorphismSchema);

            SerializerFieldInfo result;

            if (!this._serializers.TryGetValue(key, out result))
            {
                result =
                    new SerializerFieldInfo(
                        this._typeBuilder.DefineField(
                            "_serializer" + this._serializers.Count,
                            typeof(MessagePackSerializer <>).MakeGenericType(targetType),
                            FieldAttributes.Private | FieldAttributes.InitOnly),
                        il =>
                {
                    foreach (var construct in schemaRegenerationCodeProvider())
                    {
                        construct.Evaluate(il);
                    }
                }
                        );

                this._serializers.Add(key, result);
            }

            return
                ((il, thisIndex) =>
            {
                il.EmitAnyLdarg(thisIndex);
                il.EmitLdfld(result.Field);
            });
        }
Exemplo n.º 9
0
        public string RegisterSerializer(Type targetType, EnumMemberSerializationMethod enumSerializationMethod, DateTimeMemberConversionMethod dateTimeConversionMethod, PolymorphismSchema polymorphismSchema)
        {
            var key = new SerializerFieldKey(targetType, enumSerializationMethod, dateTimeConversionMethod, polymorphismSchema);

            string fieldName;

            if (!this._dependentSerializers.TryGetValue(key, out fieldName))
            {
                fieldName = "_serializer" + this._dependentSerializers.Count.ToString(CultureInfo.InvariantCulture);
                this._dependentSerializers.Add(key, fieldName);
                this._buildingType.Members.Add(
                    new CodeMemberField(
                        typeof(MessagePackSerializer <>).MakeGenericType(Type.GetTypeFromHandle(key.TypeHandle)),
                        fieldName
                        )
                {
                    Attributes = MemberAttributes.Private
                }
                    );
            }

            return(fieldName);
        }
Exemplo n.º 10
0
        public string GetSerializerFieldName(Type targetType, EnumMemberSerializationMethod enumSerializationMethod, DateTimeMemberConversionMethod dateTimeConversionMethod, PolymorphismSchema polymorphismSchema)
        {
            var key = new SerializerFieldKey(targetType, enumSerializationMethod, dateTimeConversionMethod, polymorphismSchema);

            string fieldName;

            if (!this._dependentSerializers.TryGetValue(key, out fieldName))
            {
                fieldName = "_serializer" + this._dependentSerializers.Count.ToString(CultureInfo.InvariantCulture);
                this._dependentSerializers.Add(key, fieldName);
            }

            return(fieldName);
        }