locked
Implicit Operators RRS feed

  • Question

  • Hi,

     

    In what seems like the "new" way to define a serviceport, such as in the iRobot example:

     

    Code Block

    ///

    /// IRobotCreateScript Main Operations Port

    ///

    [ServicePort]

    public class IRobotScriptingEngineOperations:

    PortSet

    {

    ///

    /// Portset Definition

    ///

    public IRobotScriptingEngineOperations():base(

    typeof(DsspDefaultLookup),

    typeof(DsspDefaultDrop),

    typeof(Get),

    typeof(ClearCurrentScript),

    ...

     

     

    I see a region called "Implicit Operators". I don't really understand any of that code and I cannot figure out why it is needed. Can someone please explain what the purpose of these implicit operators are for, and whether or not they are necessary. It seems that many of them contain information about operations that were previously dealt with behind the scenes.

     

    Would be it be enough to replace:

     

    Code Block

    [ServicePort()]

    public class SomeOperations : PortSet

    <

    DsspDefaultLookup,

    DsspDefaultDrop,

    Get,

    Subscribe,

    ...>

    {

    }

     

     

    with:

     

    Code Block

    [ServicePort]

    public class SomeOperations:

    PortSet

    {

    /// <summary>

    /// Portset Definition

    /// </summary>

    public SomeOperations():base(

    typeof(DsspDefaultLookup),

    typeof(DsspDefaultDrop),

    typeof(Get),

    typeof(Subscribe),

    ...

     

    }

     

     

    Thanks,

    Don

    Thursday, November 1, 2007 8:13 PM

Answers

  •  

    Don, you dont have to use this method of creating port sets (we call these Dynamic since you specify the types at runtime, when the PortSet is created). Its not the "new" method, its just the method you *must* use if you plan to have services running on the CompactFramework and they have more than 8 generic types. Or if you have port sets with more than 20 types in the XP/Desktop version of our runtime.

     

    The compactFramework has a wierd limitation in that generic types with more than 8 generic type arguments, will not JIT/run properly. So we were forced to create a dynamic version of the CCR PortSet, so you can have many, many types, but without using generics.

     

    Because no generics are used, this removes some type safety at compile time. So the wierd operators you see, are so this dynamic portset can cast itself to similar methods and types used by the PortSet<T,T1,T2....> versions.

     

    More is explained in this forum thread:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1553553&SiteID=1&mode=1

     

     

    Friday, November 2, 2007 11:16 PM