小编dan*_*ier的帖子

从getType()中排除属性.GetProperties()

嗨,我正在使用C#在类库中工作,我有一些带有一些属性的类.

我只想知道我是否可以添加一些内容来从getType().GetProperties()中排除一些属性.

我想要的一个例子:

课堂考试

{

class Test
{
    public string one { get; set; }
    public string two {get ; set;}
}
Run Code Online (Sandbox Code Playgroud)

}

如果我这样做:

static void Main(string [] args)

{

static void Main(string[] args)
{

       Test t = new Test();
       Type ty = t.GetType();
       PropertyInfo[] pinfo = ty.GetProperties();

       foreach (PropertyInfo p in pinfo)
       {
           Console.WriteLine(p.Name);
       }
  }
Run Code Online (Sandbox Code Playgroud)

}

我希望输出是这样的:

或者只是其中一个属性.

有可能做那样的事吗?我不知道C#中是否有某种修饰符或注释,这使我能够按照自己的意愿行事.

谢谢.

.net c# reflection

25
推荐指数
2
解决办法
2万
查看次数

标签 统计

.net ×1

c# ×1

reflection ×1