Click here to Skip to main content
15,891,629 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to Create the listener service for SOAP messages in C# Pin
snorkie28-Mar-08 6:03
professionalsnorkie28-Mar-08 6:03 
GeneralRe: How to Create the listener service for SOAP messages in C# Pin
zaboboa28-Mar-08 9:09
zaboboa28-Mar-08 9:09 
Generalopen Pin
ellllllllie28-Mar-08 5:02
ellllllllie28-Mar-08 5:02 
GeneralRe: open Pin
Giorgi Dalakishvili28-Mar-08 5:20
mentorGiorgi Dalakishvili28-Mar-08 5:20 
GeneralRe: open Pin
ellllllllie28-Mar-08 5:53
ellllllllie28-Mar-08 5:53 
GeneralRe: open Pin
Not Active28-Mar-08 6:55
mentorNot Active28-Mar-08 6:55 
Generalmsmq from outside the domain Pin
Seishin#28-Mar-08 4:57
Seishin#28-Mar-08 4:57 
QuestionGeneric interface problem Pin
Neokork28-Mar-08 4:48
Neokork28-Mar-08 4:48 
Hi,
I'm trying to build a generic Tree structure. The structure is based around parent node objects that are connected with edge object to its children node objects, everything starting from a root node object. The structure is contained in a tree object. For increased usability there is also a separate edge-connector object that stores each child- and parent node with its edge object.
Each node object contains a node element object and each edge object contains a edge element object, which are represented as respectively the generic types N and E.
To calculate the cost of traversing all edges to the leaf nodes, I've implemented a call from the tree object method GetEdgeElementsCost() that access the method int GetCost(TreeNode<N, E> ChildNode) of the generic type E through the implementation of an interface. There seem however to be something wrong with this approach as I keep getting errors when I try to compile.


I got the following errors:
Error 1 The type 'N' cannot be used as type parameter 'N' in the generic type or method 'WindowsFormsTestApplication1.TreeNode<N,E>'. There is no boxing conversion or type parameter conversion from 'N' to 'WindowsFormsTestApplication1.INodeElement'.
Error 2 The type 'E' cannot be used as type parameter 'E' in the generic type or method 'WindowsFormsTestApplication1.TreeNode<N,E>'. There is no boxing conversion or type parameter conversion from 'E' to 'WindowsFormsTestApplication1.IEdgeElement<N,E>'.

Here is an extract of the code:
public interface IEdgeElement<N, E>
{
    int GetCost(TreeNode<N, E> ChildNode);
}


public interface INodeElement
{
}


public class Tree<N, E>
    where N : INodeElement
    where E : IEdgeElement<N, E>
{
    private List<EdgeConnector<N, E>> _EdgeList;

    public Tree()
    {
        _EdgeList = new List<EdgeConnector<N, E>>();
    }

    public int GetEdgeElementsCost()
    {
        int cost = 0;

        for (int i = 0; i < this._EdgeList.Count; i++)
        {
            cost = cost + this._EdgeList[i].Edge.Element.GetCost(this._EdgeList[i].ChildNode);
        }

        return cost;
    }
}


public class EdgeConnector<N, E>
    where N : INodeElement
    where E : IEdgeElement<N, E>
{
    private TreeEdge<N, E> _Edge = null;
    private TreeNode<N, E> _ChildNode = null;

    public TreeEdge<N, E> Edge
    {
        get
        {
            return _Edge;
        }
        set
        {
            _Edge = value;
        }
    }

    public TreeNode<N, E> ChildNode
    {
        get
        {
            return _ChildNode;
        }
        set
        {
            _ChildNode = value;
        }
    }

}


public class TreeEdge<N, E>
    where N : INodeElement
    where E : IEdgeElement<N, E>
{
    private E _Element;

    public TreeEdge(E Element)
    {
        this._Element = Element;
    }

    public E Element
    {
        get
        {
            return this._Element;
        }
    }
}


public class TreeNode<N, E>
    where N : INodeElement
    where E : IEdgeElement<N, E>
{
}


Anyone who knows how to solve this problem?
Thanks Smile | :)
GeneralRe: Generic interface problem Pin
Judah Gabriel Himango29-Mar-08 14:36
sponsorJudah Gabriel Himango29-Mar-08 14:36 
GeneralContext menu senders Pin
tjschilling28-Mar-08 4:46
tjschilling28-Mar-08 4:46 
GeneralRe: Context menu senders Pin
Giorgi Dalakishvili28-Mar-08 5:22
mentorGiorgi Dalakishvili28-Mar-08 5:22 
GeneralRe: Context menu senders Pin
tjschilling28-Mar-08 5:42
tjschilling28-Mar-08 5:42 
GeneralRe: Context menu senders Pin
Giorgi Dalakishvili28-Mar-08 5:53
mentorGiorgi Dalakishvili28-Mar-08 5:53 
Generalquestion with internationalization Pin
robustm28-Mar-08 3:55
robustm28-Mar-08 3:55 
GeneralRe: question with internationalization Pin
nelo_28-Mar-08 4:34
nelo_28-Mar-08 4:34 
GeneralQuestion about Smart Client Pin
Vimalsoft(Pty) Ltd28-Mar-08 3:46
professionalVimalsoft(Pty) Ltd28-Mar-08 3:46 
GeneralRe: Question about Smart Client Pin
nelo_28-Mar-08 4:42
nelo_28-Mar-08 4:42 
GeneralRe: Question about Smart Client Pin
Vimalsoft(Pty) Ltd30-Mar-08 20:02
professionalVimalsoft(Pty) Ltd30-Mar-08 20:02 
GeneralRe: Question about Smart Client Pin
Gareth H28-Mar-08 7:08
Gareth H28-Mar-08 7:08 
GeneralRe: Question about Smart Client Pin
Vimalsoft(Pty) Ltd30-Mar-08 20:06
professionalVimalsoft(Pty) Ltd30-Mar-08 20:06 
QuestionHow to hide the particular column in Listview? Pin
Mohan Kumar28-Mar-08 3:38
Mohan Kumar28-Mar-08 3:38 
GeneralRe: How to hide the particular column in Listview? Pin
Stu Richardson28-Mar-08 4:03
Stu Richardson28-Mar-08 4:03 
GeneralRe: How to hide the particular column in Listview? Pin
Reelix28-Mar-08 4:24
Reelix28-Mar-08 4:24 
GeneralRe: How to hide the particular column in Listview? Pin
Stu Richardson28-Mar-08 4:28
Stu Richardson28-Mar-08 4:28 
GeneralRe: How to hide the particular column in Listview? Pin
jchalfant28-Mar-08 8:20
jchalfant28-Mar-08 8:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.