Esempio n. 1
0
        /// <summary>
        /// The CompileFigureType.
        /// </summary>
        /// <param name="typeName">The typeName<see cref="string"/>.</param>
        /// <returns>The <see cref="Type"/>.</returns>
        public override Type CompileFigureType(string typeName)
        {
            derivedFields = new FieldRubric[length + scode];

            TypeBuilder tb = GetTypeBuilder(typeName);

            CreateSerialCodeProperty(tb, typeof(Ussn), "SerialCode");

            CreateFieldsAndProperties(tb);

            CreateValueArrayProperty(tb);

            CreateItemByIntProperty(tb);

            CreateItemByStringProperty(tb);

            CreateUniqueKeyProperty(tb);

            CreateUniqueSeedProperty(tb);

            CreateGetUniqueBytesMethod(tb);

            CreateGetBytesMethod(tb);

            CreateGetEmptyProperty(tb);

            CreateEqualsMethod(tb);

            CreateCompareToMethod(tb);

            return(tb.CreateTypeInfo());
        }
Esempio n. 2
0
        /// <summary>
        /// The CreateSerialCodeProperty.
        /// </summary>
        /// <param name="tb">The tb<see cref="TypeBuilder"/>.</param>
        /// <param name="type">The type<see cref="Type"/>.</param>
        /// <param name="name">The name<see cref="string"/>.</param>
        public override void CreateSerialCodeProperty(TypeBuilder tb, Type type, string name)
        {
            scodeField = tb.DefineField(name.ToLower(), type, FieldAttributes.Private);

            PropertyBuilder prop = tb.DefineProperty(name, PropertyAttributes.HasDefault,
                                                     type, new Type[] { type });

            PropertyInfo iprop = typeof(IFigure).GetProperty(name);

            MethodInfo accessor = iprop.GetGetMethod();

            ParameterInfo[] args     = accessor.GetParameters();
            Type[]          argTypes = Array.ConvertAll(args, a => a.ParameterType);

            MethodBuilder getter = tb.DefineMethod(accessor.Name, accessor.Attributes & ~MethodAttributes.Abstract,
                                                   accessor.CallingConvention, accessor.ReturnType, argTypes);

            tb.DefineMethodOverride(getter, accessor);

            prop.SetGetMethod(getter);
            ILGenerator il = getter.GetILGenerator();

            il.Emit(OpCodes.Ldarg_0);           // this
            il.Emit(OpCodes.Ldfld, scodeField); // load
            il.Emit(OpCodes.Ret);               // return

            MethodInfo mutator = iprop.GetSetMethod();

            args     = mutator.GetParameters();
            argTypes = Array.ConvertAll(args, a => a.ParameterType);

            MethodBuilder setter = tb.DefineMethod(mutator.Name, mutator.Attributes & ~MethodAttributes.Abstract,
                                                   mutator.CallingConvention, mutator.ReturnType, argTypes);

            tb.DefineMethodOverride(setter, mutator);

            prop.SetSetMethod(setter);
            il = setter.GetILGenerator();

            il.Emit(OpCodes.Ldarg_0);           // this
            il.Emit(OpCodes.Ldarg_1);           // value
            il.Emit(OpCodes.Stfld, scodeField); // assign
            il.Emit(OpCodes.Ret);

            prop.SetCustomAttribute(new CustomAttributeBuilder(
                                        dataMemberCtor, new object[0],
                                        dataMemberProps, new object[2] {
                0, name.ToUpper()
            }));

            derivedFields[0]            = new FieldRubric(scodeField.FieldType, name);
            derivedFields[0].RubricInfo = scodeField;
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemberRubric"/> class.
 /// </summary>
 /// <param name="field">The field<see cref="FieldRubric"/>.</param>
 public MemberRubric(FieldRubric field) : this((IMemberRubric)field)
 {
 }