Looking for best practice to format/convert properties with private backing fields

Looking for best practice to format/convert properties with private backing fields

Old forum URL: forums.lhotka.net/forums/t/9097.aspx

j055 posted on Thursday, June 17, 2010


I'm often unsure where the best place is to format my properties for the UI in my BO. For example I have the following:

        private static readonly PropertyInfo<bool> IsActiveProperty = RegisterProperty<bool>(o => o.IsActive);

        private bool _IsActive = IsActiveProperty.DefaultValue;

        public string IsActive
                var value = GetProperty(IsActiveProperty, _IsActive);
                return value ? Resources.Yes : Resources.No;

Basically my question is - is this best practice? The good thing is I can use the _IsActive bool internally if I need to. An alternative is to convert in the data access method but that doesn't seem like best practice to me.

Any thoughts or suggestions appreciated.


triplea replied on Thursday, June 17, 2010

What about the way the samples handle conversion of SmartDate<->String:

private static PropertyInfo<SmartDate> StartedProperty = RegisterProperty<SmartDate>(p=>p.Started);

public string Started
      get { return GetPropertyConvert<SmartDate, string>(StartedProperty); }
      set { SetPropertyConvert<SmartDate, string>(StartedProperty, value); }

Not sure from the top of my head but I am sure you can make a small tweak to convert from String<-->Bool, that would be a lot cleaner...

JonnyBee replied on Wednesday, June 23, 2010


Just be aware that you may also need to add a TypeConverter and modify Utilities.CoeceValue method to handle conversion and set the Value property of a SmartBoolean if you choose to go down that path.

ajj3085 replied on Sunday, June 20, 2010

Is there any particular reason you're exposing a boolean as a string?  Normally I'd expect you'd bind to a checkbox or similar control.  If you need to allow editing as a string though, as triplea said you'd want something like a SmartBoolean.

Copyright (c) Marimer LLC