Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- delegate RET FunctionDelegate<T, RET>(T t);
- void func<T, RET>(FunctionDelegate function, T param, ...)
- {
- ...
- return function.Invoke(param);
- }
- value = obj.GetType().GetProperty("Foo").GetAccessors()[0].Invoke(obj,null);
- obj.GetType().GetProperty("Foo").GetAccessors()[1].Invoke(obj,new object[]{value});
- delegate RET FunctionDelegate<T, RET>(T t);
- void func<T, RET>(FunctionDelegate<T,RET> function, T param, ...)
- {
- ...
- return function(param);
- }
- SomeClass obj = new SomeClass();
- func<SomeClass,int>(delegate(SomeClass o){return o.Foo;},obj);
- static void Method<T, U>(this T obj, Expression<Func<T, U>> property)
- {
- var memberExpression = property.Body as MemberExpression;
- //getter
- U code = (U)obj.GetType().GetProperty(memberExpression.Member.Name).GetValue(obj, null);
- //setter
- obj.GetType().GetProperty(memberExpression.Member.Name).SetValue(obj, code, null);
- }
- DbComputerSet cs = new DbComputerSet();
- cs.Method<DbComputerSet, string>(set => set.Code);
Add Comment
Please, Sign In to add comment