Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 收集属性值_C#_Code Generation_Envdte_Texttemplate - Fatal编程技术网

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方法来定义我希望如何构建存储库查询。