示例#1
0
        public static void StaticClass()
        {
            Delegate ShowDelegate = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod methodInfoHelper = typeof(Console);
                EModel test = EModel.CreateModel <TestClass>().UseDefaultConstructor();

                test.SField("NormalField", 10);
                methodInfoHelper.ExecuteMethod <int>("WriteLine", test.LoadValue("NormalField"));

                test.SField("StaticField", 10);
                methodInfoHelper.ExecuteMethod <int>("WriteLine", test.LoadValue("StaticField"));
                test.SField("Ref_StaticField", "10");
                methodInfoHelper.ExecuteMethod <string>("WriteLine", test.LoadValue("Ref_StaticField"));

                test.SProperty("NormalProperty", 10);
                methodInfoHelper.ExecuteMethod <int>("WriteLine", test.LoadValue("NormalProperty"));
                test.SProperty("Ref_NormalProperty", "10");
                methodInfoHelper.ExecuteMethod <string>("WriteLine", test.LoadValue("Ref_NormalProperty"));

                test.SProperty("StaticProperty", 10);
                methodInfoHelper.ExecuteMethod <int>("WriteLine", test.LoadValue("StaticProperty"));
                test.SProperty("Ref_StaticProperty", "10");
                methodInfoHelper.ExecuteMethod <string>("WriteLine", test.LoadValue("Ref_StaticProperty"));
            }).Compile();

            ((Action)ShowDelegate)();
        }
示例#2
0
        public void TestMethod()
        {
            Delegate test = EHandler.CreateMethod <ulong>((il) =>
            {
                EModel modelHandler = EModel.CreateModel <MethodStruct>().UseDefaultConstructor();
                EMethod.Load(modelHandler).ExecuteMethod("GetULongMax");
            }).Compile();
            Func <ulong> action = (Func <ulong>)test;

            Assert.Equal(ulong.MaxValue, action());

            test = EHandler.CreateMethod <ulong>((il) =>
            {
                EModel modelHandler = EModel.CreateModel <MethodStruct>().UseDefaultConstructor();
                EMethod.Load(modelHandler).ExecuteMethod("GetULongMin");
            }).Compile();
            action = (Func <ulong>)test;
            Assert.Equal(ulong.MinValue, action());

            test = EHandler.CreateMethod <string>((il) =>
            {
                EModel modelHandler = EModel.CreateModel <MethodStruct>().UseDefaultConstructor();
                EVar param1         = "Hello";
                EMethod.Load(modelHandler).ExecuteMethod <string, string>("GetString", param1, " World");
            }).Compile();
            Func <string> action1 = (Func <string>)test;

            Assert.Equal("Hello World", action1());
        }
示例#3
0
        public static void TestClassAndStruct()
        {
            //动态创建Action委托
            Delegate newMethod = EHandler.CreateMethod <ENull>((il) =>
            {
                EModel model = null;
                //测试类的字段
                //model = EModel.CreateModel<ClassField>().UseDefaultConstructor();
                //测试类的属性
                //model = EModel.CreateModel<ClassProperty>().UseDefaultConstructor();
                //测试结构体的字段
                model = EModel.CreateModel <StructField>();
                //测试结构体的属性
                //model = EModel.CreateModel<StructProperty>();
                model.Set("PublicName", "This is Public-Name");
                model.Set("PrivateName", "This is Private-Name");
                model.Set("PublicAge", 666);
                model.Set("PrivateAge", 666);

                EMethod method = typeof(Console);
                method.ExecuteMethod <string>("WriteLine", model.DLoadValue("PrivateName").DelayAction);
                method.ExecuteMethod <string>("WriteLine", model.LoadValue("PublicName"));
                method.ExecuteMethod <int>("WriteLine", model.LoadValue("PublicAge"));
                method.ExecuteMethod <int>("WriteLine", model.LoadValue("PrivateAge"));
            }).Compile();

            ((Action)newMethod)();
        }
示例#4
0
        public static void TestCreateModel()
        {
            ClassBuilder builder = ClassBuilder.CreateModel("Hello");

            builder.CreateDefaultConstructor();
            builder.CreateField <string>("Age", FieldAttributes.Public);
            builder.CreateProperty <string>("Name");
            builder.CreateMethod <ENull>("Show", MethodAttributes.Public, (classModel) =>
            {
                classModel.SField("Age", "This is Age.");
                classModel.SProperty("Name", "This is name.");
                classModel.LPropertyValue("Name");
                classModel.il.REmit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
                classModel.il.REmit(OpCodes.Ret);
            });
            builder.EndBuilder();
            Delegate ShowDelegate = EHandler.CreateMethod <ENull>((il) =>
            {
                EModel Model = EModel.CreateDynamicClass("Hello").UseDefaultConstructor();
                EMethod.Load(Model).ExecuteMethod("Show");
                Model.LFieldValue("Age");
                Model.il.REmit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
            }).Compile();

            ((Action)ShowDelegate)();
        }
