zoukankan      html  css  js  c++  java
  • 一个配置文件的Mapping

    1. 需要Mapping的Xml结构

    <?xml version="1.0" encoding="utf-8"?>
    <Requestes>
    <Request name="RequestA" formname="LanguageUI" serviceurl="http://MyComputer/LanguageService" httpmethod="POST" targetui="Settings->LanuageSetting">
    <Reference name="ClassA">
    <Property name="DateFrom" type="DateTime?" />
    <Property name="DateTo" type="DateTime?" />
    </Reference>
    </Request>
    <Request name="RequestB" formname="ImageShowUI" serviceurl="http://MyComputer/ImageService" httpmethod="POST" targetui="Settings->Images">
    <Reference name="ClassB">
    <Property name="Top" type="int" />
    </Reference>
    </Request>
    </Requestes>

    2. Mapping到的类结构

     

    public class PropertyInfo
    {
    public string PropertyName
    {
    get;
    set;
    }
    public string PropertyType
    {
    get;
    set;
    }
    }
    public class DynamicEntity
    {
    public string Name
    {
    get;
    set;
    }
    public string ServiceURL
    {
    get;
    set;
    }
    public string TargetUI
    {
    get;
    set;
    }
    public List<PropertyInfo> SimplePropertyList { get; set; }
    public Dictionary<string, List<PropertyInfo>> CollectivePropertyList { get; set; }
    public List<RefenceInfo> RefenceList
    {
    get;
    set;
    }
    public string HttpMehtod
    {
    get;
    set;
    }
    public string FormName
    {
    get;
    set;
    }
    }
    public class RefenceInfo
    {
    public string Key
    {
    get;
    set;
    }
    public List<PropertyInfo> SimplePropertyList { get; set; }
    public Dictionary<string, List<PropertyInfo>> CollectivePropertyList { get; set; }
    public List<RefenceInfo> RefenceList { get; set; }
    }

     3. Mapping的方法

    public static List<DynamicEntity> Generate(string xmlPath, string formName)
    {
    XElement main
    = XElement.Load(xmlPath);

    return
    (from c
    in main.Elements("Request")
    where c.Attribute("formname").Value == formName
    select
    new DynamicEntity
    {
    Name
    = c.Attribute("name").Value,
    ServiceURL
    = c.Attribute("serviceurl").Value,
    TargetUI
    = c.Attribute("targetui").Value,
    HttpMehtod
    = c.Attribute("httpmethod").Value,
    FormName
    = c.Attribute("formname").Value,
    SimplePropertyList
    = c.Elements("Property").Where(p => p.Attribute("type").Value.Trim().ToLower() != "list").Select(p => new PropertyInfo { PropertyName = p.Attribute("name").Value, PropertyType = p.Attribute("type").Value }).ToList(),
    CollectivePropertyList
    = CollectivePropertyList(c.Elements("Property").Where(p => p.Attribute("type").Value.Trim().ToLower() == "list")),
    RefenceList
    = TopRefenceList(c.Elements("Reference"))
    }).ToList
    <DynamicEntity>();
    }
  • 相关阅读:
    vs code python 关于无法找到文件路径的问题 No such file or directory
    vs2017 c# 控制台 输出中文显示问号 ; vs2017 c# 控制台 输出中文显示乱码
    web页面实现指定区域打印功能
    html 实现动态在线预览word、excel、pdf等文件(方便快捷)
    vuetify使用时遇到的坑:默认颜色显示不了
    【VS Code】中node.js代码自动补全的方法
    vue-property-decorator使用指南
    关于webpack,babel,以及es6和commonJS之间的联系(转)
    tslint.json的配置项说明
    [TypeScript] vs code TSLint常见错误解决方案
  • 原文地址:https://www.cnblogs.com/mxy1028/p/2039136.html
Copyright © 2011-2022 走看看