0
기본적으로 우리는 XML을 사용하여 외부 코드로드를 유도하는 이전 버전의 코드를 가지고있었습니다.리플렉션을 사용하여 구체적인 유형의 일반 클래스로드
예컨대
ObjectHandle handle = Activator.CreateInstance(
information.AssemblyName,
information.TypeName);
loadedObject = (T)handle.Unwrap();
그것에 일반적인 매개 변수가있는 형식을로드 할 때 그러나,이 실패합니다. 이제 형식이 컴파일 타임에 어떻게 될지 알 수 있습니다 (형식이 외부 일 수도 있고 상황에 따라 달라질 수도 있습니다 (XML 만 해당)). 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