Ejemplo n.º 1
0
    static void Main(string[] args)
    {
        {
            Action action = () => { Console.WriteLine("Action"); };
            ActionProxy <Action> proxy = new ActionProxy <Action>(action);
            proxy.Call();
        }

        {
            Action <int> action = (arg) => { Console.WriteLine($"Action<int>: {arg}"); };
            ActionProxy <Action <int> > proxy = new ActionProxy <Action <int> >(action);
            proxy.Call();
        }

        {
            EnumValueCache <Days> days = new EnumValueCache <Days>();

            Console.WriteLine(days.GetInteger(Days.Friday));
            Console.WriteLine(days.GetInteger(Days.Thursday));
        }

        unsafe
        {
            int n = 10;
            using (UnmanagedWrapper <int> intArray = new UnmanagedWrapper <int>(n))
            {
                for (int i = 0; i < n; i++)
                {
                    intArray[i] = i;
                }

                for (int i = 0; i < n; i++)
                {
                    Console.Write(intArray[i] + ",");
                }
            }
        }

        unsafe
        {
            int n = 10;
            using (UnmanagedWrapper <long> longArray = new UnmanagedWrapper <long>(n))
            {
                for (int i = 0; i < n; i++)
                {
                    longArray[i] = i;
                }

                for (int i = 0; i < n; i++)
                {
                    Console.Write(longArray[i] + ",");
                }
            }
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// 绑定数据并注册对象
        /// 说明:已经过滤特殊名称,即不含系统自动生成的属性、方法
        /// </summary>
        /// <param name="name">对象名称</param>
        /// <param name="obj">需要绑定的对象</param>
        /// <param name="window">用于注册的V8 JS引擎对象,类似于整个程序的窗口句柄</param>
        public static void Bind(string name, object obj, CefV8Value window)
        {
            var unmanagedWrapper = new UnmanagedWrapper(obj);

            var propertyAccessor = new PropertyAccessor();
            //javascript对象包
            CefV8Value javascriptWrapper = CefV8Value.CreateObject(propertyAccessor);

            //将非托管对象放到javascript对象包
            javascriptWrapper.SetUserData(unmanagedWrapper);

            var handler = new BindingHandler();

            unmanagedWrapper.Properties = GetProperties(obj.GetType());
            CreateJavascriptProperties(javascriptWrapper, unmanagedWrapper.Properties);

            IList <string> methodNames = GetMethodNames(obj.GetType(), unmanagedWrapper.Properties);

            CreateJavascriptMethods(handler, javascriptWrapper, methodNames);

            window.SetValue(name, javascriptWrapper, CefV8PropertyAttribute.None);
        }
 public void Run()
 {
     var v = new UnmanagedWrapper();
     v.Dispose();
     v.Dispose();
 }