Generics and redundant type def's are annoying me..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert

    #1

    Generics and redundant type def's are annoying me..

    A typical declaration in a current project:
    Dim Graph As New QuickGraph.Undi rectedGraph(Of PointVertexType , TaggedEdge(Of PointVertexType , Integer))


    This gets passed as a parameter to several subroutines.
    I am sick of typing this verbose redundant declaration.
    Is there an easy way to define this once at the top of a module and then
    reuse this definition in all the other ByRefs?

    Such as:
    Dim MyGraphType as ?!? = QuickGraph.Undi rectedGraph(Of PointVertexType , TaggedEdge(Of PointVertexType , Integer))

    Function MyFn(Graph as MyGraphType)
    Function MyFn2(Graph as MyGraphType, FnState)
    Function MyFn3(Graph as MyGraphType, Fn2State)




    With this I could change the type in one place, rather than dozens..

    Thanks in advance.





  • (O)enone

    #2
    Re: Generics and redundant type def's are annoying me..

    Robert wrote:
    A typical declaration in a current project:
    Dim Graph As New QuickGraph.Undi rectedGraph(Of PointVertexType , TaggedEdge(Of PointVertexType , Integer))
    >
    >
    This gets passed as a parameter to several subroutines.
    I am sick of typing this verbose redundant declaration.
    Is there an easy way to define this once at the top of a module and then
    reuse this definition in all the other ByRefs?
    At the top of your source file, add the following:

    \\\
    Imports MyGraphType = QuickGraph.Undi rectedGraph(Of PointVertexType ,
    TaggedEdit(Of PointVertexType , Integer))
    ///

    (all on one line, in case this wraps in my post).

    After that you can use the GraphType alias exactly as you describe in
    your post.

    HTH!

    --
    (O)enone

    Comment

    • Robert

      #3
      Re: Generics and redundant type def's are annoying me..

      Robert wrote:
      >A typical declaration in a current project:
      >Dim Graph As New QuickGraph.Undi rectedGraph(Of PointVertexType , TaggedEdge(Of PointVertexType , Integer))
      >>
      >>
      >This gets passed as a parameter to several subroutines.
      >I am sick of typing this verbose redundant declaration.
      >Is there an easy way to define this once at the top of a module and then
      >reuse this definition in all the other ByRefs?
      >
      At the top of your source file, add the following:
      >
      \\\
      Imports MyGraphType = QuickGraph.Undi rectedGraph(Of PointVertexType ,
      TaggedEdge(Of PointVertexType , Integer))
      ///
      >
      (all on one line, in case this wraps in my post).
      >
      After that you can use the GraphType alias exactly as you describe in your post.
      This did not work..

      QuickGraph is a library I am using to do graph traversal.
      Undirected Graph is the specific type of graph that I need.
      This supports generics, hence the need to specify the types when declaring it..

      The problem with your idea is that PointVertexType , is declared in my code.
      So the imports chokes with the following errors in the line:

      Error 19 Type 'PointVertexTyp e' is not defined.
      Error 20 Type 'TaggedEdge' is not defined.
      Error 21 Type 'PointVertexTyp e' is not defined.

      I think the answer lies somewhere near this:
      Dim MyGraphType as System.Type = ?!?


      Wait, let me digest this:
      ms-help://MS.VSCC.v90/MS.MSDNQTR.v90. en/fxref_mscorlib/html/aedb823e-3f12-fc91-2c0a-0e478980e0cc.ht m

      the System.Type.Mak eGenericType methode.


      Comment

      • Armin Zingler

        #4
        Re: Generics and redundant type def's are annoying me..

        "Robert" <no@spam.comsch rieb
        >A typical declaration in a current project:
        Dim Graph As New QuickGraph.Undi rectedGraph(Of PointVertexType ,
        TaggedEdge(Of PointVertexType , Integer))
        >
        >
        This gets passed as a parameter to several subroutines.
        I am sick of typing this verbose redundant declaration.
        Is there an easy way to define this once at the top of a module and then
        reuse this definition in all the other ByRefs?
        >
        Such as:
        Dim MyGraphType as ?!? = QuickGraph.Undi rectedGraph(Of PointVertexType ,
        TaggedEdge(Of PointVertexType , Integer))
        >
        Function MyFn(Graph as MyGraphType)
        Function MyFn2(Graph as MyGraphType, FnState)
        Function MyFn3(Graph as MyGraphType, Fn2State)
        >
        >
        >
        >
        With this I could change the type in one place, rather than dozens..
        class MyUndirectedGra phOfPointVertex Type
        inherits QuickGraph.Undi rectedGraph _
        (of PointVertexType , TaggedEdge(Of PointVertexType , Integer))

        end class

        Didn't test it, but you should be able to use
        MyUndirectedGra phOfPointVertex Type everwhere now.

        Dim Graph as new MyUndirectedGra phOfPointVertex Type


        Armin

        Comment

        Working...