none
.NET, COM, Parametric Polymorphism and Generics RRS feed

  • General discussion

  • Greetings.  I would like to request a feature for .NET 5.  I would like for COM objects to be interoperable with parametric polymorphism, generics.

    var x1 = (IEnumerable<string>)com_object;
    var x2 = com_object as IEnumerable<string>;

    As described at Interoperating Using Generic Types (http://msdn.microsoft.com/en-us/library/ms229590.aspx), accessing generic interfaces from COM and accessing class interfaces for nongeneric classes that derive from generic classes are not presently supported in .NET 4.5 .  Such functionality would be very useful .NET COM interoperability scenarios.

    A related publication is Parametric Polymorphism for Software Component Architectures (http://curis.ku.dk/ws/files/38296554/GIDLoopsla.pdf).

    Saturday, April 6, 2013 4:55 PM

All replies

  • Hi Adam,

    To let Microsoft know you well, please submit your idea here: http://visualstudio.uservoice.com/forums/121579-visual-studio 

    Thank you for your understanding and support.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 8, 2013 12:39 AM
    Moderator
  • Mike,

    Thanks for the link.  It would be interesting to see how many other developers would be interested in the .NET, COM, parametric polymorphism and generics topics and in other features such as mathematics layout and rendering in DirectX's DirectWrite (http://xboxforums.create.msdn.com/forums/t/94145.aspx).

    The discussion topics can be phrased as .NET 5, COM, WinRT, C++/CX and parametric polymorphism, generics.  Some Windows 8, Windows Runtime, WinRT encyclopedic content (http://en.wikipedia.org/wiki/Windows_Runtime) indicates that "WinRT is essentially a COM-based API, although relying on an enhanced COM. Due to its COM-like basis, WinRT allows interfacing from multiple languages, just as COM does, but it's essentially an unmanaged, native API. The API definitions are, however, stored in '.winmd' files, which are encoded in ECMA 335 metadata format, the same format that .NET uses with a few modifications. This common metadata format allows for significantly less overhead when invoking WinRT from .NET applications compared to P/Invoke, and much simpler syntax. The new C++/CX (Component Extensions) language, which borrows some C++/CLI syntax, allows the authoring and consumption of WinRT components with less glue visible to the programmer compared to classic COM programming in C++, and at the same time imposes fewer restrictions compared to C++/CLI on the mixing of types. Regular C++ (with COM-specific discipline) can also be used to program with WinRT components, with the help of the new Windows Runtime C++ Template Library (WRL), which is similar in purpose to what Active Template Library provides for COM. The MSDN Library, however, recommends using C++/CX instead of WRL."

    Thom Gerdes describes (http://www.thomgerdes.com/2011/12/winrt-internals-winmd-files.html) that "generics are used pretty heavily throughout WinRT. In the C++ language bindings, they end up translating down to a template class, and the pre-compiled headers actually have to parametrize every instance of a generic class. This is pretty ugly and it'd be much nicer to just declare the interface and have the compiler do the right thing. Delphi has a similar problem for similar reasons. Generic Interfaces are supported by the compiler, but the problem arises in that you cannot specify a GUID for parametrized instances of a given generic interface. So for now, I've had to create a unique interface for every parameterized interface in WinRT. But how do you go about assigning a GUID to the interfaces? The answer lies in RoGetParameterizedTypeInstanceIID (http://msdn.microsoft.com/en-us/library/br229857%28v=VS.85%29.aspx)."

    There may already be WinRT development techniques for the enhanced .NET and COM interoperability scenarios.  Implementation options additionally include interfaces with methods like QueryInterface with parameters including either a tree of GUID's, the _Type interface (http://msdn.microsoft.com/en-us/library/system.runtime.interopservices._type.aspx) or a _Type2 interface.

     


    Kind regards,

    Adam Sobieski

    Monday, April 8, 2013 1:03 PM
  • Mike,

    That Windows Runtime encyclopedia article (http://en.wikipedia.org/wiki/Windows_Runtime#Type_system) indicates that "one of the major additions to WinRT relative to COM is the cross-ABI, .NET-style generics. In C++/CX these are declared using the generic keyword with a syntax very similar to that of the template keyword. WinRT classes (ref classes) can also be genericized using C++ templates but only template instantiations can be exported to .winmd metadata (with some name mangling), unlike WinRT generics which preserve their genericity in the metadata."

    I'm writing the UserVoice forum items.  In addition to the C++ COM topics and the templates and generics topics (http://en.wikipedia.org/wiki/Generic_programming), topics could include full and partial explicit specialization for both templates and generics, enhanced expressiveness for template and generic parameter constraints, enhanced heuristics for resolving types and methods, and related language enhancements.

     

     

    Kind regards,

    Adam Sobieski

    Wednesday, April 10, 2013 12:37 PM
  • Hi Adam,

    Thank you for this valuable idea.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 15, 2013 9:22 AM
    Moderator