Dynamic Data Localization Issue In .NET Framework 4.0

by hm 2. September 2011 13:18

The little pleasures of a developers life ...

RangeAttribute throws a run time error in SetUpValidator(RangeValidator1) when a decimal sign is included and the client language is German; most likely a localization issue in the .NET 4.0 Dynamic Data Framework

// [RangeAttribute(0.0d, 9.999d]

Workaround using RegularExpressionAttribute; the supplied regular expression only supports German decimal number notation; I would use a global resource like Resources.Resource.MyRegex but this is not allowed since it's static but not const; only workaround I know about: using the InMemoryMetadataManager I found on the web - very useful if "dynamic" attributes are required

[RegularExpression(@"^[0-9](\,[0-9]{1,4})?$"]
    public dynamic x {get; set; }

 

Final localized solution using InMemoryMetadataManager and my custom base class:

       

AddColumnAttributes(
           p => p.x,
           new RegularExpressionAttribute(Resource.FunctionCoordRegex)
              { ErrorMessage = Resource.InvalidFunctionCoordValue});

 

Method in generic base class:

static public void AddColumnAttributes(
          Expression<Func<T, object>> propertyAccessor,
          params Attribute[] attributes)
    {
        InMemoryMetadataManager.AddColumnAttributes<T>(propertyAccessor, attributes);
    }

 

Just a few snippets so feel free to ask ... ;)

Tags: , ,

Computers

About the author

Harald Mühlhoff, Dipl.-Inform.

Software Developer & Photographer

www.carecom.de
www.harald-muehlhoff.de

Facebook


Imprint / Impressum