WilsonORMapper v4.1.1 Released -- With a Big Thanks to Paul Welter

Update: WilsonORMapper v4.1.1.0 (8/13/2005) includes the following:
  • Added new InitialState.Updated enum value for the StartTracking method.
  • This allows immediate PersistChanges -- useful for distributed systems.
  • Now supports generic relation collections -- even for the lazy-load case.
  • This feature was added by Paul Welter -- his templates are also updated.
By the way, after looking at Paul's code that nicely creates the generic relation collections, I then recalled why I hadn't done that myself -- I couldn't figure out how to do what he did. I remember even doing some googling and convincing myself that you simply could not have a generic type created where the type itself was a variable -- so I just gave up and forgot it. So congratulations Paul -- you're a generic wizard and you have made the ORMapper much better !

6 Comments

  • Thanks for the compliments though I must confess I had to ask around for the answer as well. :) I've blogged about how it is done.



    ~ Paul

  • So how do you do it then? I had exactly the same problem Mr Wilson described I couldn't figure out how to pass a generic type where the type itself was a variable?



    Paul can you post some indicative code?

  • Paul Welter details on his blog, but here's the simple code snippet:



    private BindingFlags internalFlags = BindingFlags.CreateInstance | (BindingFlags.NonPublic | BindingFlags.Instance);

    Type genericType = typeof(CustomType<>).MakeGenericType(type);

    object[] args = new object[] { ... };

    relations = Activator.CreateInstance(genericType, internalFlags, null, args, null, null);

  • Aargh... I wish I had run into this post a while earlier because I struggled with this one for quite a while as well before figuring it out. Generics for all the power they present are going to take some time to digest and figure out all the oddities that they represent to the type system.



    Actually there's a slightly easier way:



    this.m_GenericEntity = Activator.CreateInstance<EntityType>();



  • Rick: That work's great if you know the whole type (RootType<InnerType>) as a variable, but it doesn't work if both parts are variables.

  • Sheesh. You guys are all way over my head. Now I have a reason to start playing with .Net 2.0 - just so I can play and learn about all this stuff and keep up with the conversation.

Comments have been disabled for this content.