[Fact] public unsafe void InstantFigure_ExtractOperations_Test() { InstantFigure referenceType = new InstantFigure(InstantFigureMocks.InstantFigure_MemberRubric_FieldsAndPropertiesModel(), "InstantFigure_MemberRubric_FieldsAndPropertiesModel_Reference"); FieldsAndPropertiesModel fom = new FieldsAndPropertiesModel(); object rts = InstantFigure_Compilation_Helper_Test(referenceType, fom); IntPtr pserial = rts.GetStructureIntPtr(); object rts2 = referenceType.NewObject(); pserial.ToStructure(rts2); byte[] bserial = rts2.GetBytes(); object rts3 = referenceType.NewObject(); bserial.ToStructure(rts3); object rts4 = referenceType.NewObject(); rts4.StructureFrom(bserial); InstantFigure valueType = new InstantFigure(InstantFigureMocks.InstantFigure_MemberRubric_FieldsAndPropertiesModel(), "InstantFigure_MemberRubric_FieldsAndPropertiesModel_ValueType", FigureMode.ValueType); fom = new FieldsAndPropertiesModel(); object vts = InstantFigure_Compilation_Helper_Test(valueType, fom); ValueType v = (ValueType)vts; IntPtr pserial2 = vts.GetStructureIntPtr(); object vts2 = valueType.NewObject(); ValueType v2 = (ValueType)vts2; vts2 = pserial2.ToStructure(vts2); byte[] bserial2 = vts.GetBytes(); object vts3 = valueType.NewObject(); fixed(byte *b = bserial2) vts3 = Extractor.PointerToStructure(b, vts3); object vts4 = valueType.NewObject(); vts4 = vts4.StructureFrom(pserial2); Marshal.FreeHGlobal((IntPtr)pserial2); }
private object InstantFigure_Compilation_Helper_Test(InstantFigure str, FieldsAndPropertiesModel fom) { object rts = str.NewObject(); fom.Id = 202; ((IFigure)rts)[0] = 202; Assert.Equal(fom.Id, ((IFigure)rts)[0]); ((IFigure)rts)["Id"] = 404; Assert.NotEqual(fom.Id, ((IFigure)rts)[nameof(fom.Id)]); ((IFigure)rts)[nameof(fom.Name)] = fom.Name; Assert.Equal(fom.Name, ((IFigure)rts)[nameof(fom.Name)]); ((IFigure)rts).SystemSerialCode = new Ussn(DateTime.Now.ToBinary()); string hexTetra = ((IFigure)rts).SystemSerialCode.ToString(); Ussn ssn = new Ussn(hexTetra); Assert.Equal(ssn, ((IFigure)rts).SystemSerialCode); for (int i = 1; i < str.Rubrics.Count; i++) { var r = str.Rubrics[i].RubricInfo; if (r.MemberType == MemberTypes.Field) { var fi = fom.GetType().GetField(((FieldInfo)r).Name); if (fi != null) { ((IFigure)rts)[r.Name] = fi.GetValue(fom); } } if (r.MemberType == MemberTypes.Property) { var pi = fom.GetType().GetProperty(((PropertyInfo)r).Name); if (pi != null) { ((IFigure)rts)[r.Name] = pi.GetValue(fom); } } } for (int i = 1; i < str.Rubrics.Count; i++) { var r = str.Rubrics[i].RubricInfo; if (r.MemberType == MemberTypes.Field) { var fi = fom.GetType().GetField(((FieldInfo)r).Name); if (fi != null) { Assert.Equal(((IFigure)rts)[r.Name], fi.GetValue(fom)); } } if (r.MemberType == MemberTypes.Property) { var pi = fom.GetType().GetProperty(((PropertyInfo)r).Name); if (pi != null) { Assert.Equal(((IFigure)rts)[r.Name], pi.GetValue(fom)); } } } return(rts); }