【问题标题】:Configuration section designer custom elements配置部分设计器自定义元素
【发布时间】:2014-06-05 02:10:07
【问题描述】:

我正在使用配置部分设计器 (CSD) 来管理我的 ASP.NET 站点服务,到目前为止我很喜欢它。我轻松地创建了部分、集合和集合项(仅限属性)。问题是如何在 jsonWebApiService 类型的字符串中创建“Json”元素。我想我可能需要创建一个自定义元素和转换器。不确定任何建议、链接或想法是否会有所帮助。 Tkanks。

问题是 查看架构https://drive.google.com/file/d/0B4oqlkkf0yHDMHo0M21PZzBZeEU/edit?usp=sharing

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <jsonWebApiSection xmlns="Web.JsonWebApi.Configuration">
        <services>
            <jsonWebApiService uniqueName="products" typeFullName="Company.Services.Products" typeAssembly="Services" route="/public/services/products.json">
                <json>{"Filter" :"OnSale"}</json>
            </jsonWebApiService>
        </services>
    </jsonWebApiSection>
</configuration>

【问题讨论】:

    标签: configuration config designer config-designer-csd


    【解决方案1】:

    您需要执行以下操作:

    1. 对于 JsonWebApiService 元素,将属性“具有自定义子元素”设置为“真”
    2. 您还需要在一个单独的 cs 文件中提供函数来解析该内部内容:

      public partial class JsonWebApiService : ConfigurationElement
      {
          private bool HandleUnrecognizedElement(string elementName, 
                  System.Xml.XmlReader reader)
          {
              /* parse your Json here */
              return true;
          }
      }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 2015-04-29
      • 1970-01-01
      • 2010-10-25
      • 2013-10-31
      • 2020-08-30
      相关资源
      最近更新 更多