Beispiel #1
0
        private void combineDynamicType(FigureCompiler compiler)
        {
            var fcvt = compiler;

            compiledType = fcvt.CompileFigureType(Name);
            Rubrics.KeyRubrics.Add(fcvt.Identities.Values);
            this.Type = compiledType.New().GetType();
            Size      = Marshal.SizeOf(this.Type);
            var rf = this.Type.GetRuntimeFields().ToArray();

            if (!Rubrics.AsValues().Where(m => m.Name == "SerialCode").Any())
            {
                var mr = new MemberRubric(rf[0]);
                mr.RubricName = "SerialCode";
                Rubrics.Insert(0, mr);
            }

            Rubrics.AsValues().Select((m, y) => m.FigureField = rf[y]).ToArray();
            Rubrics.AsValues().Where(m => m.FigureField != null)
            .Select((f, y) => new object[] {
                f.FieldId      = y - 1,
                f.RubricId     = y - 1,
                f.RubricOffset = (int)Marshal.OffsetOf(this.Type, f.FigureField.Name)
            })
            .ToArray();
        }
Beispiel #2
0
        private void combineDerivedType(FigureCompiler compiler)
        {
            var fcdt = compiler;

            compiledType = fcdt.CompileFigureType(Name);
            Rubrics.KeyRubrics.Add(fcdt.Identities.Values);
            this.Type = compiledType.New().GetType();
            Size      = Marshal.SizeOf(this.Type);

            if (!Rubrics.AsValues().Where(m => m.Name == "SerialCode").Any())
            {
                var f  = this.Type.GetField("serialcode", BindingFlags.NonPublic | BindingFlags.Instance);
                var mr = new MemberRubric(f);
                mr.RubricName   = "SerialCode";
                mr.FigureField  = f;
                mr.RubricOffset = (int)Marshal.OffsetOf(this.Type, f.Name);
                Rubrics.Insert(0, mr);
            }

            var df = fcdt.derivedFields;

            Rubrics.AsValues().Select((m, y) => m.FigureField = df[y].RubricInfo).ToArray();
            Rubrics.AsValues().Where(m => m.FigureField != null)
            .Select((f, y) => new object[] {
                f.FieldId  = y - 1,
                f.RubricId = y - 1
            })
            .ToArray();

            foreach (var rubric in Rubrics.Skip(1).ToArray())
            {
                try
                {
                    rubric.RubricOffset = (int)Marshal.OffsetOf(BaseType, rubric.FigureField.Name);
                }
                catch (Exception ex)
                {
                    rubric.RubricOffset = -1;
                }
            }
        }