c# - Get read/write properties of Anonymous Type -


I need to bring all the properties of an anonymous type that can be written.

Example:

  var person = new {name = "person's name", age = 25}; Type anonymous type = person.GetType (); Var Properties = Anonymous Type.GetProperties (BindingFlags.Public | BindingFlags.Instance);  

The problem is that all properties have their canwrite property false . It has come back as the right one for non-anonymous forms.
I tried to call PropertyInfo.GetSetMethod () , which returns null .
How can I check whether the property can be written?

Edit: Maybe it would be enough to know if some type is unknown or not, how will I know if some type is anonymous due to reflection?

There are anonymous types generated from C # always is immutable, so writeable The set of properties is empty This is optional in VB: Each property default to be unstable, but if you upgrade it with the key ; For the similarity and hash code generation only the declared property using the key count personally I like the approach of C #.

Can not return always returns in the form of truth for non-anonymous types - only read-only attributes for people who write For example, you can only write, or read, for example:

  test for the public class {// Cannreight will return false. CanRead will return true public int just to read ({get return 10;}} // will return right back to CanRead I CanRead will return false public int onlyonly {set {}} // canwrite right back to CanRead return true Will give public intradrad {get {return 10;} set {}}}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -