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

  • Thread starter Thread starter Robert
  • Start date Start date
R

Robert

A typical declaration in a current project:
Dim Graph As New QuickGraph.UndirectedGraph(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.UndirectedGraph(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.
 
Robert said:
A typical declaration in a current project:
Dim Graph As New QuickGraph.UndirectedGraph(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.UndirectedGraph(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!
 
Robert said:
At the top of your source file, add the following:

\\\
Imports MyGraphType = QuickGraph.UndirectedGraph(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 'PointVertexType' is not defined.
Error 20 Type 'TaggedEdge' is not defined.
Error 21 Type 'PointVertexType' 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.htm

the System.Type.MakeGenericType methode.
 
Robert said:
A typical declaration in a current project:
Dim Graph As New QuickGraph.UndirectedGraph(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.UndirectedGraph(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 MyUndirectedGraphOfPointVertexType
inherits QuickGraph.UndirectedGraph _
(of PointVertexType, TaggedEdge(Of PointVertexType, Integer))

end class

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

Dim Graph as new MyUndirectedGraphOfPointVertexType


Armin
 
Robert,

I am not knowing what you are up to.

However, be aware that the signature is not only to pass, it is ass well to
keep all overloads apart, that's why you see so many situations were simple
an integer should be enough, but then an int16 is used to seperate.

Cor
 
I have no idea what your reply means.
I am not knowing what you are up to.

However, be aware that the signature is not only to pass, it is ass well to keep all overloads apart,

Not using any overloads..
that's why you see so many situations were simple an integer should be enough, but then an int16 is used to seperate.

Seperate what?!?
 
Back
Top