I am trying to make a simple string extension that assigns the changes to the original string (like toUpper).In this case, the method is assigning the contents to a second argument if it is neither white space nor null...otherwise, it leaves the current value in place, or assigns a null value to "". So, I would like to have it go:
somerecord.Property1.func(someobj.property);
somerecord.Property2.func(someobj.otherproperty);
somerecord.Property3.func(someobj.anotherproperty);
while my code looks like
public static string func(this String str, string replacement)
{
if (!String.IsNullOrWhiteSpace(replacement)) {
str = replacement;
return replacement;
}
else
{
if(str == null)
str = "";
return "";
}
}
I wanted to set this
to ref
but I can't. Any ideas on how to implement this cleanly?