示例#5
0
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            FrmMsgBox.ShowOkCancel(this, this.Text, "Note: PLSR requires the R library \"pls\" to function.", FrmMsgBox.EDontShowAgainId.PlsrMode, DialogResult.OK);

            this._method = EMethod.Plsr;
            this.UpdateScores();
        }
示例#6
0
        public static void TestStructClone()
        {
            EReflector.Create(typeof(SingleModel));
            TestStruct t = new TestStruct();

            t.TEnum = TestEnum.Address;
            t.Set();
            t.Name  = "小明";
            t.Name1 = "小明1";
            t.Age   = 10;
            t.Age1  = 101;

            Delegate ShowDelegate = EHandler.CreateMethod <TestStruct>((il) =>
            {
                EMethod methodInfoHelper = typeof(Console);
                EModel model             = EModel.CreateModelFromObject(t);
                model.SField("PrivateFAge", 10);
                model.LFieldValue("PrivateFAge");
                methodInfoHelper.ExecuteMethod <int>("WriteLine");
                model.Load();
            }).Compile();
            TestStruct t2 = ((Func <TestStruct>)ShowDelegate)();

            Console.WriteLine(t2.Name);
            Console.WriteLine(t2.Age);
            Console.WriteLine(t2.Name1);
            Console.WriteLine(t2.Age1);
            t2.Show();
            Console.WriteLine(t.TEnum);
            Console.WriteLine(t2.TEnum);
        }
示例#7
0
        public static void TestJudge()
        {
            Action action = (Action)(EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod methodInfoHelper = typeof(Console);
                EVar Int_1 = 2;
                EVar Int_2 = 2;

                EArray objectArray = EArray.CreateArraySpecifiedLength <object>(2);
                objectArray.StoreArray(0, Int_1.InStackAndPacket);
                objectArray.StoreArray(1, Int_2.InStackAndPacket);

                EJudge.
                If(Int_1 > 2)(() =>
                {
                    EVar str = "{0}>{1}";
                    methodInfoHelper.ExecuteMethod <string, object[]>("WriteLine", str, objectArray);
                })
                .ElseIf(Int_1 == Int_2)(() =>
                {
                    EVar str = "{0}={1}";
                    methodInfoHelper.ExecuteMethod <string, object[]>("WriteLine", str, objectArray);
                })
                .Else(() =>
                {
                    EVar str = "{0}<{1}";
                    methodInfoHelper.ExecuteMethod <string, object[]>("WriteLine", str, objectArray);
                });
            }).Compile());

            action();
        }
示例#8
0
文件: Http.cs 项目: daviddw/Kinsky
        public static string Method(EMethod aMethod)
        {
            switch (aMethod)
            {
            case (EMethod.eOptions): return(kHttpMethodOptions);

            case EMethod.eGet: return(kHttpMethodGet);

            case EMethod.eHead: return(kHttpMethodHead);

            case EMethod.ePost: return(kHttpMethodPost);

            case EMethod.ePut: return(kHttpMethodPut);

            case EMethod.eDelete: return(kHttpMethodDelete);

            case EMethod.eTrace: return(kHttpMethodTrace);

            case EMethod.eConnect: return(kHttpMethodConnect);

            case EMethod.eExtension: return(kHttpMethodExtension);

            default: break;
            }
            Assert.Check(false);
            return("");
        }
