c# - Localizing StringLengthValidator does not get the right resource string -
i have following code in datacontract
following validation attributes field lastname:
[datamember] [required(errormessageresourcetype = typeof(patientdatacontractres), errormessageresourcename = "lastnamerequired")] [stringlengthvalidator(1, 50, errormessageresourcename = "lastnamelength" , errormessageresourcetype = typeof(patientdatacontractres))] public string lastname { get; set; }
the required attribute working fine when change culture while running application, stringlengthvalidator seems default resource string. app in english , french , stringlengthvalidator returns english text. both attributes use same resource. why working required
attribute?
i solved problem adding cultureinfo in constructor of propertyvalidatorcachekey , fixing propertyvalidationfactory use it
private struct propertyvalidatorcachekey : iequatable<propertyvalidatorcachekey> { private type sourcetype; private string propertyname; private string ruleset; private cultureinfo cultureinfo; public propertyvalidatorcachekey(type sourcetype, string propertyname, string ruleset, cultureinfo cultureinfo) { this.sourcetype = sourcetype; this.propertyname = propertyname; this.ruleset = ruleset; this.cultureinfo = cultureinfo; } public override int gethashcode() { return this.sourcetype.gethashcode() ^ this.propertyname.gethashcode() ^ (this.ruleset != null ? this.ruleset.gethashcode() : 0) ^ this.cultureinfo.gethashcode(); } #region iequatable<propertyvalidatorcachekey> members bool iequatable<propertyvalidatorcachekey>.equals(propertyvalidatorcachekey other) { return (this.sourcetype == other.sourcetype) && (this.propertyname.equals(other.propertyname)) && (this.ruleset == null ? other.ruleset == null : this.ruleset.equals(other.ruleset)) && (this.cultureinfo == other.cultureinfo); } }
Comments
Post a Comment