[英]Pascal case class names when generating code with Visual Studio xsd.exe
Title pretty much says it all. 标题几乎说明了一切。 VS xsd.exe creates classes in camel case.
VS xsd.exe以驼峰大小写创建类。 Is there a way of generating the classes in pascal case?
有没有办法在pascal情况下生成类?
If not does anyone know of a good tool to convert a load of class names from camel case to pascal case. 如果没有,有人知道一个很好的工具,可以将类名称从驼峰案例转换为pascal案例。
Thanks 谢谢
EDIT: 编辑:
xsd.exe doesn't generate class names in camel case as standard - it just follows the convention of the schema - however, I am interested in overriding this behaviour so the XmlElement name attribute will still follow the conventions defined by the schema, but the class name is pascal case. xsd.exe不会在camel情况下生成类名作为标准 - 它只是遵循模式的约定 - 但是,我有兴趣重写此行为,因此XmlElement name属性仍将遵循模式定义的约定,但是类名是pascal case。
Check out XmlSchemaClassGenerator , an open source console application that includes PascalCasing among its features. 查看XmlSchemaClassGenerator ,这是一个包含PascalCasing功能的开源控制台应用程序。 (I found this after the 15-day trial of xsd2code expired.)
(我在xsd2code过期的15天试用期后发现了这个。)
- Map XML namespaces to C# namespaces, either explicitly or through a (configurable) function
将XML命名空间显式或通过(可配置)函数映射到C#命名空间
- Generate C# XML comments from schema annotations
从架构注释生成C#XML注释
- Generate DataAnnotations attributes from schema restrictions
从架构限制生成DataAnnotations属性
- Use
Collection<T>
properties (initialized in constructor and with private setter)使用
Collection<T>
属性(在构造函数和私有setter中初始化)- Use either int, long, decimal, or string for xs:integer and derived types
对xs:integer和派生类型使用int,long,decimal或string
- Automatic properties
自动属性
- Pascal case for classes and properties
类和属性的Pascal案例
- Generate nullable adapter properties for optional elements and attributes without default values (see below)
为没有默认值的可选元素和属性生成可空的适配器属性(参见下文)
- Optional support for PCL
可选的PCL支持
- Optional support for
INotifyPropertyChanged
对
INotifyPropertyChanged
可选支持
In my case, before I could get the console app to work, I had to modify the xsd document to include a targetNamespace
field as follows: 在我的情况下,在我可以使控制台应用程序工作之前,我必须修改xsd文档以包含
targetNamespace
字段,如下所示:
Original: 原版的:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1">
Modified: 改性:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="gateway" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1">
My final usage looked something like this: 我的最终用法看起来像这样:
XmlSchemaClassGenerator.Console -n "http://www.w3.org/2001/XMLSchema=gateway" -o "C:\{output-folder}" {xsd-file-name}.xsd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.