示例#9
0
        /// <summary>
        /// 使用Natasha根据参数数组信息生成Command高速构建缓存
        /// </summary>
        /// <typeparam name="T">实际执行函数返回的类型</typeparam>
        /// <param name="sql">SQL语句</param>
        /// <param name="values">object参数数组</param>
        /// <returns>动态方法</returns>
        private static SqlDelegate <T> .GetCommandByObject GetEmitCommandCache <T>(string sql, object[] values)
        {
            Type returnType = typeof(T);

            if (!Cache.SqlCache.ContainsKey(returnType))
            {
                ModelAnalyser.Initialization(returnType);
            }

            Delegate newMethod = EHandler.CreateMethod <ERef <IDbCommand>, object[], ENull>((il) =>
            {
                EModel idbCommand = EModel.CreateModelFromParameter <IDbCommand>(0);
                idbCommand.UseRef();
                idbCommand.Set("CommandText", sql);

                EArray arrayArg       = EArray.CreateArrayFromParameter(1, typeof(object));
                EModel copyParameters = idbCommand.Load("Parameters");

                MatchCollection collection = ParameterRegex.Matches(sql);
                int length = collection.Count;
                for (int i = 0; i < length; i += 1)
                {
                    Type type = values[i].GetType();

                    string memberName = collection[i].Groups[1].Value;
                    copyParameters.Dup();
                    EModel copyParameter = EMethod.Load(idbCommand).ExecuteMethod("CreateParameter").Dup();
                    copyParameter.Set("ParameterName", "@".Append(memberName));
                    copyParameter.Dup().Set("DbType", (int)SqlTypes[type]);

                    if (type.IsPrimitive)
                    {
                        copyParameter.Dup().Set("Value", () => { arrayArg.LoadArray(i); });
                    }
                    else
                    {
                        EJudge.If(ENull.IsNull(() => { arrayArg.LoadArray(i); }))(() =>
                        {
                            copyParameter.Dup().Set("Value", EDBNull.LoadValue);
                        }).Else(() =>
                        {
                            copyParameter.Dup().Set("Value", () => { arrayArg.LoadArray(i); });
                        });
                    }
                    EMethod.Load <IList>().ExecuteMethod <object>("Add").Pop();
                }
                copyParameters.Pop();
            }).Compile(typeof(SqlDelegate <T> .GetCommandByObject));

            return((SqlDelegate <T> .GetCommandByObject)newMethod);
        }
示例#10
0
 void Awake()
 {
     m_SprRdr  = GetComponent <SpriteRenderer> ();
     m_MatOrig = m_SprRdr.material;
     if (m_Method == EMethod.Image)
     {
         m_MatOutline = new Material(m_SdrImageOutline);
     }
     if (m_Method == EMethod.Sdf)
     {
         m_MatOutline = new Material(m_SdrSdfOutline);
     }
     m_MethodPrev = m_Method;
 }
示例#11
0
 void UpdateOutlineShader()
 {
     if (m_Method != m_MethodPrev)
     {
         if (m_Method == EMethod.Image)
         {
             m_MatOutline = new Material(m_SdrImageOutline);
         }
         if (m_Method == EMethod.Sdf)
         {
             m_MatOutline = new Material(m_SdrSdfOutline);
         }
         m_MethodPrev = m_Method;
     }
 }
示例#12
0
    public void UseMethod(int value)
    {
        m_Method = ( EMethod )value;
        PanelCompass.SetActive(EMethod.Kompass == m_Method);
        m_CompassStrip.SetActive(EMethod.Kompass == m_Method);
        //  PanelManual.SetActive ( EMethod.Manual == m_Method ) ;
        //  PanelSequential.SetActive ( EMethod.Sequential == m_Method ) ;

        /*  switch ( m_Method )
         * {
         *    case EMethod.Kompass    : m_PhotoTask = m_CompassStrip   ; break ;
         *    case EMethod.Manual     : m_PhotoTask = m_TaskManual     ; break ;
         *    case EMethod.Sequential : m_PhotoTask = m_TaskSequential ; break ;
         * }*/
        Reset();
    }
示例#13
0
    string GetKernelName(EMethod method)
    {
        string kernelName = "";

        switch (method)
        {
        case EMethod.RenderTexture:
            kernelName = KernelName_Texture;
            break;

        case EMethod.ComputerBuffer:
            kernelName = KernelName_Buffer;
            break;
        }
        return(kernelName);
    }
示例#14
0
        public static void TestSingle()
        {
            //动态创建Action委托
            Delegate newMethod = EHandler.CreateMethod <ENull>((il) =>
            {
                //创建没有临时变量的普通入栈变量(没有临时变量,所以自加操作没有意义)
                EVar intHandler = 1;
                //创建函数操作句柄
                EMethod method = typeof(Console);
                //输出intHandler的时候,让变量做加法运算。
                method.ExecuteMethod <int>("WriteLine", intHandler + 665);
                //结果:666;
            }).Compile();

            ((Action)newMethod)();

            //动态创建Action<int,string>委托
            Delegate newMethod1 = EHandler.CreateMethod <ENull>((il) =>
            {
                //创建有临时变量的普通入栈变量(自加操作可以被自身储存) 也就是说可以使用store存储函数
                //int i = 664;
                EVar intHandler = EVar.CreateVarFromObject(664);
                //i++;
                intHandler++;
                //i=i+1;
                intHandler.Store(intHandler + 1);
                //创建函数操作句柄
                EMethod method = typeof(Console);
                //输出intHandler
                method.ExecuteMethod <int>("WriteLine", intHandler);
                //结果:666
            }).Compile();

            ((Action)newMethod1)();

            ////动态创建Action委托
            //Delegate newMethod0 = EHandler.CreateMethod<ENull>((il) => { }).Compile();

            ////动态创建Action<string,int>委托
            //Delegate newMethod1 = EHandler.CreateMethod<string,int,ENull>((il) => { }).Compile();

            ////动态创建Func<string>委托
            //Delegate newMethod2 = EHandler.CreateMethod<string>((il) => { }).Compile();

            ////动态创建Func<string,TestClass>委托
            //Delegate newMethod3 = EHandler.CreateMethod<string, TestClass>((il) => { }).Compile();
        }
