如何从Function对象获取自定义属性?
public static void Main(string[] args) {
Func<object> fun = () => Foo();
//fun. Get Foo Custom Attribute
}
[CustomAttrib]
public static object Foo() {
return new object();
}
答案 0 :(得分:2)
使用- (NSMutableDictionary *)deepMutableCopyOfDictionary:(NSDictionary *)dictionary
{
NSMutableDictionary *mutableDictionary = [dictionary mutableCopy];
for (id key in [mutableDictionary allKeys]) {
id value = mutableDictionary[key];
if ([value isKindOfClass:[NSDictionary class]]) {
// If the value is a dictionary make it mutable and call recursively
mutableDictionary[key] = [self deepMutableCopyOfDictionary:dictionary[key]];
}
else if ([value isKindOfClass:[NSArray class]]) {
// If the value is an array, make it mutable
mutableDictionary[key] = [(NSArray *)value mutableCopy];
}
}
return mutableDictionary;
}
时,您要查找的信息不可用AFAIK。
但是,如果它是private final String User_role ="admin";
if(User_role.eguals(UserRole.getUser())){
PreparedStatement st = session.connection().prepareStatement("{update tblUser user set user.user_role = ? where (Condition)}");
st.setString(1,User_role );
st.execute();
}
,那将非常简单:
Function
您可以使用Expression
方法将Expression<Func<object>> expression = () => Foo();
var method = ((MethodCallExpression)expression.Body).Method;
Console.WriteLine(method.GetCustomAttributes(false)[0]);
转换为Expression
。
Function
如果您自己定义Compile()
,这可能会有所帮助,但如果来自某些您无法修改的第三方代码则不会。