如何使用BigCookieKit.Reflect?
Nuget>>Search>>BigCookieKit.Reflect
首先引入命名空间
using BigCookieKit.Reflect;
基础类型的初始化
var action = SmartBuilder.DynamicMethod<Action>(string.Empty, emit =>
{
//初始化string
var to_string = emit.NewString("字符串");
//初始化int
var to_int = emit.NewInt32(int.MaxValue);
//初始化long
var to_long = emit.NewInt64(long.MaxValue);
//初始化datetime
var to_datetime = emit.NewDateTime(DateTime.Now);
//初始化float
var to_float = emit.NewFloat(float.MaxValue);
//初始化double
var to_double = emit.NewDouble(double.MaxValue);
//初始化decimal
var to_decimal = emit.NewDecimal(decimal.MaxValue);
//初始化object
var to_object = emit.NewObject(decimal.MaxValue);
//初始化bool
var to_bool = emit.NewBoolean(true);
//初始化array
var to_array = emit.NewArray<string>(10);
//初始化model
var to_model = emit.NewEntity<TestModel>();
//初始化list
var to_list = emit.NewList<TestModel>();
//初始化可空类型
var to_nullable_int = emit.NewInt32(int.MaxValue).AsNullable();
emit.Return();
});
action.Invoke();