Raja Krishnaswamy and Jesse Kaplan: CLR 4 - Inside No-PIA

Play Raja Krishnaswamy and Jesse Kaplan: CLR 4 - Inside No-PIA

The Discussion

  • User profile image

    So this Type Equivalence... are we talking about something that might be the basis of "static duck typing" as in C++ templates?

    e.g. public static void Foo<T>(T arg) where T : IBar

    Currently this means T must implement IBar... will type equivalence open up the possibility that T could be something that satisfies the method signatures of IBar, but doesn't necessarily have to implement it?

    That would be great. Suppose I have to work with several third party classes, they all have a method:

        void Log(string str)

    but they don't implement any common interface. I might write:

        interface ICanLog { void Log(string str); }

    Would I then (with some attribute magic?) be able to assign instances of those third party classes to variables/parameters of that interface type?

        ICanLog canLog = new ThirdPartyThing();


  • User profile image

    Bah... based on this, I'm guess the answer is no.

  • User profile image

    If you think about it, type equivalence is about matching two essentially 'identical' types that are not actually the same clr type.. which is different to duck typing which is more of a.. these types are different (even outside of the clr type), but they look similar.

    The key difference tending to be that type equivalence is about allowing a boundary to be broken where two types are intending to be the same thing, but duck typing is less about the types intending to be the same, but just looking the same.

    Personally I don't see a lot of places where duck typing would be useful.. tends to be a simple proxy class fits most scenarios.

  • User profile image

    It becomes more of a problem as a project evolves over several years, especially with independently developed components going into it.

    Over time, the number of cases where proxy classes are needed grows until they blot out the intention of the "actual" code, which is when a language feature becomes valuable.

  • User profile image

    Does this embedding only work if you use a VSTO template in Visual Studio?

    For example, I'm working on project right now that's a WPF application which uses the PIAs to extract data from Excel for use by another application, and my app is basically a bridge for these programs, is this scenario supported?

  • User profile image

    Don't we have type embedding already, of sorts. Open up Reflector load say, the Word PIA and cut and paste the class interfaces you need into your project. This then gives you masive flexibility to modify the interfaces, leave member out and/or redefine members so they do not throw exceptions, but return hResults. Then you can use Compiler extensions to bolt on Word 12 interfaces and methods onto the Word 10/11 Object model. This is a very usefull trick Wink

  • User profile image


Add Your 2 Cents