Есть ли возможность не «приводить» top.First (). Value () возвращаться к «Node», а скорее автоматически принимать это (в отличие от NodeBase), поэтому я вижу расширенные атрибуты для класс, который я определяю в Node?
То есть есть способ сказать:
top.Nodes.First().Value.Path;
вместо того, чтобы идти теперь:
((Node)top.Nodes.First().Value).Path)
спасибо
[TestMethod()]
public void CreateNoteTest()
{
var top = new Topology();
Node node = top.CreateNode("a");
node.Path = "testpath";
Assert.AreEqual("testpath", ((Node)top.Nodes.First().Value).Path); // *** HERE ***
}
class Topology : TopologyBase<string, Node, Relationship>
{
}
class Node : NodeBase<string>
{
public string Path { get; set; }
}
public class NodeBase<T>
{
public T Key { get; set; }
public NodeBase()
{
}
public NodeBase(T key)
{
Key = key;
}
}
public class TopologyBase<TKey, TNode, TRelationship>
where TNode : NodeBase<TKey>, new()
where TRelationship : RelationshipBase<TKey>, new()
{
// Properties
public Dictionary<TKey, NodeBase<TKey>> Nodes { get; private set; }
public List<RelationshipBase<TKey>> Relationships { get; private set; }
}