An interface member that is explicitly implemented cannot be accessed from a class instance. That means


interface IHierarchyItem<T>

{

T Id{get;}

T ParentId{ get;}

int Level{get;set;}

}

class ImportedDataItem: IHierarchyItem<string>

{

string IHierarchyItem<string>.Id=> ...;

string IHierarchyItem<string>.ParentId => ...;

int IHierarchyItem<string>.Level { ... };

}

var item = new ImportedDataItem.Builder( rawData ).Build();

if( string.IsNullOrEmpty( item.ParentId ) )

{

...

}

 

will fail to compile.

The code should be changed to


var hierarchyItem = item as IHierarchyItem<string>;

if( string.IsNullOrEmpty( hierarchyItem.ParentId ) )

{

....

}

Advertisements