示例#15
0
        public static void TestIf()
        {
            Delegate showResult = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod method = typeof(Console);

                EVar emit_A = EVar.CreateWithoutTempVar(10);
                EVar emit_B = EVar.CreateVarFromObject(20);

                TestClass t = new TestClass()
                {
                    Field = 10
                };
                t.PropertyName = "3";
                EModel model   = EModel.CreateModelFromObject(t);

                EJudge.If(emit_A == model.DLoadValue("Field").Operator)(() =>
                {
                    method.ExecuteMethod <string>("WriteLine", "相等");
                }).ElseIf(emit_A > emit_B)(() =>
                {
                    method.ExecuteMethod <int>("WriteLine", emit_A);
                }).Else(() =>
                {
                    method.ExecuteMethod <int>("WriteLine", emit_B);
                });



                EVar string_A = "6";
                EVar string_B = "2";

                EJudge.If(string_A == "1")(() =>
                {
                    method.ExecuteMethod <string>("WriteLine", string_A);
                }).ElseIf(string_A == model.DLoadValue("PropertyName").Operator)(() =>
                {
                    method.ExecuteMethod <string>("WriteLine", string_A);
                }).Else(() =>
                {
                    method.ExecuteMethod <string>("WriteLine", string_B);
                });
            }).Compile();

            ((Action)showResult)();
        }
示例#16
0
        public static void TestClass()
        {
            Delegate ShowDelegate = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod methodInfoHelper = typeof(Console);
                EModel model             = EModel.CreateModel <TestClass>().UseDefaultConstructor();
                model.Set("Name", "Name");
                model.LoadValue("Name");
                methodInfoHelper.ExecuteMethod <string>("WriteLine");

                model.Set("Age", 10);
                methodInfoHelper.ExecuteMethod <int>("WriteLine", model.LoadValue("Age"));
                methodInfoHelper.ExecuteMethod <int>("WriteLine", model.Load("FieldNext").LoadValue("Age"));
            }).Compile();

            ((Action)ShowDelegate)();
        }
示例#17
0
    public void Bake(string saveDir)
    {
        if (HDR_Image == null)
        {
            return;
        }

        if (m_BakeMat == null)
        {
            Shader sh = Shader.Find("Hidden/HDRIBaker");
            m_BakeMat = new Material(sh);
        }


        //m_BakeMat.SetFloat("_RgbmMaxValue", RGBM_MaxValue);
        Shader.SetGlobalFloat("_RgbmMaxValue", RGBM_MaxValue);
        if (SkyMat != null)
        {
            for (int i = 0; i < (int)EMethod.Max; i += 2)
            {
                EMethod e = (EMethod)i;
                SkyMat.DisableKeyword(e.ToString());
            }

            string keyword = Method.ToString();
            SkyMat.EnableKeyword(keyword);
        }

        RenderTexture tempRT = RenderTexture.GetTemporary(HDR_Image.width, HDR_Image.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);

        Graphics.Blit(HDR_Image, tempRT, m_BakeMat, (int)Method);

        SaveRenderTextureToPNG(tempRT, saveDir, HDR_Image.name + "_Encoded");
        m_RT = tempRT;
        //RenderTexture.ReleaseTemporary(tempRT);


        if (SeperateColorAndAlpha)
        {
            RenderTexture tempRT2 = RenderTexture.GetTemporary(HDR_Image.width, HDR_Image.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
            Graphics.Blit(HDR_Image, tempRT2, m_BakeMat, (int)(Method + 1));
            SaveRenderTextureToPNG(tempRT2, saveDir, HDR_Image.name + "_Encoded_Alpha");

            m_RT2 = tempRT2;
        }
    }
示例#18
0
        public static void TestNull()
        {
            //动态创建Action委托
            Delegate newMethod = EHandler.CreateMethod <ENull>((il) =>
            {
                //创建没有临时变量的普通入栈变量(没有临时变量,所以自加操作没有意义)
                EVar intHandler = EVar.CreateVarFromObject("2");
                //创建函数操作句柄
                EMethod method = typeof(Console);
                //输出intHandler
                method.ExecuteMethod <string>("WriteLine", intHandler);
                //填空值string=null
                intHandler.Store(ENull.Value);
                method.ExecuteMethod <string>("WriteLine", intHandler);
            }).Compile();

            ((Action)newMethod)();
        }
示例#19
0
        public static void TestClassOperator()
        {
            Delegate showResult = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod methodInfoHelper = typeof(Console);
                EModel model             = EModel.CreateModel <TestClass>().UseDefaultConstructor();
                model.Set("Age", 10);

                EModel model2 = EModel.CreateModel <TestClass>().UseDefaultConstructor();
                model2.Set("Age", 11);
                methodInfoHelper.ExecuteMethod <int>("WriteLine", model.LoadValue("Age") + model2.LoadValue("Age"));
                methodInfoHelper.ExecuteMethod <int>("WriteLine", model.LoadValue("Age") - model2.LoadValue("Age"));
                methodInfoHelper.ExecuteMethod <int>("WriteLine", model.LoadValue("Age") * model2.LoadValue("Age"));
                methodInfoHelper.ExecuteMethod <int>("WriteLine", model.LoadValue("Age") / model2.LoadValue("Age"));
                methodInfoHelper.ExecuteMethod <int>("WriteLine", model.LoadValue("Age") + 1000);
            }).Compile();

            ((Action)showResult)();
        }
