C# - How to apply ToUpper() or other function to each member/property of a class.
I have a large number of classes where I need to force uppercase and filter out special characters for all the string members and properties.
I'm assuming reflection is the answer but I'm not sure how to implement it effectively.
So I'd like to have a utility class/function where I can pass a class object like the one below to it and have all strings converted to upper case.
For the class below, I'd expect these members/properties to have their values converted to uppercase after I make the one utility function call:
- FirstName
- LastName
- CompanyName
- WebUrl
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age;
private DateTime StartDate;
public string CompanyName;
private string WebUrl;
}
We will get a lot of reuse out of this function so is greatly appreciated.
0 comments:
Post a Comment