クラスをベースインターフェイスにダウンコンバートする際に問題があります。私は(簡体字)、次があります。ジェネリックタイプのインターフェイスでクラスからインターフェイスに変換するインターフェイス<Interface>
public interface ITaxonomy
{
string CommonName { get; set; }
string ScientificName { get; set; }
}
public interface ITaxonomyHasChildren<TChild> : ITaxonomy where TChild : ITaxonomy
{
ICollection<TChild> Children { get; set; }
}
public interface ITaxonomyHasParent<TParent> : ITaxonomy where TParent : ITaxonomy
{
TParent Parent { get; set; }
}
をそして私は私のVMに出て戻ってデータを抽出する必要があります。
private void SelectedEntityChanged(ITaxonomy selectedEntity)
{
CommonName = selectedEntity.CommonName;
ScientificName = selectedEntity.ScientificName;
Children = selectedEntity.GetType().GetProperty(nameof(ITaxonomyHasChildren<ITaxonomy>.Children))?
.GetValue(selectedEntity) as ICollection<ITaxonomy>;
Parent = selectedEntity.GetType().GetProperty(nameof(ITaxonomyHasParent<ITaxonomy>.Parent))?
.GetValue(selectedEntity) as ITaxonomy;
}
Children
一部が動作しない、それはをdoesnのため、私は想定していますtをICollection<MyClass>
からICollection<ITaxonomy>
に変更すると、
どのようにすればいいですか?
が展開し、 "動作しない"、例外はありますか?期待される行動は何か。 – raidensan