0
リフレクションを使用して、アセンブリ内のすべての型を取得しました。私はそれがインタフェース「のICommand」実行時に明示的に型をInterfaceにキャストする
ICommand C;
foreach(Type t in asm.GetTypes())
{
if (t.GetInterfaces()[0].Name is "ICommand")
{
C = (ICommand)t; //throws Exception here - Unable
//to cast to ICommand
RootDir.AddCommand(C, t.Namespace.Split('.'));
}
}
私はこのようにを実装する必要がありますどのように
public interface ICommand
{
string HelpDescription { get; }
void Execute(CommandClass CC);
}
class CurrentDir : ICommand
{
public string HelpDescription => "Current Directory - Change current directory";
public static explicit operator CurrentDir (Type T)
{
return new CurrentDir();
}
void ICommand.Execute(CommandClass CC)
{
throw new NotImplementedException();
}
}
をキャストしようとしていますタイプの例を実装していることを知っているかどうかはどのようにICommandのにT型にキャストすることができますSystem.TypeからICommandにキャストできますか?