数据成员验证-ISO 4217(货币)和639-1(语言) [英] Data Member Validation - ISO 4217 (currency) and 639-1 (language)

查看:154
本文介绍了数据成员验证-ISO 4217(货币)和639-1(语言)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我希望对当前正在工作的.NET项目中的某些模型进行一些自定义的数据字段验证.

这些涉及默认语言和默认货币.为了满足此应用程序以及所涉及的各种其他应用程序和服务的标准,货币必须是ISO 4217(3个字符的货币)标准,语言必须是ISO 639-1(2个字符的语言)./p>

由于目前尚未针对此任何地方进行任何模型验证,因此我很高兴进行设置,在开始制作一些大型自定义数据验证器之前,我想知道是否有人知道任何现成的提供这些标准的库,即使它类似于检查可以自己插入Data Validator的字符串之类的东西.

任何建议和/或建议将不胜感激.

解决方案

好的,所以我找到了一个可行的解决方案.有点不雅致,但是有效.

可以在System.Globalization命名空间的RegionInfo对象上的TwoLetterISORegionName属性中找到ISO 639-1(2个字符的语言)代码.

可以在同一对象的ISOCurrenySymbol属性上找到ISO 4217(3个字符的货币)代码.

要创建区域信息,请使用:

new RegionInfo(Int32)

其中int是区域性标识符

要生成区域性标识符列表,使用起来非常简单

System.Globalization.CultureInfo.GetCultures(CULTURETYPE)

其中CULTURETYPE是各种文化类型的枚举或相应的数字(请务必选择不包含中性文化的文化,因为它们不会正确映射).这将返回一个CultureInfo对象数组,每个对象都包含一个LCID属性.此属性可用于构造各自的RegionInfo,您可以从那里获取所需的内容.

So, I am looking to do some custom Data Field Validation on some models in the .NET project I am currently working on.

These involve a Default Language and a Default Currency. In order to meet the standards of this application and the various other applications and services involved, the currency needs to be a ISO 4217 (3 character currency) standard and the language needs to be a ISO 639-1 (2 character language).

Seeing as no model validation is being done for this anywhere yet, I have the joy of setting it up and before I go about making some huge custom data validator, I was wondering if anyone knew of any existing libraries that readily provide these standards, even if it's something like checking a string that I can plug into a Data Validator myself.

Any advice and/or recommendations would be greatly appreciated.

解决方案

Okay so I found a workable solution to this. It's a little inelegant but it works.

The ISO 639-1 (2 character language) code can be found as the TwoLetterISORegionName property on the RegionInfo object in the System.Globalization namespace.

The ISO 4217 (3 character currency) code can be found on the ISOCurrenySymbol property on the same object.

To create a region info, use:

new RegionInfo(Int32)

where the int is the culture identifier

To Generate a list of culture identifiers it is quite simple to use

System.Globalization.CultureInfo.GetCultures(CULTURETYPE)

where CULTURETYPE is either the enum or respective number for various culture types (just be sure to choose one that doesn't contain neutral cultures as these do not map correctly). This returns an array of CultureInfo objects, each of which contains an LCID property. This property can be used to construct the respective RegionInfo and you can take what you need from there.

这篇关于数据成员验证-ISO 4217(货币)和639-1(语言)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