示例#20
0
        public static void TestOperator()
        {
            Delegate showResult = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod method = typeof(Console);
                EVar emit_A    = EVar.CreateWithoutTempVar(12);
                EVar emit_B    = EVar.CreateVarFromObject(13);
                method.ExecuteMethod <int>("WriteLine", emit_A + emit_B);
                method.ExecuteMethod <int>("WriteLine", emit_A + 1);
                method.ExecuteMethod <int>("WriteLine", 1 + 1);
                method.ExecuteMethod <int>("WriteLine", emit_B++);
            }).Compile();

            ((Action)showResult)();

            TestClass t = new TestClass();

            t.Field    = 10;
            t.Property = 20;

            TestStruct t2 = new TestStruct();

            t2.Field    = 90;
            t2.Property = 80;
            t.Next      = t2;
            showResult  = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod method = typeof(Console);
                EVar emit_A    = EVar.CreateWithoutTempVar(12);
                EVar emit_B    = EVar.CreateVarFromObject(13);
                EModel model   = EModel.CreateModelFromObject(t);

                method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field").DelayAction);
                method.ExecuteMethod <int>("WriteLine", (model.DLoadValue("Field").Operator++).DelayAction);
                method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field") + emit_A);
                method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field").Operator + 10);
                method.ExecuteMethod <int>("WriteLine", (model.DLoad("Next").DLoadValue("Property").Operator++).DelayAction);
                method.ExecuteMethod <int>("WriteLine", (model.DLoad("Next").DLoadValue("Property").Operator + 10));
                method.ExecuteMethod <int>("WriteLine", emit_B + model.DLoadValue("Property").Operator);
                method.ExecuteMethod <int>("WriteLine", emit_B++);
            }).Compile();
            ((Action)showResult)();
        }
示例#21
0
        public static void TestDefault()
        {
            Action action = (Action)(EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod methodInfoHelper = typeof(Console);
                EVar stringHandler = "16";
                EVar intHandler = 10;
                EVar doubleHandler = 0.00;
                EJudge.If(EDefault.IsDefault(doubleHandler.TypeHandler, () => { doubleHandler.Load(); }))(() =>
                {
                    EMethod.Load(typeof(Console)).ExecuteMethod <string>("WriteLine", "doubleHandler是默认值");
                }).Else(() =>
                {
                    doubleHandler.This();
                    methodInfoHelper.ExecuteMethod <double>("WriteLine");
                });
            }).Compile());

            action();
        }
