Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 类型字符串的验证器?_.net_Configuration_Validation - Fatal编程技术网

.net 类型字符串的验证器?

.net 类型字符串的验证器?,.net,configuration,validation,.net,Configuration,Validation,有人知道是否已经有“类型”字符串的验证器吗 我希望确保自定义配置中的类型属性是以下属性之一: type="TopNamespace.SubNameSpace.ContainingClass, MyAssembly" type="TopNamespace.SubNameSpace.ContainingClass, MyAssembly, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089" type=“TopNames

有人知道是否已经有“类型”字符串的验证器吗

我希望确保自定义配置中的类型属性是以下属性之一:

type="TopNamespace.SubNameSpace.ContainingClass, MyAssembly" type="TopNamespace.SubNameSpace.ContainingClass, MyAssembly, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089" type=“TopNamespace.SubNameSpace.ContainingClass,MyAssembly” type=“TopNamespace.SubNameSpace.ContainingClass,MyAssembly,版本=1.3.0.0,区域性=中性,PublicKeyToken=b17a5c561934e089”
编写一个很容易,我只是不想重新发明轮子。

如果resharper的全局错误分析找不到名称空间或类,你会得到一个错误,但如果你引用插件,这并不总是有帮助的

可能最简单的事情是将代码放在try-catch块中加载应用程序域


如果dll在bin中,它将在启动时加载,但在您使用它之前它不会抛出错误,因此如果您刚刚创建ContainingClass的实例。您可以从配置中提取名称空间,然后尝试使用每个类。

我很确定框架中没有为此内置任何内容

有两个。它们中的任何一个都应该适用于您描述的场景。但是,请记住,它们都不会正确支持用于指定泛型类型的语法。为了正确处理这个问题,仅仅使用正则表达式是不够的——您需要针对泛型类型参数递归处理相同的正则表达式。例如,考虑以下类型名称:

List<>
"System.Collections.Generic.List`1"

List<string>
"System.Collections.Generic.List`1[[System.String]]"

Dictionary<string, string>
"System.Collections.Generic.Dictionary`2[[System.String],[System.String]]"

Dictionary<string, List<string>>
"System.Collections.Generic.Dictionary`2[[System.String],[System.Collections.Generic.List`1[[System.String]]]]"
列表
“System.Collections.Generic.List`1”
列表
“System.Collections.Generic.List`1[[System.String]]”
字典
System.Collections.Generic.Dictionary`2[[System.String],[System.String]]
字典
“System.Collections.Generic.Dictionary`2[[System.String],[System.Collections.Generic.List`1[[System.String]]””

有关更多信息,请参阅上的MSDN文档。

我不确定“自定义配置”是什么意思,但如果您仍在.NET的配置框架内工作(例如,开发自定义/),则只需键入as System.type(而不是字符串),NET将自动进行验证。

如果您正在编写自定义配置部分,Abraham Pinzur的建议是正确的


Type.GetType(…)
允许您手工操作。

您使用的是什么语言/环境?如果你把它添加到标签中,你可能会得到更好的答案。不要在意标签,把它放在标题中。加载类型很容易。我要做的是在我尝试之前检查配置中的字符串是否正常。为此编写验证器很容易。如果.NET somwhere中已经存在一个,我就不想这样做。我没有看到任何东西,但是它的正则表达式应该不会太难。