コード例 #1
0
ファイル: BReader.cs プロジェクト: peterpavles/Conari
 /// <summary>
 /// Gets next value in byte-sequence with size of type by default.
 /// </summary>
 /// <param name="type">The type of value.</param>
 /// <returns></returns>
 public dynamic next(Type type)
 {
     return(next(type, NativeData.SizeOf(type)));
 }
コード例 #2
0
ファイル: BindingTest.cs プロジェクト: solidest/Conari
        public void complexTest1()
        {
            using (var l = new ConariL(UNLIB_DLL))
            {
                IntPtr ptr1 = l.DLR.get_TSpec <IntPtr>();
                IntPtr ptr2 = l.bind <Func <IntPtr> >("get_TSpec")();

                var    dyn  = l.bind(Dynamic.GetMethodInfo(typeof(IntPtr)), "get_TSpec");
                IntPtr ptr3 = (IntPtr)dyn.dynamic.Invoke(null, new object[0]);

                Assert.AreNotEqual(IntPtr.Zero, ptr1);
                Assert.IsTrue(ptr1 == ptr2 && ptr2 == ptr3);

                /*
                 *  struct TSpec
                 *  {
                 *      BYTE a;
                 *      int b;
                 *      char* name;
                 *  };
                 *
                 *  s->a    = 2;
                 *  s->b    = 4;
                 *  s->name = "Conari";
                 *
                 */
                var TSpecPtr = NativeData
                               ._(ptr1)
                               .t <int, int>("a", "b")
                               .t <IntPtr>("name")
                               .AlignSizeByMax;

                byte[]  bytes  = TSpecPtr.Raw.Values;
                dynamic dlr    = TSpecPtr.Raw.Type;
                var     fields = TSpecPtr.Raw.Type.Fields;

                Assert.AreEqual(3, fields.Count);

                int    expA    = 2;
                int    expB    = 4;
                string expName = "Conari";

                // a
                Assert.AreEqual("a", fields[0].name);
                Assert.AreEqual(NativeData.SizeOf <int>(), fields[0].tsize);
                Assert.AreEqual(typeof(int), fields[0].type);
                Assert.AreEqual(expA, fields[0].value);

                // b
                Assert.AreEqual("b", fields[1].name);
                Assert.AreEqual(NativeData.SizeOf <int>(), fields[1].tsize);
                Assert.AreEqual(typeof(int), fields[1].type);
                Assert.AreEqual(expB, fields[1].value);

                // name
                Assert.AreEqual("name", fields[2].name);
                Assert.AreEqual(IntPtr.Size, fields[2].tsize);
                Assert.AreEqual(typeof(IntPtr), fields[2].type);
                Assert.AreEqual(expName, (CharPtr)fields[2].value);

                // DLR
                Assert.AreEqual(expA, dlr.a);
                Assert.AreEqual(expB, dlr.b);
                Assert.AreEqual(expName, (CharPtr)dlr.name);

                // byte-seq
                var br = new BReader(bytes);
                Assert.AreEqual(expA, br.next <int>(NativeData.SizeOf <int>()));
                Assert.AreEqual(expB, br.next <int>(NativeData.SizeOf <int>()));
                Assert.AreEqual(expName, (CharPtr)br.next <IntPtr>(NativeData.SizeOf <IntPtr>()));
            }
        }