我正在嘗試獲取這樣的列舉的 ToString 方法
var parameterExpression = Expression.Parameter(typeof(Program), "x");
var toStringMethod = typeof(Enum).GetMethod("ToString", new Type[0]);
Expression leftExpression = Expression.Call(property, toStringMethod);
但這在傳遞時回傳 null 。
uj5u.com熱心網友回復:
你是說你想要一個方法 on EnumcalledToString它有一個 type 引數Enum。
但這不是 的簽名Enum.ToString。Enum.ToString具有以下多載:
string ToString();
string ToString (string? format);
// and two obsolete overloads
尋找正確的引數型別,就可以了:
var toStringMethod = typeof(Enum).GetMethod("ToString", new Type[0]);
或者:
var toStringMethod = typeof(Enum).GetMethod("ToString", new[] { typeof(string) });
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/463239.html
