Expression動態生成Lambda

2022-09-09 20:36:33 字數 2606 閱讀 5730

using system;

using system.linq.expressions;

using system.reflection;

namespace helper

///

/// 建立lambda表示式:p=>false

///

///

///

public static expression> false()

///

/// 建立lambda表示式:p=>p.propertyname

///

///

///

///

///

public static expression> getorderexpression(string propertyname)

///

/// 建立lambda表示式:p=>p.propertyname == propertyvalue

///

///

///

///

///

public static expression> createequal(string propertyname, string propertyvalue)

///

/// 建立lambda表示式:p=>p.propertyname != propertyvalue

///

///

///

///

///

public static expression> createnotequal(string propertyname, string propertyvalue)

///

/// 建立lambda表示式:p=>p.propertyname > propertyvalue

///

///

///

///

///

public static expression> creategreaterthan(string propertyname, string propertyvalue)

///

/// 建立lambda表示式:p=>p.propertyname < propertyvalue

///

///

///

///

///

public static expression> createlessthan(string propertyname, string propertyvalue)

///

/// 建立lambda表示式:p=>p.propertyname >= propertyvalue

///

///

///

///

///

public static expression> creategreaterthanorequal(string propertyname, string propertyvalue)

///

/// 建立lambda表示式:p=>p.propertyname <= propertyvalue

///

///

///

///

///

public static expression> createlessthanorequal(string propertyname, string propertyvalue)

///

/// 建立lambda表示式:p=>p.propertyname.contains(propertyvalue)

///

///

///

///

///

private static expression> getcontains(string propertyname, string propertyvalue)

);constantexpression constant = expression.constant(propertyvalue, typeof(string));

return expression.lambda>(expression.call(member, method, constant), parameter);

}///

/// 建立lambda表示式:!(p=>p.propertyname.contains(propertyvalue))

///

///

///

///

///

private static expression> getnotcontains(string propertyname, string propertyvalue)

);constantexpression constant = expression.constant(propertyvalue, typeof(string));

return expression.lambda>(expression.not(expression.call(member, method, constant)), parameter);}}

}

動態生成CS檔案(動態生成C 類)

1.codetypedeclaration 可用於表示宣告類 結構 介面或列舉的 官方傳送門 2.codememberfield 表示某種型別的字段的宣告 官方傳送門 3.codedomprovider 可用於建立和檢索 生成器和 編譯器的例項。生成器可用於以特定的語言生成 而 編譯器可用於將 編譯...

動態生成Table DataSet

querymsmqlist querymsmq new querymsmqlist private coreexchange listquerylist querymsmq.mreceive dataset dsqueuemsmq new dataset datatable dsqueuetable...

動態生成列

create procedure sp createtable tname varchar 100 colscript varchar 1000 colnum int coltype varchar 100 as begin declare s varchar 8000 i int set s cr...