System.Reflection GetProperties method not returning values

前端 未结 4 1161
情书的邮戳
情书的邮戳 2020-12-17 08:19

Can some one explain to me why the GetProperties method would not return public values if the class is setup as follows.

public class DocumentA
         


        
4条回答
  •  余生分开走
    2020-12-17 08:56

    Because the way you have declared your class now is using Fields. If you want to access the fields trough reflection you should use Type.GetFields() (see Types.GetFields Method1)

    I don't now which version of C# you're using but the property syntax has changed in C# 2 to the following:

    public class Foo
    {
      public string MyField;
      public string MyProperty {get;set;}
    }
    

    Wouldn't this help in reducing the amount of code?

提交回复
热议问题