示例#1
0
 public static void IncrementInvertPointerFieldsRefReturn(
     [DNNE.C99Type("struct ptr_fields")] PointerFields input,
     [DNNE.C99Type("struct ptr_fields*")] PointerFields *result)
 {
     *(result->i) = *(input.i) + 1;
     *(result->b) = !(*input.b);
     *(result->c) = (char)(*(input.c) + 1);
 }
示例#2
0
        public unsafe void ValidatePointerFields()
        {
            int  iInitial = 31;
            bool bInitial = false;
            char cInitial = 'A';

            int  iExpected = iInitial + 1;
            bool bExpected = !bInitial;
            char cExpected = (char)(cInitial + 1);

            int  i       = iInitial;
            bool b       = bInitial;
            char c       = cInitial;
            var  initial = new PointerFields()
            {
                i = &i,
                b = &b,
                c = &c,
            };

            PointerFields input = initial;

            {
                int  iResult;
                bool bResult;
                char cResult;
                var  result = new PointerFields()
                {
                    i = &iResult,
                    b = &bResult,
                    c = &cResult
                };
                NativeExportsNE.IncrementInvertPointerFieldsRefReturn(input, ref result);
                Assert.Equal(initial, input);
                ValidateFieldValues(result);
            }

            {
                ResetFieldValues(input);
                NativeExportsNE.IncrementInvertPointerFieldsByRef(ref input);
                Assert.Equal(initial, input);
                ValidateFieldValues(input);
            }

            {
                ResetFieldValues(input);
                NativeExportsNE.IncrementInvertPointerFieldsByRefIn(in input);
                Assert.Equal(initial, input);
                ValidateFieldValues(input);
            }

            void ResetFieldValues(PointerFields input)
            {
                *(input.i) = iInitial;
                *(input.b) = bInitial;
                *(input.c) = cInitial;
            }

            void ValidateFieldValues(PointerFields result)
            {
                Assert.Equal(iExpected, *result.i);
                Assert.Equal(bExpected, *result.b);
                Assert.Equal(cExpected, *result.c);
            }
        }