c# - How to trim class members? -


i have 2 classes like:

class customer {   string name;   string address;   string phone; }  class company {   string name;   string taxid; } 

if trim every class member 1 method, how on way?

for example:

customer.name = "aaa   " customer.address = "city1   " customer.phone = "   999   " 

i want remove space, like:

customer.name = "aaa" customer.address = "city1" customer.phone = "999" 

public static class stringhelper {     /// <summary>trim string properties of given object</summary>     public static tself trimstringproperties<tself>(this tself input)     {         if (input == null)             return input;          var stringproperties = typeof(tself).getproperties()             .where(p => p.propertytype == typeof(string));          foreach (var stringproperty in stringproperties)         {             string currentvalue = (string)stringproperty.getvalue(input, null);             if (currentvalue != null)                 stringproperty.setvalue(input, currentvalue.trim(), null);         }         return input;     } } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -