0
基本的に、XMLを使用して外部コードのロードを駆動する旧バージョンのコードをいくつか用意しました。リフレクトを使用した具体的な汎用クラスのロード
例えば
ObjectHandle handle = Activator.CreateInstance(
information.AssemblyName,
information.TypeName);
loadedObject = (T)handle.Unwrap();
その上、一般的なパラメータを持っているタイプをロードしようとしたときただし、これは失敗します。コンパイル時にタイプがどのようになるかを知っています(おそらく型も外部にあり、状況によって変わる可能性があります)。 Tは型ActionSettings
public class MockTestRunner<T> : IRunner<T> where T : class
{
#region IRunner<T> Members
public T Run(string runnerXml)
{
MvcActionSettings mvcActionSettings = XmlSerialiser.XmlDeserialise<MvcActionSettings>(runnerXml);
IMvcActionSettingsCreator creator = new MockPassThroughActionSettingsGenerator();
var v = creator.Create(mvcActionSettings);
return v as T;
}
public void Initialise(IWizardManagerBase manager)
{
}
}
/// <summary>
/// An MVC controller settings object.
/// </summary>
[Serializable]
public class ActionSettings
{
/// <summary>
/// Initializes a new instance of the ActionSettings class.
/// </summary>
public ActionSettings()
{
PartialViews = new List<PartialViewEntity>();
}
public ActionSettings(bool endOfWizard)
{
EndOfWizard = endOfWizard;
}
public bool EndOfWizard
{
get;
set;
}}
よろしく、 ジェイミー
http://stackoverflow.com/questions/266115/pass-an-instantiated-system-type-as-a-type-parameter-for-a-generic-class –
ありませんかなりの場合、Typeパラメータは実行中のアセンブリ内またはフレームワーク内に明示的に存在します。私はそれを外部の種類をロードする必要があります。 – Jamie