Hi Guys
I have an object obj
that is passed into a helper method.
public static MyTagGenerateTag<T>(this HtmlHelper htmlHelper, T obj /*, ... */)
{
Type t = typeof(T);
foreach (PropertyInfo prop in t.GetProperties())
{
object propValue = prop.GetValue(obj, null);
string stringValue = propValue.ToString();
dictionary.Add(prop.Name, stringValue);
}
// implement GenerateTag
}
I've been told this is not a correct use of generics. Can somebody tell me if I can achieve the same result without specifying a generic type? If so, how?
I would probably change the signature so it'd be like:
public static MyTag GenerateTag(this HtmlHelper htmlHelper, object obj /*, ... */)
{
Type t = typeof(obj);
// implement GenerateTag
}
but Type t = typeof(obj);
is impossible.
Any suggestions?
Thanks
Dave