Click here to Skip to main content
15,891,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using generics and doing the following:
I am calling my generic method but providing it a type which is determined at runtime, not at compile time, but it does not work.

Can anybody suggest any sort of help?

Regards.
C#
public static void GetChild<T>(T obj, string objName, EntityEvent<T> APICallback) where T : Entity
{
  Type tp = null;
  PropertyInfo[] prop = obj.GetType().GetProperties();
  foreach (PropertyInfo pInfo in obj.GetType().GetProperties())
  {
    if (pInfo.Name == objName)
    { tp = pInfo.GetType(); }
    break;
  }
  APIHelper.GetEntity<tpp>(obj, APICallback); //This does not work

}
Posted
Updated 6-Jan-11 21:52pm
v4
Comments
JF2015 7-Jan-11 3:40am    
Added code formatting - always wrap you code snippets in <pre> tags.
Espen Harlinn 7-Jan-11 3:46am    
In "APIHelper.GetEntity<tpp>(obj, APICallback);" you use tpp, was that supposed to be tp?
Dalek Dave 7-Jan-11 3:52am    
Minor Edit for Readability.

1 solution

Where is tpp defined?

You're using it on the
APIHelper.GetEntity<tpp>(obj, APICallback);

line, but I can't see where it's defined.

Should it be

APIHelper.GetEntity<t>(obj, APICallback);</t>


instead?

Hope this helps,
Fredrik Bornander
 
Share this answer
 
v2
Comments
Dalek Dave 7-Jan-11 3:52am    
That should help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900