Print Page | Close Window

Property Names

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1543
Printed Date: 23-Apr-2024 at 4:30am


Topic: Property Names
Posted By: Waxman
Subject: Property Names
Date Posted: 04-Nov-2009 at 7:43am
I'm having some issues with property names during validation.  I've got an entity with a 'LastName' property that automatically gets a [Display(Name="Last Name", AutoGenerateField=true)] attribute, which is great.  My UI (Telerik) grid view automatically picks up on this attribute and displays the specified name when bound to the property.  I guess I'm surprised that the verification messages don't use this by default (it still just shows "LastName" by default).  Is there a reason?  Do I need to switch something on to allow this?
 
Next issue: I know the documentation shows the order in which it will try to determine the property name to display, so to try to overcome the first issue, I've set the engine's 'PropertyNameToDisplayNameTranslator' property to a custom method in which I try to discover the 'DisplayAttribute' mentioned above and use the Name value specified.  However, my method never gets called.  I have no idea why.  I set this property as soon as I create my entity manager and notice that this property is initially null.  When I get into one of my entities, its verifier engine still seems to have a valid reference to my method, but it doesn't seem to matter - it just never gets called.  Am I missing something?
 
Of course, I would love to just have it use the Display attribute by default, and if there is no current implementation to allow it, consider this my vote for a future feature.
 
Thanks,
Terry



Replies:
Posted By: GregD
Date Posted: 05-Nov-2009 at 4:22pm
Terry:

We actually already have a feature request for that (#1178), which was placed on hold for reasons I can't determine at the moment. In any event, it makes sense to me, too, so I've reopened that request so that the discussion of it will get reopened.

In the meantime, here's some code that shows how to wire up the PropertyNameToDisplayNameTranslator:

    private void InitializeVerifierEngine() {
      _entityManager.VerifierEngine.PropertyNameToDisplayNameTranslator =
        delegate(Type pType, String pPropertyName) {
           // the following will surround the PropertyName with brackets
           // in every single verifier result description
            return "[" + pPropertyName + "]";

          // the following is an example of how to change a specific property on a specific Entity
          //if ((pType == typeof(Employee)) && pPropertyName.Equals("HireDate")) {
          //  pPropertyName = "Emp Hire Date";
          //}
          //return pPropertyName;

        };
    }



Print Page | Close Window