void CreateTypes()
{
ProxyAssemblyBuilder builder = new ProxyAssemblyBuilder();
// Creates IList<T> and ListProxy<T>:
builder.AddType(typeof(System.Collections.Generic.List<>));
// Creates IStack and StackProxy, the latter of which encapsulates a Stack<int> instance
builder.AddType(typeof(System.Collections.Generic.Stack<int>));
builder.CreateAssembly();
}
void CreateMethods()
{
Type realSubjectType = typeof(System.Collections.Generic.Dictionary<,>);
ProxyTypeBuilder builder = new ProxyTypeBuilder("namespace", realSubjectType);
// Add and ContainsKey are implemented in terms of generic type arguments.
builder.AddMethod(realSubjectType.GetMethod("Add"));
builder.AddMethod(realSubjectType.GetMethod("ContainsKey"));
builder.AddProperty(realSubjectType.GetProperty("Count"));
builder.CreateProxy();
}
If you use the ProxyAssemblyGen.exe program as your driver, then you should familiarize yourself with the .NET Assembly Qualified Name syntax for types. This syntax is used in the XML file that is passed to the console program, and the type names are ultimately passed to a Type.GetType() method for loading.
The ProxyTypeBuilder still lacks support for handling generic methods, and I've added code to explicitly warn a caller when such a method is encountered. My next task will be to work on issue #29, which addresses generic methods. Furthermore, I need to clean-up some of the code, remove some duplication, and ultimately update to Visual Studio 9/.NET 3.5/C# 3.0.
Things are looking good as we approach the first release!
0 comments:
Post a Comment