zoukankan      html  css  js  c++  java
  • xml、Json生成cs代码文件

    一:xml生成cs实体类

    1、开始菜单》Visual Studio 2015》 Visual Studio Tools》VS2015 开发人员命令提示

    2、xsd xmlFileName.xml

    3、xsd xmlFileName.xsd /classes

     

    二、Json生成C#实体类代码:

    1、http://tool.sufeinet.com/Creater/JsonClassGenerator.aspx

    2、http://www.jsons.cn/jsontomodel/

    3、http://tool.chinaz.com/Tools/json2entity.aspx

    4、将下面的html存为文件打开

    <html><head><title>json生成c#类</title><link rel="stylesheet" href="http://js.chahuo.com/prettify/prettify.css"><script language="javascript" type="text/javascript" src="http://js.chahuo.com/prettify/prettify.js"></script><script type="text/javascript" src="http://tool.oschina.net/js/jsbeautify.js"></script></head><body>
        
        <h1>json生成C#类小工具</h1>
        <h5>JSON 字符串</h5>
        <div>
            <textarea style="600px;height:300px;margin-bottom:5px;" id="jsonStr"></textarea>
            <br>
            <button onclick="document.getElementById('jsonStr').value='';document.getElementById('class').innerHTML=''">清除</button>
            <button onclick="do_js_beautify()">格式化代码</button>
            <button onclick="startGen()">生成C#类</button>
        </div>
    
        <h5>C#类代码 <button onclick="selectCode()">选中代码</button></h5>
        
        <pre class="prettyprint" id="class" style="border:1px solid #ccc; padding:10px; 800px;"> 
                
        </pre>
        
        <script>
        
            String.prototype.format = function(){
                var args = arguments;
                return this.replace(/{(d+)}/g,                
                    function(m,i){
                        return args[i];
                });
            }
            
            String.prototype.trim=function(){
                 return this.replace(/(^s*)|(s*$)/g,"");
            }
            
            JSON2CSharp={
                _allClass:[],
                _genClassCode:function(obj,name){
                    var clas="public class {0}
    {
    ".format(name || "Root");
                    for(var n in obj){
                        var v = obj[n];
                        n = n.trim();
                        clas += "    {0}    public {1} {2} { get; set; }
    
    ".format(this._genComment(v),this._genTypeByProp(n,v),n);
                    }
                    clas += "}
    
    ";
                    this._allClass.push(clas);
                    return this._allClass.join("
    
    ");
                },
                _genTypeByProp:function(name,val){
                    switch(Object.prototype.toString.apply(val)){
                        case "[object Number]" :{
                            return val.toString().indexOf(".") > -1 ? "double" : "int";
                        }
                        case "[object Date]":{
                            return "DateTime";
                        }
                        case "[object Object]":{
                                                    name =  name.substring(0,1).toUpperCase() + name.substring(1);
                            this._genClassCode(val,name);
                            return name;
                        }
                        case "[object Array]":{
                            return "List<{0}>".format(this._genTypeByProp(name+"Item",val[0]));
                        }
                        default:{
                            return "string";
                        }
                    }   
                },
                _genComment:function(val){
                    var commm= typeof(val) == "string" && /.*[u4e00-u9fa5]+.*$/.test(val) ? val : "" ;
                    return "/// <summary>
        /// "+commm+ "
        /// </summary>
    ";
                },
                convert:function(jsonObj){
                    this._allClass=[];
                    return this._genClassCode(jsonObj);
                }
            }
            
            
            
            function do_js_beautify() {
                var js_source =document.getElementById("jsonStr").value.replace(/^s+/, '');
                if(js_source.length==0)                return;
                tabchar = ' ';
                var fjs = js_beautify(js_source);
                document.getElementById("jsonStr").value=fjs;
            }
    
            
            function startGen(){
                try{
                    var v = eval("("+document.getElementById("jsonStr").value+")");
                    document.getElementById("class").className ="prettyprint";
                    document.getElementById("class").innerHTML=JSON2CSharp.convert(v);
                    prettyPrint();  
                    document.getElementById("jsonStr").focus();
                }catch(e){
                    alert(e.message);
                }
            }
            
            function selectCode() {
                if (document.selection) {
                    var range = document.body.createTextRange();
                    range.moveToElementText(document.getElementById('class'));
                    range.select();
                } else if (window.getSelection) {
                    var range = document.createRange();
                    range.selectNode(document.getElementById('class'));
                    window.getSelection().addRange(range);
                }
            }
        </script></body></html>
    

      

    xml生成C#代码文件、xml生成C#实体类代码文件、Json生成C#代码文件、Json生成C#实体类代码文件

  • 相关阅读:
    python 计算 父亲节
    python 计算 母亲节
    python 计算 感恩节
    《AINLP年度阅读收藏清单》,2020-01-01,52nlp
    《命名实体识别 NER 论文综述:那些年,我们一起追过的却仍未知道的花名 (一)》,2020-05,龚俊民(昵称: 除夕)
    《How to Automate Manual Steps after SSH》2019-03,amitness
    《Back Translation for Text Augmentation with Google Sheets》,2020-02,amitness
    《BERT 的优秀变体:ALBERT 论文图解介绍》2020-05,作者:amitness,译者:ronghuaiyang
    《NLP中数据增强的综述,快速的生成大量的训练数据》2020-05,作者:amitness ,编译:ronghuaiyang
    《努力成为优秀的工程师》李航,2013-03
  • 原文地址:https://www.cnblogs.com/linmilove/p/8175993.html
Copyright © 2011-2022 走看看