dimanche 7 mai 2017

How to use reflection to handle all types?

I was trying to do many utility functions like this:

public bool HasMember(object obj, string name)
{
etc.
}

The name and meaning of this particular utility function is not relevant.

Unfortunately, the function above cannot handle all types, like DateTime or Decimal which are structs. It handles integers and custom objects well. I understand that c# have both structs and objects, and struct is not an object. But how can I handle all the types in my utility method? It is preferable that there is no overloaded methods, because there is so many utility functions needed.

Previous Research:

The language reference did not give me advice: http://ift.tt/2qfZzr4

Also no help with the text explaining the value types: http://ift.tt/2qRem8I





Aucun commentaire:

Enregistrer un commentaire