MEF의 일부인 사용자 정의 속성을 만들었습니다. 여기에서 클래스와 관련된 ID 목록을 정의하여 쿼리 할 수 있습니다. 시스템 속성에 목록 추가
는 또한 클래스는 자체 내에서 정의를 포함하는이 내가 사용에 대해 생각하는 이유가 중요하다[SignalSystemData("ServiceIds", new List<int>(){1})]
어떻게 진행해야한다?
다음과 같이 검색 내 구현은 다음과 같습니다 정의와
var c = new Class1();
var v = c.EditorSystemList;
foreach (var lazy in v.Where(x=>x.Metadata.LongName=="ServiceIds"))
{
if (lazy.Metadata.ServiceId.Contains(serviceIdToCall))
{
var v2 = lazy.Value;
// v2 is the instance of MyEditorSystem
Console.WriteLine(serviceIdToCall.ToString() + " found");
}else
{
Console.WriteLine(serviceIdToCall.ToString() + " not found");
}
}
내 수출 클래스는 다음과 같아야합니다
[Export(typeof(IEditorSystem))]
[SignalSystemData("ServiceIds", new List<int>{1})]
public class MyEditorSystem1 : IEditorSystem
{
void test()
{
Console.WriteLine("ServiceID : 1");
}
}
public interface IEditorSystem
{
}
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class SignalSystemDataAttribute : ExportAttribute
{
public SignalSystemDataAttribute(string longName, List<int> serviceId)
: base(typeof (IEditorSystem))
{
LongName = longName;
ServiceId = serviceId;
}
public string LongName { get; set; }
public List<int> ServiceId { get; set; }
}
public interface IEditorSystemMetadata
{
string LongName { get; }
List<int> ServiceId { get; }
}
비행하지 않습니다. [특성 값은 (컴파일 시간) 상수 여야합니다]. (http://msdn.microsoft.com/en-us/library/yd21828z.aspx) –
@ Christian.K 내가 아는 바로는 그래서 나는 찾으려고합니다. 방법은, 코마 분리 한 끈을 사용하기 위하여 의지없이. – cpoDesign
아, 죄송합니다. 질문에 그 사실을 표시하고 싶을 수도 있습니다. 또한 내 대답. –