C# 收集属性值
如果这有点复杂,我会提前道歉 我有这样一个属性类:C# 收集属性值,c#,code-generation,envdte,texttemplate,C#,Code Generation,Envdte,Texttemplate,如果这有点复杂,我会提前道歉 我有这样一个属性类: [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] public class RepositoryCollectionMethodAttribute : Attribute { public string MethodName { get; set; } public RepositoryCollectionMethodAttribute(strin
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RepositoryCollectionMethodAttribute : Attribute
{
public string MethodName { get; set; }
public RepositoryCollectionMethodAttribute(string methodName)
{
MethodName = methodName;
}
}
我正在使用EnvDTE
遍历我的类域,收集类以生成代码。查找使用RepositoryCollectionMethod
装饰一个或多个属性的类
这一部分相对简单,因此对于每个具有一些修饰属性的类,我现在有一个IEnumerable
I调用properties
现在我被卡住了。由于这些EnvDTE对象的性质(它们似乎不喜欢强类型和好的文档/示例),我不知道如何从属性集合中提取MethodName
property值的不同列表,其中至少有一个将有RepositoryCollectionMethod
装饰它
换句话说,如果我有这样一个“Foo”类:
public class Foo
{
public Guid FooId { get; set; }
[RepositoryCollectionMethod("GetFoosByCategory")]
public string Category { get; set; }
[RepositoryCollectionMethod("GetFoosByClass")]
[RepositoryCollectionMethod("GetFoosByClassAndLot")]
public string Class { get; set; }
[RepositoryCollectionMethod("GetFoosByLot")]
[RepositoryCollectionMethod("GetFoosByClassAndLot")]
public string Lot { get; set; }
}
…给定Foo
属性的IEnumerable
,我想生成以下列表:
- GetFoosByCategory
- GetFoosByClass
- GetFoosByClassAndLot
- GetFoosByLot
有人能帮我吗?你找到答案了吗?结果走了一条完全不同的路;你是怎么做到的,如果可能的话,我可以解释一下?基本上,我使用了一种基于约定的fluent方法来定义我希望如何构建存储库查询。