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(); }
public static void Create(Type TypeHandler) { Delegate func = EHandler.CreateMethod <object, bool>((il) => { LocalBuilder builder = il.DeclareLocal(TypeHandler); il.REmit(OpCodes.Ldarg_0); il.REmit(OpCodes.Unbox_Any, TypeHandler); il.REmit(OpCodes.Stloc_S, builder); EVar returnTrueResult = true; EVar returnFalseResult = false; EModel model = EModel.CreateModelFromBuilder(builder, TypeHandler); #region Property Dictionary <string, PropertyInfo> properties = model.Struction.Properties; foreach (var item in properties) { DebugHelper.WriteLine("检测" + item.Key + "是否为默认值:"); Type type = item.Value.PropertyType; if (type.IsValueType && type.IsPrimitive) { EJudge.If(EDefault.IsDefault(type, () => { model.LPropertyValue(item.Key); }))(() => { }).Else(() => { MethodHelper.ReturnValue(false); }); } else if (type.IsClass) { EJudge.If(ENull.IsNull(() => { model.LPropertyValue(item.Key); }))(() => { }).Else(() => { MethodHelper.ReturnValue(false); }); } } #endregion #region Fields Dictionary <string, FieldInfo> fields = model.Struction.Fields; foreach (var item in fields) { DebugHelper.WriteLine("检测" + item.Key + "是否为默认值:"); Type type = item.Value.FieldType; if (type.IsValueType && type.IsPrimitive) { EJudge.If(EDefault.IsDefault(type, model.DLoadValue(item.Key).DelayAction))(() => { }).Else(() => { MethodHelper.ReturnValue(false); }); } else if (type.IsClass) { EJudge.If(ENull.IsNull(model.DLoadValue(item.Key).DelayAction))(() => { }).Else(() => { MethodHelper.ReturnValue(false); }); } } #endregion il.EmitBoolean(true); }, "Check").Compile(typeof(CheckStructDelegate)); ClassCache.CheckStructDict[TypeHandler] = (CheckStructDelegate)func; }