c# - Data class public properties to Dictionary -


I use the following code to convert the public properties of my class into a single dictionary:

  Public Stable Dictionary & lt; String, Object & gt; ClassPropsToDictionary & LT; T & gt; (ClassProps) {classProps.GetType () returned GetProperties (BindingFlags.Instance | BindingFlags.Public) .toDictionary (prop = & gt; prop.Name, prop = & gt; prop.getveralu (classProps, tap)). ; }  

This works fine, but I do not want to refer to the class reference:

  public class unit {public virtual string description {get; Set; } // Fine Public Virtual Employee Employee Employee {Received; Set; } // do not want it}  

What binding flag do I want to avoid from the employee's member?

Thanks

where with IsClass Use the property:

  classProps .GetType () .GetProperties (! BindingFlags.Instance | BindingFlags.Public). Where (x => x.PropertyType.IsClass) .ToDictionary (prop = & gt; prop.Name, prop = & gt; prop.getValue (classProps, tap));  

There is no binding flag for this. Most are relevant to the binding pumps access modifiers and heritage hierarchies. They can not be quoted to eliminate the value type or reference types. If you do not want to eliminate the underlying type like string , then declare an array, put all the types in it , Then contains :

  var allowed type = new [] {typeof (string), ...}; .Where (X => X.PropertyType.IsClass {allowedTypes.Contains (x.PropertyType))  

The built-in type of remains in the system < / Code> Namespaces can also be done in this easy way:

  .Where (! X => x.PropertyType.IsClass {x.PropertyType.AssemblyQualifiedName.StartsWith (" System "))  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -