// Use this for initialization void Start() { feeding_rate = power / defence; SimpleStruct ss = new SimpleStruct(); ss.X = 500; ss.DisplayX(); }
public static SimpleStruct Test1(SimpleStruct ss) { Console.WriteLine ("Test1 called " + ss.a + " " + ss.b); SimpleStruct res = new SimpleStruct (); res.a = !ss.a; res.b = !ss.b; return res; }
public void testCall1() { var x = new SimpleStruct(); var a = ModifyA(x); AssertEquals("x.a", 0, x.a); AssertEquals("a", 27, a); }
public static void Main() { SimpleStruct ss = new SimpleStruct(); ss.X = 5; ss.DisplayX(); SS si = (SS) ss; si.X = 90; si.DisplayX(); ss = (SimpleStruct) si ; ss.X = 5; ss.DisplayX(); SimpleClass ss1 = new SimpleClass(); ss1.X = 5; ss1.DisplayX(); try { ss1 = (SimpleClass) si ; ss1.X = 5; ss1.DisplayX(); } catch(Exception) { Console.WriteLine("Failed to cast"); } }
static SimpleStruct MethodWithStructArgs(string label, SimpleStruct ss_arg, int x) { Console.WriteLine($"- ss_arg: {ss_arg.str_member}"); ss_arg.Kind = DateTimeKind.Utc; ss_arg.str_member = $"ValueTypesTest#MethodWithStructArgs#updated#ss_arg#str_member"; ss_arg.gs.StringField = $"ValueTypesTest#MethodWithStructArgs#updated#gs#StringField#{x}"; return(ss_arg); }
public void GetClone_Struct_Cloned() { var source = new SimpleStruct() { Property = 10, _field = 3 }; var target = CloneFactory.GetClone(source); }
public static SimpleStruct aMethod_Inline(SimpleStruct Struct) { Struct.i = 10; Struct.str = "abc"; int x = Struct.i; string str1 = Struct.str; return Struct; }
public static void TestIncrementAssignmentInStructs() { var ss = new SimpleStruct(5); ss.DoubleIncrement(); Assert.AreEqual(7, ss.GetField()); }
public void Initialize() { MyInt16 = 1; MyInt32 = 2; MyInt64 = 3; MyUInt16 = 4; MyUInt32 = 5; MyUInt64 = 6; MyByte = 7; MySByte = 8; MyChar = 'a'; MyString = "Hello"; MyBooleanTrue = true; MyBooleanFalse = false; MySingle = 1.1f; MyDouble = 2.2d; MyDecimal = 3.3m; MyDateTime = new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc); MyDateTimeOffset = new DateTimeOffset(2019, 1, 30, 12, 1, 2, new TimeSpan(1, 0, 0)); MyEnum = SampleEnum.Two; MyInt64Enum = SampleEnumInt64.MinNegative; MyUInt64Enum = SampleEnumUInt64.Max; MySimpleStruct = new SimpleStruct { One = 11, Two = 1.9999 }; MyInt16Array = new short[] { 1 }; MyInt32Array = new int[] { 2 }; MyInt64Array = new long[] { 3 }; MyUInt16Array = new ushort[] { 4 }; MyUInt32Array = new uint[] { 5 }; MyUInt64Array = new ulong[] { 6 }; MyByteArray = new byte[] { 7 }; MySByteArray = new sbyte[] { 8 }; MyCharArray = new char[] { 'a' }; MyStringArray = new string[] { "Hello" }; MyBooleanTrueArray = new bool[] { true }; MyBooleanFalseArray = new bool[] { false }; MySingleArray = new float[] { 1.1f }; MyDoubleArray = new double[] { 2.2d }; MyDecimalArray = new decimal[] { 3.3m }; MyDateTimeArray = new DateTime[] { new DateTime(2019, 1, 30, 12, 1, 2, DateTimeKind.Utc) }; MyDateTimeOffsetArray = new DateTimeOffset[] { new DateTimeOffset(2019, 1, 30, 12, 1, 2, new TimeSpan(1, 0, 0)) }; MyEnumArray = new SampleEnum[] { SampleEnum.Two }; MyStringList = new List <string>() { "Hello" }; MyStringIEnumerableT = new string[] { "Hello" }; MyStringIListT = new string[] { "Hello" }; MyStringICollectionT = new string[] { "Hello" }; MyStringIReadOnlyCollectionT = new string[] { "Hello" }; MyStringIReadOnlyListT = new string[] { "Hello" }; MyStringISetT = new HashSet <string> { "Hello" }; }
public void testLocalVar1() { var x = new SimpleStruct(); x.a = 5; var y = x; y.a = 6; AssertEquals("x.a", 5, x.a); AssertEquals("y.a", 6, y.a); }
public ReadOnlyBase(string foo) { obj = new SimpleClass() { member = 100 }; member = foo; simpleStruct = new SimpleStruct(); }
public static SimpleStruct Test1(SimpleStruct ss) { Console.WriteLine("Test1 called " + ss.a + " " + ss.b); SimpleStruct res = new SimpleStruct(); res.a = !ss.a; res.b = !ss.b; return(res); }
public static int test_0_marshal_lpstruct() { SimpleStruct ss = new SimpleStruct(); ss.b = true; ss.d = "TEST"; return(mono_test_marshal_lpstruct(ss)); }
public static bool InstanceDelegateWithStruct() { Delegates delegates = new Delegates(); SimpleStruct simpleStruct = new SimpleStruct(); simpleStruct.i = 2; simpleStruct.j = 3; StructDel sd = new StructDel(delegates.StructAsArgument); int result = sd(simpleStruct); return result == 5 ? true : false; }
public static void Main() { Console.WriteLine("instaniante a ss structure object"); SimpleStruct ss = new SimpleStruct(); Console.WriteLine("Set the integer to 5 in the ss structure object"); ss.X = 5; Console.WriteLine("Call the Displayx function in the ss structure object"); ss.DisplayX(); }
private void should_implement_ISimpleMethodsWithOutParameters() { Execute(() => { var @object = new ImplementSimpleMethodsClass(); var @interface = @object as ISimpleMethodsWithOutParameters; var p1 = 1; var p2 = "a"; var p3 = new SimpleStruct(1); var p4 = new SimpleClass(1); var p5 = new[] { 1 }; var p6 = new[] { "a" }; var p7 = new[] { new SimpleStruct(1) }; var p8 = new[] { new SimpleClass(1) }; var p9 = new List <int> { 1 }; var p10 = new List <string> { "a" }; var p11 = new List <SimpleStruct> { new SimpleStruct(1) }; var p12 = new List <SimpleClass> { new SimpleClass(1) }; int out1; string out2; SimpleStruct out3; SimpleClass out4; int[] out5; string[] out6; SimpleStruct[] out7; SimpleClass[] out8; List <int> out9; List <string> out10; List <SimpleStruct> out11; List <SimpleClass> out12; @interface.ReturnOutParameters(out out1, out out2, out out3, out out4, out out5, out out6, out out7, out out8, out out9, out out10, out out11, out out12); Assert.Equal(p1, out1); Assert.Equal(p2, out2); Assert.Equal(p3.Value, out3.Value); Assert.Equal(p4.Value, out4.Value); Assert.Equal(p5[0], out5[0]); Assert.Equal(p6[0], out6[0]); Assert.Equal(p7[0].Value, out7[0].Value); Assert.Equal(p8[0].Value, out8[0].Value); Assert.Equal(p9[0], out9[0]); Assert.Equal(p10[0], out10[0]); Assert.Equal(p11[0].Value, out11[0].Value); Assert.Equal(p12[0].Value, out12[0].Value); }); }
public static SimpleStruct aMethod_Inline(SimpleStruct Struct) { Struct.i = 10; Struct.str = "abc"; int x = Struct.i; string str1 = Struct.str; return(Struct); }
public void ReadTStruct() { MemoryBufferAddressSpace dataSource = new MemoryBufferAddressSpace(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }); Reader reader = new Reader(dataSource); SimpleStruct s = reader.Read <SimpleStruct>(1); Assert.Equal(0x05040302, s.X); Assert.Equal(0x0706, s.Y); }
private void return_string_with_original_parameters_values_when_ReturnOriginalRefParametersAsString_is_called() { Execute(() => { var instance = new InterceptMethodsClass(); var p1 = 1; var p2 = "a"; var p3 = new SimpleStruct(1); var p4 = new SimpleClass(1); var p5 = new[] { 1 }; var p6 = new[] { "a" }; var p7 = new[] { new SimpleStruct(1) }; var p8 = new[] { new SimpleClass(1) }; var p9 = new List <int> { 1 }; var p10 = new List <string> { "a" }; var p11 = new List <SimpleStruct> { new SimpleStruct(1) }; var p12 = new List <SimpleClass> { new SimpleClass(1) }; var expected = Helper.AsString(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); var ref1 = p1; var ref2 = p2; var ref3 = p3; var ref4 = p4; var ref5 = p5; var ref6 = p6; var ref7 = p7; var ref8 = p8; var ref9 = p9; var ref10 = p10; var ref11 = p11; var ref12 = p12; var result = instance.ReturnOriginalRefParametersAsString(ref ref1, ref ref2, ref ref3, ref ref4, ref ref5, ref ref6, ref ref7, ref ref8, ref ref9, ref ref10, ref ref11, ref ref12); Assert.Equal(expected, result); Assert.Equal(p1, ref1); Assert.Same(p2, ref2); Assert.Equal(p3, ref3); Assert.Same(p4, ref4); Assert.Same(p5, ref5); Assert.Same(p6, ref6); Assert.Same(p7, ref7); Assert.Same(p8, ref8); Assert.Same(p9, ref9); Assert.Same(p10, ref10); Assert.Same(p11, ref11); Assert.Same(p12, ref12); }); }
/* Test structures as in arguments of delegates */ public static int test_0_marshal_in_struct_delegate() { SimpleStruct ss = new SimpleStruct() { a = true, b = false, c = true, d = "TEST2" }; InStructDelegate d = new InStructDelegate(delegate_test_struct_in); return(mono_test_marshal_in_struct(1, ref ss, 2, d)); }
public void ShouldSerializeSimpleStruct() { var str = new SimpleStruct { A = 5, B = "allman" }; var copy = SerializerClone(str); Assert.AreEqual(str, copy); }
public static int delegate_test_struct_out(int a, out SimpleStruct ss, int b) { ss.a = true; ss.b = true; ss.c = true; ss.d = "TEST3"; ss.d2 = "TEST4"; return(0); }
public void SimpleStructWrite() { var writer = new BitBufferWriter <SevenBitEncoding <u32ArrayMemory> >(); var expected = new SimpleStruct { a = 1.2f, b = 123, c = byte.MaxValue, d = ushort.MaxValue }; writer.block(in expected); Assert.True(writer.LengthWritten < Unsafe.SizeOf <SimpleStruct>()); }
public static int delegate_test_struct_out (int a, out SimpleStruct ss, int b) { ss.a = true; ss.b = true; ss.c = true; ss.d = "TEST3"; ss.d2 = "TEST4"; return 0; }
public void testArray1() { var x = new SimpleStruct[5]; var y = new SimpleStruct[5]; x[0].a = 5; y[0] = x[0]; y[0].a = 6; AssertEquals("x[0].a", 5, x[0].a); AssertEquals("y[0].a", 6, y[0].a); }
static int Main () { Type t = typeof (Test); MethodInfo m2 = t.GetMethod ("Test2"); if (m2 != null) return 1; MethodInfo m1 = t.GetMethod ("Test1"); if (m1 == null) return 1; object [] args = new object [1]; SimpleStruct ss = new SimpleStruct (); ss.a = true; ss.b = false; args [0] = ss; SimpleStruct res = (SimpleStruct)m1.Invoke (null, args); if (res.a == true) return 1; if (res.b == false) return 1; // Test that the objects for byref valuetype arguments are // automatically created MethodInfo m3 = typeof(Test).GetMethod("Foo"); args = new object[2]; m3.Invoke(null, args); if ((((int)(args [0])) != 20) || (((int)(args [1])) != 30)) return 2; // Test the return value from ConstructorInfo.Invoke when a precreated // valuetype is used. ConstructorInfo ci = typeof (SimpleStruct).GetConstructor (new Type [] { typeof (bool) }); ci.Invoke (ss, new object [] { false }); // Test invoking of the array Get/Set methods string[,] arr = new string [10, 10]; arr.GetType ().GetMethod ("Set").Invoke (arr, new object [] { 1, 1, "FOO" }); string s = (string)arr.GetType ().GetMethod ("Get").Invoke (arr, new object [] { 1, 1 }); if (s != "FOO") return 3; // Test the sharing of runtime invoke wrappers for string ctors typeof (string).GetConstructor (new Type [] { typeof (char[]) }).Invoke (null, new object [] { new char [] { 'a', 'b', 'c' } }); typeof (Assembly).GetMethod ("GetType", new Type [] { typeof (string), }).Invoke (typeof (int).Assembly, new object [] { "A" }); return 0; }
private void return_string_with_original_parameters_values_when_ReturnOriginalOutParameters_is_called() { Execute(() => { var instance = new InterceptMethodsClass(); var p1 = 1; var p2 = "a"; var p3 = new SimpleStruct(1); var p4 = new SimpleClass(1); var p5 = new[] { 1 }; var p6 = new[] { "a" }; var p7 = new[] { new SimpleStruct(1) }; var p8 = new[] { new SimpleClass(1) }; var p9 = new List <int> { 1 }; var p10 = new List <string> { "a" }; var p11 = new List <SimpleStruct> { new SimpleStruct(1) }; var p12 = new List <SimpleClass> { new SimpleClass(1) }; int out1; string out2; SimpleStruct out3; SimpleClass out4; int[] out5; string[] out6; SimpleStruct[] out7; SimpleClass[] out8; List <int> out9; List <string> out10; List <SimpleStruct> out11; List <SimpleClass> out12; instance.ReturnOriginalOutParameters(out out1, out out2, out out3, out out4, out out5, out out6, out out7, out out8, out out9, out out10, out out11, out out12); Assert.Equal(p1, out1); Assert.Equal(p2, out2); Assert.Equal(p3.Value, out3.Value); Assert.Equal(p4.Value, out4.Value); Assert.Equal(p5[0], out5[0]); Assert.Equal(p6[0], out6[0]); Assert.Equal(p7[0].Value, out7[0].Value); Assert.Equal(p8[0].Value, out8[0].Value); Assert.Equal(p9[0], out9[0]); Assert.Equal(p10[0], out10[0]); Assert.Equal(p11[0].Value, out11[0].Value); Assert.Equal(p12[0].Value, out12[0].Value); }); }
public void GetHashCode_should_return_value_for_struct() { var instance = new SimpleStruct(); instance.X = 1; instance.Y = 2; var result = instance.GetHashCode(); Assert.NotEqual(0, result); }
public void SimpleStructTest() { var s = new SimpleStruct(1, "2") { Ignored = "3" }; var c = Cloner.Clone(s); Assert(s.Computed == c.Computed); Assert(c.Ignored == null); }
private void return_string_with_intercepted_parameters_values_when_ReturnInterceptedOutParameters_is_called() { Execute(() => { var instance = new InterceptMethodsClass(); var interceptedP1 = 2; var interceptedP2 = "ab"; var interceptedP3 = new SimpleStruct(2); var interceptedP4 = new SimpleClass(2); var interceptedP5 = new[] { 2, 1 }; var interceptedP6 = new[] { "cd", "ab" }; var interceptedP7 = new[] { new SimpleStruct(2), new SimpleStruct(1) }; var interceptedP8 = new[] { new SimpleClass(2), new SimpleClass(1) }; var interceptedP9 = new List <int> { 2, 1 }; var interceptedP10 = new List <string> { "cd", "ab" }; var interceptedP11 = new List <SimpleStruct> { new SimpleStruct(2), new SimpleStruct(1) }; var interceptedP12 = new List <SimpleClass> { new SimpleClass(2), new SimpleClass(1) }; int out1; string out2; SimpleStruct out3; SimpleClass out4; int[] out5; string[] out6; SimpleStruct[] out7; SimpleClass[] out8; List <int> out9; List <string> out10; List <SimpleStruct> out11; List <SimpleClass> out12; instance.ReturnInterceptedOutParameters(out out1, out out2, out out3, out out4, out out5, out out6, out out7, out out8, out out9, out out10, out out11, out out12); Assert.Equal(interceptedP1, out1); Assert.Equal(interceptedP2, out2); Assert.Equal(interceptedP3.Value, out3.Value); Assert.Equal(interceptedP4.Value, out4.Value); Assert.Equal(interceptedP5[0], out5[0]); Assert.Equal(interceptedP6[0], out6[0]); Assert.Equal(interceptedP7[0].Value, out7[0].Value); Assert.Equal(interceptedP8[0].Value, out8[0].Value); Assert.Equal(interceptedP9[0], out9[0]); Assert.Equal(interceptedP10[0], out10[0]); Assert.Equal(interceptedP11[0].Value, out11[0].Value); Assert.Equal(interceptedP12[0].Value, out12[0].Value); }); }
public static int test_0_return_vtype() { SimpleStruct ss = mono_test_return_vtype(new IntPtr(5)); if (!ss.a && ss.b && !ss.c && ss.d == "TEST" && ss.d2 == "TEST2") { return(0); } return(1); }
public static void Main() { SimpleStruct ss = new SimpleStruct(); ss.X = 5; ss.DisplayX(); SS si = (SS)ss; si.X = 90; si.DisplayX(); }
public static void MethodWithStructs() { var ss = new SimpleStruct(); ss.gs.StringField = "field in GenericStruct"; var ss_arr = new SimpleStruct [] {}; var gs = new GenericStruct <Math> (); Math m = new Math(); Console.WriteLine($"Using the struct: {ss.dt}, {ss.gs.StringField}, ss_arr: {ss_arr.Length}, gs: {gs.StringField}"); }
public void ShouldSerializeStructInClass() { var str = new SimpleStruct { A = 1, B = "allman" }; var box = new GenericBox <SimpleStruct> { Element = str }; var copy = SerializerClone(box); Assert.AreEqual(str, copy.Element); }
public unsafe void OptionalInOutStructPointer() { var test = new SimpleStruct { I = 5 }; void *addr = &test; NativeFunctions.AddOne((IntPtr)addr); Assert.Equal(6, test.I); }
public static SimpleStruct delegate_test_struct(SimpleStruct ss) { SimpleStruct res; res.a = !ss.a; res.b = !ss.b; res.c = !ss.c; res.d = ss.d + "-RES"; res.d2 = ss.d2 + "-RES"; return(res); }
public void Union_2Items_MultipleStructs_RoundTrip() { var simpleStruct1 = new SimpleStruct { Long = 3 }; var simpleStruct2 = new SimpleStruct2 { Long = 4 }; Assert.AreEqual(simpleStruct1.Long, CreateAndDeserialize1(simpleStruct1, simpleStruct2).Long); Assert.AreEqual(simpleStruct2.Long, CreateAndDeserialize2(simpleStruct1, simpleStruct2).Long); }
public void Validate_MarshalSeriazlier() { SimpleStruct data = new SimpleStruct(); MarshalSerializer <SimpleStruct> serializer = new MarshalSerializer <SimpleStruct>(); var bytes = serializer.ObjectToBytes(data); var result = serializer.BytesToObject(bytes); Assert.AreEqual(data.Num, result.Num); Assert.AreEqual(data.Age, result.Age); Assert.AreEqual(data.False, result.False); Assert.AreEqual(data.La, result.La); }
public static SimpleStruct delegate_test_struct (SimpleStruct ss) { SimpleStruct res; res.a = !ss.a; res.b = !ss.b; res.c = !ss.c; res.d = ss.d + "-RES"; res.d2 = ss.d2 + "-RES"; return res; }
public static int delegate_test_struct_byref (int a, ref SimpleStruct ss, int b) { if (a == 1 && b == 2 && ss.a && !ss.b && ss.c && ss.d == "TEST2") { ss.a = true; ss.b = true; ss.c = true; ss.d = "TEST3"; return 0; } return 1; }
public static int test_0_ctor_vtype () { // Test the return value from ConstructorInfo.Invoke when a precreated // valuetype is used. SimpleStruct ss = new SimpleStruct (); ss.a = true; ss.b = false; ConstructorInfo ci = typeof (SimpleStruct).GetConstructor (new Type [] { typeof (bool) }); ci.Invoke (ss, new object [] { false }); return 0; }
static int Main() { Type t = typeof (Test); MethodInfo m2 = t.GetMethod ("Test2"); if (m2 != null) return 1; MethodInfo m1 = t.GetMethod ("Test1"); if (m1 == null) return 1; object [] args = new object [1]; SimpleStruct ss = new SimpleStruct (); ss.a = true; ss.b = false; args [0] = ss; SimpleStruct res = (SimpleStruct)m1.Invoke (null, args); if (res.a == true) return 1; if (res.b == false) return 1; // Test that the objects for byref valuetype arguments are // automatically created MethodInfo m3 = typeof(Test).GetMethod("Foo"); args = new object[2]; m3.Invoke(null, args); if ((((int)(args [0])) != 20) || (((int)(args [1])) != 30)) return 2; return 0; }
/* Test structures as in arguments of delegates */ public static int test_0_marshal_in_struct_delegate () { SimpleStruct ss = new SimpleStruct () { a = true, b = false, c = true, d = "TEST2" }; InStructDelegate d = new InStructDelegate (delegate_test_struct_in); return mono_test_marshal_in_struct (1, ref ss, 2, d); }
/* Test structures as out arguments of delegates */ public static int test_0_marshal_out_struct_delegate () { SimpleStruct ss = new SimpleStruct (); OutStructDelegate d = new OutStructDelegate (delegate_test_struct_out); return mono_test_marshal_out_struct (1, out ss, 2, d); }
/* Test structures as byref arguments of delegates */ public static int test_0_marshal_byref_struct_delegate () { SimpleStruct ss = new SimpleStruct (); TestDelegate d = new TestDelegate (delegate_test_struct_byref); ss.b = true; ss.d = "TEST1"; if (mono_test_ref_vtype (1, ref ss, 2, d) != 0) return 1; if (! (ss.a && ss.b && ss.c && ss.d == "TEST3")) return 2; return 0; }
public static extern int mono_test_marshal_in_struct (int a, ref SimpleStruct ss, int b, InStructDelegate d);
public static extern int mono_test_marshal_out_struct (int a, out SimpleStruct ss, int b, OutStructDelegate d);
public Ctor500(int arg1, bool arg2, string arg3, object arg4, EnumInt32 arg5, SimpleClass arg6, SimpleStruct arg7) { }
public NestedStruct(double firstValue, string secondValue, double innerStructFirstValue, string innerStructSecondValue) { FirstValue = firstValue; SecondValue = secondValue; InnerStruct = new SimpleStruct(innerStructFirstValue, innerStructSecondValue); }
public SimpleClassWithSimpleStruct(double structFirstValue, string structSecondValue) { Struct = new SimpleStruct(structFirstValue, structSecondValue); }
public int StructAsArgument(SimpleStruct simpleStruct) { return simpleStruct.i + simpleStruct.j; }
static int Main() { Type t = typeof (Test); MethodInfo m2 = t.GetMethod ("Test2"); if (m2 != null) return 1; MethodInfo m1 = t.GetMethod ("Test1"); if (m1 == null) return 1; object [] args = new object [1]; SimpleStruct ss = new SimpleStruct (); ss.a = true; ss.b = false; args [0] = ss; SimpleStruct res = (SimpleStruct)m1.Invoke (null, args); if (res.a == true) return 1; if (res.b == false) return 1; MethodInfo m3 = typeof(Test).GetMethod("Foo"); args = new object[2]; m3.Invoke(null, args); if ((((int)(args [0])) != 20) || (((int)(args [1])) != 30)) return 2; ConstructorInfo ci = typeof (SimpleStruct).GetConstructor (new Type [] { typeof (bool) }); SimpleStruct res2 = (SimpleStruct)ci.Invoke (ss, new object [] { false }); string[,] arr = new string [10, 10]; arr.GetType ().GetMethod ("Set").Invoke (arr, new object [] { 1, 1, "FOO" }); string s = (string)arr.GetType ().GetMethod ("Get").Invoke (arr, new object [] { 1, 1 }); if (s != "FOO") return 3; return 0; }
// try this with keyword args, unpack tuple public void M700(int arg1, string arg2, bool arg3, object arg4, EnumInt16 arg5, SimpleClass arg6, SimpleStruct arg7) { }
public static int test_0_structure_to_ptr () { SimpleStruct ss = new SimpleStruct (); int size = Marshal.SizeOf (typeof (SimpleStruct)); //if (size != 52) //return 1; IntPtr p = Marshal.AllocHGlobal (size); ss.a = 1; ss.bool1 = true; ss.bool2 = false; ss.b = 2; ss.a1 = new short [2]; ss.a1 [0] = 6; ss.a1 [1] = 5; ss.s1 = "abcd"; ss.emb1 = new SimpleStruct2 (); ss.emb1.a = 3; ss.emb1.b = 4; ss.emb2 = new SimpleObj (); ss.emb2.a = 10; ss.emb2.b = 11; ss.s2 = "just a test"; ss.x = 1.5; ss.a2 = new char [2]; ss.a2 [0] = 'a'; ss.a2 [1] = 'b'; Marshal.StructureToPtr (ss, p, false); Type t = ss.GetType (); if (Marshal.ReadInt32 (p, (int)Marshal.OffsetOf (t, "a")) != 1) return 1; if (Marshal.ReadInt32 (p, (int)Marshal.OffsetOf (t, "bool1")) != 1) return 2; if (Marshal.ReadInt32 (p, (int)Marshal.OffsetOf (t, "bool2")) != 0) return 3; if (Marshal.ReadInt32 (p, (int)Marshal.OffsetOf (t, "b")) != 2) return 4; if (Marshal.ReadInt16 (p, 16) != 6) return 5; if (Marshal.ReadInt16 (p, 18) != 5) return 6; if (Marshal.ReadByte (p, 20) != 97) return 7; if (Marshal.ReadByte (p, 21) != 98) return 8; if (Marshal.ReadByte (p, 22) != 99) return 9; if (Marshal.ReadByte (p, 23) != 0) return 10; if (Marshal.ReadInt32 (p, 24) != 3) return 11; if (Marshal.ReadInt32 (p, 28) != 4) return 12; if (Marshal.ReadInt32 (p, 32) != 10) return 13; if (Marshal.ReadInt32 (p, 36) != 11) return 14; if (Marshal.ReadByte (p, (int)Marshal.OffsetOf (t, "a2")) != 97) return 15; if (Marshal.ReadByte (p, (int)Marshal.OffsetOf (t, "a2") + 1) != 98) return 16; SimpleStruct cp = (SimpleStruct)Marshal.PtrToStructure (p, ss.GetType ()); if (cp.a != 1) return 16; if (cp.bool1 != true) return 17; if (cp.bool2 != false) return 18; if (cp.b != 2) return 19; if (cp.a1 [0] != 6) return 20; if (cp.a1 [1] != 5) return 21; if (cp.s1 != "abc") return 22; if (cp.emb1.a != 3) return 23; if (cp.emb1.b != 4) return 24; if (cp.emb2.a != 10) return 25; if (cp.emb2.b != 11) return 26; if (cp.s2 != "just a test") return 27; if (cp.x != 1.5) return 28; if (cp.a2 [0] != 'a') return 29; if (cp.a2 [1] != 'b') return 30; return 0; }
public static extern int mono_test_ref_vtype (int a, ref SimpleStruct ss, int b, TestDelegate d);
public static int test_0_marshal_struct() { SimpleStruct ss = new SimpleStruct (); ss.b = true; ss.d = "TEST"; return mono_test_marshal_struct (ss); }
public static void Main() { SimpleStruct ss = new SimpleStruct(); ss.X = 5; ss.DisplayX(); }