私は次のクラスを持っています:
namespace CommonInterfaces
{
public interface INode
{
int? ParentNodeId { get; set; }
int? ChildNodeId { get; set; }
}
}
public class FieldDependencyModel : DataModel<int>, ICacheable
{
#region Field
private int _FieldDependencyId;
private int? _FieldId;
private int? _FieldParentId;
#endregion
#region Properties
public virtual int FieldDependencyId
{
get { return getPropertyValue("FieldDependencyId",_FieldDependencyId); }
set { _FieldDependencyId = value; }
}
public virtual int? ChildNodeId
{
get { return getPropertyValue("FieldId",_FieldId); }
set { _FieldId = value; }
}
public virtual int? ParentNodeId
{
get { return getPropertyValue("FieldParentId",_FieldParentId); }
set { _FieldParentId = value; }
}
#endregion
}
public interface IFieldDependencyService
{
IList<FieldDependency> GetAllFieldDependencies();
}
public class FieldDependency : FieldDependencyModel, INode
{
}
public class FieldDependencyDataService : BaseDataService, IFieldDependencyService
{
public FieldDependencyDataService(DataAccessHandle serviceHandler) : base(serviceHandler) {}
public IList<FieldDependency> GetAllFieldDependencies()
{
return _accessService.loadAll<FieldDependency>();
}
}
public class TreeService
{
private IList<INode> _relationships;
private INode _rootNode;
public TreeService(INode rootNode, IList<INode> nodeRelationships)
{
_relationships = nodeRelationships;
_rootNode = rootNode;
}
public Tree<INode> BuildTree()
{
Tree<INode> tree;
tree = new Tree<INode>(_rootNode, _relationships);
return tree;
}
}
INodeを実装するタイプを送信しようとしましたが、fieldDependencies を新しい TreeService インスタンス化に渡そうとすると、次のエラーが表示されます。
Error 5 Argument 2: cannot convert from 'System.Collections.Generic.IList<FieldDependency>' to 'System.Collections.Generic.IList<CommonInterfaces.INode>'
このエラーが発生する呼び出しコードは次のとおりです。
IList<FieldDependency> fieldDependencies = _service.GetAllFieldDependencies();
FieldDependency rootDependency = fieldDependencies.First(d => d.ParentNodeId == null);
var service = new TreeService(rootDependency, fieldDependencies); // fails here, doesn't like fieldDependencies