Example #1
0
        public static void TestStructIsDefault()
        {
            EStruckCheck.Create(typeof(TestStruct));
            TestStruct model = new TestStruct();

            model.Age  = 1;
            model.Name = "1";
            Console.WriteLine(EStruckCheck.IsDefaultStruct(model));
            TestClass t = new TestClass();

            Console.WriteLine(EStruckCheck.IsDefaultStruct(t.FieldNext));
        }
Example #2
0
        public static void NoErrorLoad(this ILGenerator il, object value)
        {
            ENull enull = value as ENull;

            if (value != null)
            {
                Type          type          = value.GetType();
                ILoadInstance instance      = value as ILoadInstance;
                LocalBuilder  builder       = value as LocalBuilder;
                IOperator     modelOperator = value as IOperator;
                if (value is Action)
                {
                    ((Action)value)();
                }
                else if (instance != null)
                {
                    instance.Load();
                }
                else if (builder != null)
                {
                    il.EmitLoadBuidler(builder);
                }
                else if (enull != null)
                {
                    il.REmit(OpCodes.Ldnull);
                }
                else if (value is Type)
                {
                    il.REmit(OpCodes.Ldtoken, (Type)value);
                    il.REmit(OpCodes.Call, ClassCache.ClassHandle);
                }
                else if (type.IsClass && type != typeof(string))
                {
                    EModel model = EModel.CreateModelFromObject(value, type);
                    model.Load();
                }
                else if (type.IsEnum)
                {
                    il.REmit(OpCodes.Ldc_I4, (int)value);
                }
                else if (type.IsValueType && !type.IsPrimitive)
                {
                    EModel model;
                    if (EStruckCheck.IsDefaultStruct(value, type))
                    {
                        model = EModel.CreateModel(type);
                    }
                    else
                    {
                        model = EModel.CreateModelFromObject(value, type);
                    }
                    model.Load();
                }
                else
                {
                    il.LoadObject(value, type);
                    //il.CallNullableCtor(type);
                }
            }
            else
            {
                il.REmit(OpCodes.Ldnull);
            }
        }