As for your concern with calling ParseName
4 times, I'm not sure I understand why - it looks like a case of ayour want-to-be-helpfulupdated frameworkcode is actually making a simple task rather complicated. Again I don't know and have never usedwhat doing that with reactive, and it's probably supersystem.reactive might look like -useful otherwise although again, but it to me it looksI've never used that namespace before.
public MainViewModel()
{
this.WhenAnyValue(x => x.Full).Where(x => x != null).Select(x => ParseName(x))
.ToProperty(this, x => x.NameObject, out __oapName);
}
Seems legit. It might read a little easier like your ViewModel is simply missing the forest for the treesthis though:
public NameMainViewModel()
{
Model { { getWhenAnyValue(name {=> returnname.Full).Where(name _name;=> }name set!= {null)
RaiseAndSetIfChanged .Select(refname _name,=> valueParseName(name);)
} .ToProperty(this, vm => vm.Name, out _name);
}
(ignore the name parsing bit!)
Your markup could bind itsWhy? It's a really interesting LastName
boxbit of code!
You're populating these arrays every time you call the function, but you shouldn't have to:
// Might want to add more to this list
string[] prefixes = { "mr", "mrs", "ms", "dr", "miss", "sir", "madam", "mayor", "president" };
// Might want to add more to this list, or use code/regex for roman-numeral detection
string[] suffixes = { "jr", "sr", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x", "xi", "xii", "xiii", "xiv", "xv" };
Make them Model.LastNameprivate static IReadOnlyList<string>
fields, and so onthat will create them only once for the type instead of per call. But I might be missing something
Then, I'd try to extract a private method for each member I'm trying to parse out of that string, to up the abstraction level a bit.