CodeSmith Community
Your Code. Your Way. Faster!

Patch to use FriendlyName attributes

Latest post 03-10-2007 11:48 PM by kevlingo. 2 replies.
  • 03-09-2007 4:36 PM

    • kevlingo
    • Top 500 Contributor
    • Joined on 12-22-2006
    • Posts 12
    • Points 290

    Patch to use FriendlyName attributes

    Hello,

    I have made a few changes to the rules engine, namely:

    • ValidationRuleArgs has a new property called FriendlyName which can be used instead of PropertyName to display validation errors.
    • A new constructor has been added to ValidationRuleArgs (and all it's subclasses) to optionally accept a friendly name value. If one is not provided, the PropertyName will be used.
    • When the column Enum members are generated, the EnumTextValue attribute now uses the FriendlyName instead of the PropertyName value in the mapping file.

    When the Entity validation region is generated the following changes were made:

    • Currently, the templates provide rules for AllowNulls and Checking the length of a string and were created using the following convention:

    ValidationRules.Add(Validation.CommonRules.NotNull, "PropertyName");

    This has been changed to utilize the new FriendlyName field which it gets the value from the NetTiers mapping file. IE:

    ValidationRules.Add(Validation.CommonRules.NotNull, new ValidationRuleArgs("PropertyName", "Friendly Name"));

    • The CanCheckLength method was only returning true if the DataType of the column was StringFixedLength. It now returns true for this as well as if the DataType is String and if the column size doesn't equal -1 (VarChar(MAX)).
    • I've also added a new rule handler: SelectionRequired. The rule is generated if the column is a foriegn key member and nulls are not allowed. The handler will return false if the field value is either null or 0. Note:This fits a specific requirement in my project where new FK values are initialized to 0 if a dropdown list is used. Generating the rule on all entities may not be the best for everyone. Perhaps the rule handler can still be available, but the generated rule should be commented out?...

    Several files were modified in order to implement these changes, so I'm not exactly sure of the proper way to get those changes to the team members. I've attached a patch file in case it's useful.

    Hope the community finds this useful!

    Kevin

     

     

    • Post Points: 35
  • 03-10-2007 5:08 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Patch to use FriendlyName attributes

    Kevin,

    Thanks for the contribution (checked-in rev. 516). Great implementation.

    I've made a change though, hoping you don't mind. I've renamed the SelectionRequired handler to the ForeignKeyValueRequired, and since your logic handles foreignkeys that are numeric, i've put condition in place to check for the key datatype and render ForeignKeyValueRequired or StringRequired handlers.

     [edit] There seem to be already condition in place that performs AllowDBNull check if (! cols[x].AllowDBNull && IsCSReferenceDataType(cols[x]))  Your implementation remains, however the handler is removed

     Thanks again!

    [/edit]
     

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 03-10-2007 11:48 PM In reply to

    • kevlingo
    • Top 500 Contributor
    • Joined on 12-22-2006
    • Posts 12
    • Points 290

    Re: Patch to use FriendlyName attributes

    Looks great. Glad I could contribute something to the project!

    Kevin

    • Post Points: 5
Page 1 of 1 (3 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems