Beispiel #1
0
        public InstantFigure(IList <MemberInfo> membersInfo, string typeName, FigureMode modeType = FigureMode.Reference)
        {
            TypeName = typeName;
            Mode     = modeType;

            members = CreateMemberRurics(membersInfo);

            Rubrics            = new MemberRubrics();
            Rubrics.KeyRubrics = new MemberRubrics();
            foreach (MemberRubric mr in members)
            {
                Rubrics.Add(mr);
            }

            if (modeType == FigureMode.Reference)
            {
                InstantFigureReferenceCompiler rtbld = new InstantFigureReferenceCompiler(this);
                compiledType = rtbld.CompileFigureType(typeName);
            }
            else
            {
                InstantFigureValueTypeCompiler rtbld = new InstantFigureValueTypeCompiler(this);
                compiledType = rtbld.CompileFigureType(typeName);
            }

            Figure     = (IFigure)compiledType.New();
            FigureType = Figure.GetType();
            FigureSize = Marshal.SizeOf(FigureType);

            if (!membersInfo.Where(m => m.Name == "SystemSerialCode").Any())
            {
                members = new MemberRubric[] { new MemberRubric(FigureType.GetProperty("SystemSerialCode")) }
            }
        private FieldBuilder[] CreateFieldsAndProperties(TypeBuilder tb, MemberRubrics members)
        {
            for (int i = scode; i < length + scode; i++)
            {
                MemberInfo mi   = members[i - scode];
                Type       type = null;
                string     name = mi.Name;
                if (mi.MemberType == MemberTypes.Field)
                {
                    if (mi is MemberRubric)
                    {
                        type = ((MemberRubric)mi).RubricType;
                    }
                    else
                    {
                        type = ((FieldInfo)mi).FieldType;
                    }
                }
                else if (mi.MemberType == MemberTypes.Property)
                {
                    if (mi is MemberRubric)
                    {
                        type = ((MemberRubric)mi).RubricType;
                    }
                    else
                    {
                        type = ((PropertyInfo)mi).PropertyType;
                    }
                }
                if (type.IsArray && !type.GetElementType().IsValueType)
                {
                    type = null;
                }
                else if (!type.IsArray && !type.IsValueType && type != typeof(string))
                {
                    type = null;
                }

                if (type != null)
                {
                    FieldBuilder fb = CreateField(tb, mi, type, name);

                    if (fb != null)
                    {
                        PropertyBuilder pi = CreateProperty(tb, fb, type, name);
                        fields[i] = fb;
                        props[i]  = pi;
                        pi.SetCustomAttribute(new CustomAttributeBuilder(dataMemberCtor, new object[0], dataMemberProps, new object[2] {
                            i - scode, name
                        }));
                    }
                }
            }

            return(fields);
        }
Beispiel #3
0
        private MemberRubrics CloneRubrics()
        {
            var rbrcs = new MemberRubrics();

            rbrcs.KeyRubrics = new MemberRubrics();
            foreach (var rbrc in Figure.Rubrics.AsValues())
            {
                rbrcs.Add(new MemberRubric(rbrc));
            }
            return(rbrcs);
        }