2

我想像这样在 sectiongroup 中有多个部分

 **<CredentialsGroup>
        <Credentials>

          <company name="Carolina" userid="abc" password="dd"></company>
          <file name="dfbf0f94-767e-4c71-b4ee-2dc05fb76e3c.csv" 
      url="https://e.brightree.net/Home/file.csv"></file>

         <company name="Asbury" userid="abc" password="dde"></company>
          <file name="dfbf0f94-767e-4c71-b4ee-2dc05fb76e3c.csv"
      url="https://e.brightree.net/Home/file.csv"></file>
        </Credentials>
    </CredentialsGroup>**

这是我的自定义配置文件

**public class CredentialsSection: ConfigurationSection
    {
        [ConfigurationProperty("company",IsRequired=true)]

        public CompanyElement Company
        {
            get {

                return (CompanyElement)this["company"];            
            }

            set
            {
                this["company"] = value;
            }

        }


        [ConfigurationProperty("file",IsRequired=true)]

        public FileElement File
        {
            get
            {

                return (FileElement)this["file"];
            }

            set
            {
                this["file"] = value;
            }

        }


    }

   public class CompanyElement : ConfigurationElement
    { 
    [ConfigurationProperty("name",IsRequired=true)]

    public string Name
    {
        get {

            return (string)this["name"];
        }

        set
        {
            this["name"] = value;
        }

    }

    [ConfigurationProperty("userid", IsRequired = true)]

    public string UserId
    {
        get
        {

            return (string)this["userid"];
        }

        set
        {
            this["userid"] = value;
        }

    }

    [ConfigurationProperty("password", IsRequired = true)]

    public string Password
    {
        get
        {

            return (string)this["password"];
        }

        set
        {
            this["password"] = value;
        }

    }


    }

 public   class FileElement : ConfigurationElement
    {

        [ConfigurationProperty("name", IsRequired = true)]

        public string Name
        {
            get
            {

                return (string)this["name"];
            }

            set
            {
                this["name"] = value;
            }

        }

        [ConfigurationProperty("url",IsRequired=true)]

    public string Url
    {
    get
    {
    return (string)this["url"];
    }
        set {
            this["url"] = value;

        }

    }


    }**

公司和文件节点应该是兄弟节点,它们的选择将取决于公司名称,如下所示

ConfigurationManager.GetSection("CredentialsGroup/Credentials/company['name']=" + companyName); 请帮忙

4

0 回答 0