Just to add to the other answers, I made the following test (more specific to how you are structuring your code):
public class XmlCodec<T>
{
public List<string> MyList = new List<string>();
public string GetCollectionName()
{
return "Some Collection Name";
}
public void ReadCollection(string collectionName)
{
for (int i = 0; i < 100; i++)
MyList.Add(collectionName + i.ToString());
}
}
class Program
{
static void Main(string[] args)
{
Type xmlCodecType = typeof(XmlCodec<>).MakeGenericType(typeof(string));
dynamic xmlCodec = Activator.CreateInstance(xmlCodecType);
xmlCodec.ReadCollection(xmlCodec.GetCollectionName());
Print(xmlCodec);
Console.ReadKey(true);
}
public static void Print(dynamic obj)
{
foreach (string s in obj.MyList)
Console.WriteLine(s);
}
}
Now, in DotPeek, this is what it looks like (Print method omitted for brevity):
private static void Main(string[] args)
{
object instance = Activator.CreateInstance(typeof (XmlCodec<>).MakeGenericType(typeof (string)));
// ISSUE: reference to a compiler-generated field
if (Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site1 == null)
{
// ISSUE: reference to a compiler-generated field
Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site1 = CallSite<Action<CallSite, object, object>>.Create(Binder.InvokeMember(CSharpBinderFlags.ResultDiscarded, "ReadCollection", (IEnumerable<Type>) null, typeof (Program), (IEnumerable<CSharpArgumentInfo>) new CSharpArgumentInfo[2]
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string) null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string) null)
}));
}
// ISSUE: reference to a compiler-generated field
Action<CallSite, object, object> action = Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site1.Target;
// ISSUE: reference to a compiler-generated field
CallSite<Action<CallSite, object, object>> callSite = Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site1;
object obj1 = instance;
// ISSUE: reference to a compiler-generated field
if (Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site2 == null)
{
// ISSUE: reference to a compiler-generated field
Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site2 = CallSite<Func<CallSite, object, object>>.Create(Binder.InvokeMember(CSharpBinderFlags.None, "GetCollectionName", (IEnumerable<Type>) null, typeof (Program), (IEnumerable<CSharpArgumentInfo>) new CSharpArgumentInfo[1]
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string) null)
}));
}
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
object obj2 = Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site2.Target((CallSite) Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site2, instance);
action((CallSite) callSite, obj1, obj2);
// ISSUE: reference to a compiler-generated field
if (Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site3 == null)
{
// ISSUE: reference to a compiler-generated field
Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site3 = CallSite<Action<CallSite, Type, object>>.Create(Binder.InvokeMember(CSharpBinderFlags.ResultDiscarded, "Print", (IEnumerable<Type>) null, typeof (Program), (IEnumerable<CSharpArgumentInfo>) new CSharpArgumentInfo[2]
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.IsStaticType, (string) null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, (string) null)
}));
}
// ISSUE: reference to a compiler-generated field
// ISSUE: reference to a compiler-generated field
Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site3.Target((CallSite) Program.\u003CMain\u003Eo__SiteContainer0.\u003C\u003Ep__Site3, typeof (Program), instance);
Console.ReadKey(true);
}
Notice how the type and activation have been consolidated into one line. The rest of the method body (aside from the Print at the bottom) is for calling the two nested methods which look like they have been expanded into two calls.