示例#22
0
        public void ShowInt()
        {
            //测试int上限 无临时变量
            Delegate test = EHandler.CreateMethod <int>((il) => {
                EVar temp_var = int.MaxValue;
                EMethod.Load(typeof(Console)).ExecuteMethod <int>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <int> action = (Func <int>)test;

            Assert.Equal(int.MaxValue, action());

            //测试int下限 有临时变量
            Delegate test2 = EHandler.CreateMethod <int>((il) => {
                EVar temp_var = EVar.CreateVarFromObject(int.MinValue);
                EMethod.Load(typeof(Console)).ExecuteMethod <int>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <int> action2 = (Func <int>)test2;

            Assert.Equal(int.MinValue, action2());
        }
示例#23
0
        public static void TestComplexClone()
        {
            TestClass testModel = new TestClass();

            testModel.Name = "X";
            testModel.Age  = 10;

            TestStruct nestingStruct = new TestStruct();

            nestingStruct.Age  = 101;
            nestingStruct.Name = "CX";

            TestInterfaceModel interfaceModel = new TestInterfaceModel();

            interfaceModel.Shut = true;

            testModel.PInterface    = interfaceModel;
            testModel.FieldNext     = nestingStruct;
            testModel.PropertyNext1 = nestingStruct;

            Delegate ShowDelegate = EHandler.CreateMethod <TestClass>((il) =>
            {
                EMethod method    = typeof(Console);
                EModel classModel = EModel.CreateModelFromObject(testModel);
                classModel.ALoad("PrivatePName").GetAttributeModel("Attribute1").LoadValue("Name");
                method.ExecuteMethod <string>("WriteLine");
                classModel.Load();
            }).Compile();
            TestClass Result = ((Func <TestClass>)ShowDelegate)();

            Console.WriteLine(Result.Name);
            Console.WriteLine(Result.FieldNext.Name);
            Console.WriteLine(Result.FieldNext.Age);
            Console.WriteLine(Result.PropertyNext1.Name);
            Console.WriteLine(Result.PropertyNext1.Age);
            Console.WriteLine(Result.PInterface.Shut);
        }
示例#24
0
        public static void TestList()
        {
            List <string> list = new List <string>();

            bool shut = list.All(func);

            Console.WriteLine(shut);

            Func <List <string>, Func <string, bool>, bool> ShowDelegate = (Func <List <string>, Func <string, bool>, bool>)EHandler.CreateMethod <List <string>, Func <string, bool>, bool>((il) =>
            {
                EVar elist = EVar.CreateVarFromParameter(0);
                EVar efunc = EVar.CreateVarFromParameter(1);
                EMethod.Load(elist)
                .Use(typeof(Enumerable))
                .AddGenricType <string>()
                .ExecuteMethod <Func <string, bool> >("All", efunc);
            }).Compile();

            Console.WriteLine(ShowDelegate(list, (str) =>
            {
                if (str == "1")
                {
                    return(true);
                }
                return(false);
            }));

            Action ShowDelegate1 = (Action)EHandler.CreateMethod <ENull>((il) =>
            {
                EModel model = EModel.CreateModel <Student>().UseDefaultConstructor();
                EMethod.Load(model).ExecuteMethod("Show");
                EMethod.Load(model).ExecuteMethod <string>("Show", "test");
            }).Compile();

            ((Action)ShowDelegate1)();
        }
示例#25
0
        public static void TestNesting()
        {
            Delegate ShowDelegate = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod methodInfoHelper = typeof(Console);

                EModel structModel = EModel.CreateModel <TestStruct>().UseDefaultConstructor();
                structModel.SProperty("Name", "Name1");
                structModel.SField("Age", 101);


                EModel nesting_classModel = EModel.CreateModel <TestClass>().UseDefaultConstructor();
                nesting_classModel.SProperty("Name", "Name2");
                nesting_classModel.SField("Age", 102);

                EModel classModel = EModel.CreateModel <TestClass>().UseDefaultConstructor();
                classModel.SProperty("Name", "Name");
                classModel.SField("Age", 10);
                classModel.SField("FieldNext", structModel);
                classModel.SProperty("PropertyNext", nesting_classModel);

                classModel.LField("FieldNext").LFieldValue("Age");
                methodInfoHelper.ExecuteMethod <int>("WriteLine");

                classModel.LField("FieldNext").LPropertyValue("Name");
                methodInfoHelper.ExecuteMethod <string>("WriteLine");

                classModel.LPropertyValue("PropertyNext").LFieldValue("Age");
                methodInfoHelper.ExecuteMethod <int>("WriteLine");

                classModel.LPropertyValue("PropertyNext").LPropertyValue("Name");
                methodInfoHelper.ExecuteMethod <string>("WriteLine");
            }).Compile();

            ((Action)ShowDelegate)();
        }
示例#26
0
        public static void TestWhile()
        {
            Delegate showResult = EHandler.CreateMethod <ENull>((il) =>
            {
                EMethod method = typeof(Console);

                EVar emit_A = EVar.CreateWithoutTempVar(16);
                EVar emit_B = EVar.CreateVarFromObject(20);
                ELoop.While(emit_A < emit_B)(() =>
                {
                    method.ExecuteMethod <int>("WriteLine", emit_B);
                    emit_B--;
                });


                TestClass t = new TestClass()
                {
                    Field = 10
                };
                EModel model = EModel.CreateModelFromObject(t);
                ELoop.While(model.DLoadValue("Field").Operator < emit_B)(() =>
                {
                    //这里需要传递委托,不传递委托则返回的是model类型而不是int类型
                    method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field").DelayAction);
                    model.DLoadValue("Field").Operator++;
                });

                ELoop.While(model.DLoadValue("Field").Operator != 25)(() =>
                {
                    method.ExecuteMethod <int>("WriteLine", model.DLoadValue("Field").DelayAction);
                    model.DLoadValue("Field").Operator++;
                });
            }).Compile();

            ((Action)showResult)();
        }
示例#27
0
        public void ShowBoolean()
        {
            //测试float上限 无临时变量
            Delegate test = EHandler.CreateMethod <bool>((il) =>
            {
                EVar temp_var = true;
                EMethod.Load(typeof(Console)).ExecuteMethod <bool>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <bool> action = (Func <bool>)test;

            Assert.Equal(true, action());

            //测试float下限 有临时变量
            Delegate test2 = EHandler.CreateMethod <bool>((il) =>
            {
                EVar temp_var = EVar.CreateVarFromObject(false);
                EMethod.Load(typeof(Console)).ExecuteMethod <bool>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <bool> action2 = (Func <bool>)test2;

            Assert.Equal(false, action2());
        }
示例#28
0
        public void ShowChar()
        {
            //测试char 无临时变量
            Delegate test = EHandler.CreateMethod <char>((il) =>
            {
                EVar temp_var = 'a';
                EMethod.Load(typeof(Console)).ExecuteMethod <char>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <char> action = (Func <char>)test;

            Assert.Equal('a', action());

            //测试string 有临时变量
            Delegate test2 = EHandler.CreateMethod <char>((il) =>
            {
                EVar temp_var = EVar.CreateVarFromObject('`');
                EMethod.Load(typeof(Console)).ExecuteMethod <char>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <char> action2 = (Func <char>)test2;

            Assert.Equal('`', action2());
        }
示例#29
0
        public void ShowString()
        {
            //测试string 无临时变量
            Delegate test = EHandler.CreateMethod <string>((il) =>
            {
                EVar temp_var = string.Empty;
                EMethod.Load(typeof(Console)).ExecuteMethod <string>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <string> action = (Func <string>)test;

            Assert.Equal(string.Empty, action());

            //测试string 有临时变量
            Delegate test2 = EHandler.CreateMethod <string>((il) =>
            {
                EVar temp_var = EVar.CreateVarFromObject(string.Empty);
                EMethod.Load(typeof(Console)).ExecuteMethod <string>("WriteLine", temp_var);
                temp_var.Load();
            }).Compile();
            Func <string> action2 = (Func <string>)test2;

            Assert.Equal(string.Empty, action2());
        }
示例#30
0
文件: Http.cs 项目: weeble/ohos
 public static string Method(EMethod aMethod)
 {
     switch (aMethod)
     {
         case EMethod.Options: return kHttpMethodOptions;
         case EMethod.Get: return kHttpMethodGet;
         case EMethod.Head: return kHttpMethodHead;
         case EMethod.Post: return kHttpMethodPost;
         case EMethod.Put: return kHttpMethodPut;
         case EMethod.Delete: return kHttpMethodDelete;
         case EMethod.Trace: return kHttpMethodTrace;
         case EMethod.Connect: return kHttpMethodConnect;
         case EMethod.Extension: return kHttpMethodExtension;
         default: break;
     }
     throw new HttpError();
 }
示例#31
0
        public TypeStructionAnalyzer(Type parameter_Handler) : base()
        {
            PrewCallOption    = LinkCallOption.Default;
            CurrentCallOption = LinkCallOption.Default;
            if (parameter_Handler == null)
            {
                return;
            }
            TypeHandler   = parameter_Handler;
            MethodHandler = parameter_Handler;
            //判断是否为结构体

            if (TypeHandler.IsValueType && !TypeHandler.IsPrimitive && !TypeHandler.IsEnum)
            {
                IsStruct = true;
            }
            else
            {
                IsStruct = false;
            }
            ElementType = TypeHandler.GetElementType();
            if (ElementType != null)
            {
                if (ElementType.IsValueType && !ElementType.IsPrimitive && !ElementType.IsEnum)
                {
                    IsStruct = true;
                }
                else
                {
                    IsStruct = false;
                }
            }
            if (ElementType == null)
            {
                ElementType = TypeHandler;
            }
            //填充类结构缓冲
            if (ClassCache.ClassInfoDict.ContainsKey(TypeHandler.Name))
            {
                Struction = ClassCache.ClassInfoDict[TypeHandler.Name];
            }
            else
            {
                //创建类结构
                Struction             = new ClassStruction();
                Struction.Name        = TypeHandler.Name;
                Struction.TypeHandler = TypeHandler;
                Struction.IsStruct    = IsStruct;
                ClassCache.ClassInfoDict[TypeHandler.Name] = Struction;

                Type[]         types     = TypeHandler.GetInterfaces();
                HashSet <Type> hashTypes = new HashSet <Type>(types);

                #region 此处保留,因为具体操作的时候有些接口是没必要用的,可以在这里做过滤
                Type type = TypeHandler.GetInterface("IDictionary");
                if (type != null)
                {
                    for (int i = 0; i < types.Length; i += 1)
                    {
                        if (types[i].Name.Contains("ICollection") || !types[i].IsGenericType)
                        {
                            hashTypes.Remove(types[i]);
                        }
                    }
                }
                #endregion

                hashTypes.Add(TypeHandler);
                foreach (var item in hashTypes)
                {
                    Type tempType = item;

                    //获取方法结构
                    MethodInfo[] methods = tempType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                    for (int j = 0; j < methods.Length; j += 1)
                    {
                        string methodName = methods[j].Name;
                        if (methodName.Length > 4)
                        {
                            if (methodName[0] == 103 || methodName[0] == 115)
                            {
                                if (methodName[1] == 101)
                                {
                                    if (methodName[2] == 116)
                                    {
                                        if (methodName[3] == 95)
                                        {
                                            continue;
                                        }
                                    }
                                }
                            }
                        }

                        Struction.Methods[methods[j].Name] = methods[j];
                        //处理方法标签
                        object[] attributes = methods[j].GetCustomAttributes(true);
                        if (attributes != null && attributes.Length > 0)
                        {
                            Struction.AttributeTree[methods[j].Name] = new Dictionary <string, object>();
                            for (int n = 0; n < attributes.Length; n += 1)
                            {
                                Type attributeType = attributes[n].GetType();
                                if (CheckHaveDefautlConstructor(attributeType))
                                {
                                    Struction.AttributeTree[methods[j].Name][attributeType.Name] = attributes[n];
                                }
                            }
                        }
                    }
                    Type currentType = null;
                    //获取属性结构
                    PropertyInfo[] properties = tempType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                    for (int j = 0; j < properties.Length; j += 1)
                    {
                        currentType = properties[j].PropertyType;
                        //内部私有类的数组不做操作
                        if (currentType.IsArray)
                        {
                            if (currentType.GetElementType().GetTypeInfo().IsNestedPrivate)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (currentType.GetTypeInfo().IsNestedPrivate)
                            {
                                continue;
                            }
                        }
                        //处理属性标签
                        object[] attributes = properties[j].GetCustomAttributes(true);
                        if (attributes != null && attributes.Length > 0)
                        {
                            Struction.AttributeTree[properties[j].Name] = new Dictionary <string, object>();
                            for (int n = 0; n < attributes.Length; n += 1)
                            {
                                Type attributeType = attributes[n].GetType();
                                if (CheckHaveDefautlConstructor(attributeType))
                                {
                                    Struction.AttributeTree[properties[j].Name][attributeType.Name] = attributes[n];
                                }
                            }
                        }
                        Struction.Properties[properties[j].Name] = properties[j];

                        //if (currentType.IsClass && ((currentType.BaseType == typeof(MulticastDelegate) || currentType.BaseType == typeof(Delegate))))
                        //{
                        //    Struction.DelegateMethods[properties[j].Name] = currentType.GetMethod("Method");
                        //}
                    }

                    //获取字段结构
                    FieldInfo[] fields = tempType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                    for (int j = 0; j < fields.Length; j += 1)
                    {
                        currentType = fields[j].FieldType;
                        //内部私有类的数组不做操作
                        if (currentType.IsArray)
                        {
                            if (currentType.GetElementType().GetTypeInfo().IsNestedPrivate)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            //readonly const 内部私有类 不做操作
                            if (fields[j].IsInitOnly || (fields[j].IsLiteral && fields[j].IsStatic) || currentType.GetTypeInfo().IsNestedPrivate)
                            {
                                continue;
                            }
                        }
                        //处理字段标签
                        object[] attributes = fields[j].GetCustomAttributes(true);
                        if (attributes != null && attributes.Length > 0)
                        {
                            Struction.AttributeTree[fields[j].Name] = new Dictionary <string, object>();
                            for (int n = 0; n < attributes.Length; n += 1)
                            {
                                Type attributeType = attributes[n].GetType();
                                if (CheckHaveDefautlConstructor(attributeType))
                                {
                                    Struction.AttributeTree[fields[j].Name][attributeType.Name] = attributes[n];
                                }
                            }
                        }
                        Struction.Fields[fields[j].Name] = fields[j];

                        //if (currentType.IsClass && (currentType.BaseType == typeof(MulticastDelegate) || currentType.BaseType == typeof(Delegate)))
                        //{
                        //    //PropertyInfo info = currentType.GetProperty("Method");
                        //    //info.GetValue();
                        //    //Struction.DelegateMethods[fields[j].Name] =
                        //}
                    }
                }
            }
            if (this is IDelayOperator)
            {
                ((IDelayOperator)this).Initialize();
            }
        }