New Posts New Posts RSS Feed: Property Names
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Property Names

 Post Reply Post Reply
Author
Waxman View Drop Down
Newbie
Newbie
Avatar

Joined: 29-Oct-2009
Location: Ann Arbor, MI
Posts: 9
Post Options Post Options   Quote Waxman Quote  Post ReplyReply Direct Link To This Post Topic: Property Names
    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
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post 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;

        };
    }
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down