You can call the function with a lambda expression:
private void setFromQueryString<T>(Action<T> setter, String queryString, HttpContext context)
{
//here I want to handle pulling the values out of
//the query string and parsing them or setting them
//to null or empty string...
String valueString = context.Request.QueryString[queryString].ToString();
//I need to check the type of the property that I am setting.
//this is null so I can't check it's type
Type t = typeof(T);
...
setter(value);
}
You would call it like this:
setFromQueryString<int>(i => myFoo.Age = i, "inputAge", context);
EDIT: If you really want type inference:
private void setFromQueryString<T>(Func<T> getter, Action<T> setter, String queryString, HttpContext context) {
...
}
setFromQueryString(() => myFoo.Age, i => myFoo.Age = i, "inputAge", context);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…