Friendly name property is not available in the broken rule we are using CSLA 3.7

Friendly name property is not available in the broken rule we are using CSLA 3.7

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


arigney posted on Wednesday, January 06, 2010

Hi Guys,

                   We would like to do this but the friendly name is not available in a brokenrule object.

private static string GetValidationMessage(BaseElement element)

{

if (element.IsValid)

return "The element has no validation errors.";

else

return string.Format("The {0} element has the following validation errors: {1}{2}",

((eElementType)element.Element_ElementTypePK).GetDescription(),

Environment.NewLine, GetValidationErrors(element.BrokenRulesCollection));

}

private static string GetValidationErrors(BrokenRulesCollection brokenRules)

{

StringBuilder builder = new StringBuilder();

brokenRules.ToList().ForEach(x => builder.AppendFormat("\t{0}: {1}{2}", x.Property, x.Description, Environment.NewLine));

// TODO next version of CSLA will probably give us access to the friendly name so we can do this

//brokenRules.ToList().ForEach(x => builder.AppendFormat("\t{0}: {1}{2}", x.FriendlyName, x.Description, Environment.NewLine));

// or this

//brokenRules.ToList().ForEach(x => builder.AppendFormat("\t{0}: {1}{2}", x.GetType().GetProperty("FriendlyName"), x.Description, Environment.NewLine));

// For now we have to use the property name as a friendly name.

return builder.ToString();

}


JonnyBee replied on Thursday, January 07, 2010

Hi,

I do not agree that FriendlyName should be included in BrokenRules. You can get it from PropertyInfoManager - using the businessObject and PropertyName.

ex:

      public string GetPropertyFriendlyName(object businessObject, string propertyName)
      {
          var propertyInfo = Csla.Core.FieldManager.PropertyInfoManager.GetRegisteredProperties(businessObject.GetType()).Where(p => p.Name == propertyName).FirstOrDefault();
          return propertyInfo != null ? propertyInfo.FriendlyName : propertyName;
      }


arigney replied on Thursday, January 07, 2010

Dear Johnny,

                     Thanks very much mate? But we are using CSLA cslacs-3.7.0-090710 and in that version PropertyInfoManager is an internal class. Maybe its available in another version?

Regards,

                Alistair

rxelizondo replied on Thursday, January 07, 2010

arigney:

But we are using CSLA cslacs-3.7.0-090710 and in that version PropertyInfoManager is an internal class.


Yeah, that got me too. Not sure why PropertyInfoManager does not expose that functionality.

Anyway, Jonny has answer this in other posts, the general idea is for you to create your own subclass of BussinesBase that implements the functionality you need. Once you have that you will inherit from that class.

You can use some code like the following:

internal string GetPropertyFriendlyName(string propertyName)
{
var propertyInfo = this.FieldManager.GetRegisteredProperties().Where(p => p.Name == propertyName).FirstOrDefault();
return propertyInfo != null ? propertyInfo.FriendlyName : propertyName;
}

arigney replied on Thursday, January 07, 2010

Awesome thanks Mate!

Kool so I guess I really need to ask what version of CSLA you recommend we use and is it much of a headache upgrading to that version. Maybe this has been "fixed" in a later release? Also with the version that you recommend, what other additions would you say that we need.

I guess we can pay you for any advice.We have been working on a big gov project here in Canberra Australia for the last year, we had to fight to get them to accept CSLA and the customer wouldn't let us use an ORM so we had to use our old dataset tools with CSLA as the ORM.

Best Regards,

                       Alistair

Copyright (c) Marimer LLC