2011-04-12 178 views
2

我想在我的定制配置部分中使用枚举。所以我实现了一个枚举DatabaseMode和相应的属性。定制配置部分中的Enum IntellisSense

我还在我的System.Configuration.ConfigurationElement中实施了相应的Property。但是为了使IntelliSense在web.config中工作,我需要提供以xsd格式镜像相同结构的模式定义(xsd)。

我的问题是模式应该如何支持枚举?

不同的选项枚举:

public enum DatabaseMode 
{ 
    Development, 
    Deployment, 
    Production 
} 

属性存储有关模式的信息:

[ConfigurationProperty(databaseAlias)] 
public DatabaseElement Database 
{ 
    get { return (DatabaseElement)this[databaseAlias]; } 
    set { this[databaseAlias] = value; } 
} 

下面我schema文件的重要组成部分:

<xs:element name="database"> 
    <xs:complexType> 
    <xs:attribute name="server" type="xs:anyURI" use="required" /> 
    <xs:attribute name="name" type="xs:string" use="required" /> 
    <xs:attribute name="user" type="xs:string" use="required" /> 
    <xs:attribute name="password" type="xs:string" use="required" /> 
    </xs:complexType> 
</xs:element> 

回答

1

你实际上可以在XSD中定义一个枚举。对于您的示例DatabaseMode属性,XSD片段将如下所示:

<xs:attribute name="databaseMode"> <!-- I'm assuming you're using camelCasing --> 
    <xs:simpleType> 
     <xs:restriction base="xs:string"> 
      <xs:enumeration value="development" /> 
      <xs:enumeration value="deployment" /> 
      <xs:enumeration value="production" /> 
     </xs:restriction> 
    </xs:simpleType> 
</xs:attribute> 

希望有所帮助。

如果有其他人想要回答的问题是,一旦创建了XSD,应该在什么位置放置它,以便Visual Studio在web.config文件中识别它?

更新:我在SO上找到了我上面问题here的答案。

相关问题