zoukankan      html  css  js  c++  java
  • 常规属性生成

    本代码是在所写JFrameWork当中辅助的一个类,:-)
    很简单.请大家共赏

    源代码:

    using System;
    using System.Collections;
    using JFrameWork.Common;

    namespace JFrameWork.CodeBuilder
    {
     /// <summary>
     /// Description of Propety.
     /// </summary>
     public class Property
     {
      public Property()
      {
      }
      

      public static string GetPropertyBlock(string prespace, ArrayList name, ArrayList type)
      {
       return GetPropertyBlock(prespace,ArrayHelper.ToStringArray(name),ArrayHelper.ToStringArray(type));
      }
      
      public static string GetPropertyBlock(string prespace, string[] name, string[] type)
      {
       System.Text.StringBuilder block = new System.Text.StringBuilder();
       
       for(int i = 0; i < name.Length; i++)
       {
        // Gen:
        // private <TYPE> <_Property>;
              // public <TYPE> <Property>
              // {
              //  get
              // {
              //     return (<_Property>);
              //  }
              //  set
              // {
              //    <_Property> = value;
              //  }
              // }
              block.Append(prespace + " private " + type[i] + " _" + name[i] + ";\r\n");
              block.Append(prespace + " \r\n");
              block.Append(prespace + " public  " + type[i] + "  " + name[i] + "\r\n");
              block.Append(prespace + " {\r\n");
              block.Append(prespace + " \tget\r\n");
              block.Append(prespace + " \t{\r\n");
              block.Append(prespace + " \t\treturn  _" + name[i] + ";\r\n");
              block.Append(prespace + " \t}\r\n");
              block.Append(prespace + " \tset\r\n");
              block.Append(prespace + " \t{\r\n");
              block.Append(prespace + " \t\t_" + name[i] + " = value;\r\n");
              block.Append(prespace + " \t}\r\n");         
              block.Append(prespace + " }\r\n");
              block.Append(prespace + " \r\n");
              ;
       }
       return block.ToString();
      }
     }
    }

    引用方法:
      /// <summary>
      /// 转换为字符串数组ArrayHelper。ToStringArray
      /// </summary>
      /// <param name="coll"></param>
      /// <returns></returns>
      public static string[ ] ToStringArray( ICollection coll )
      {
       string[ ] result = new string[coll.Count];
       int i = 0;
       foreach( object obj in coll )
       {
        result[ i++ ] = obj.ToString();
       }
       return result;
      }

    测试以及引用示例:
    using System;
    using System.Collections;
    using JFrameWork.CodeBuilder;
    using JFrameWork.PubUtility.File;

    namespace JFrameWork.CodeBuilder.Test
    {
     class MainClass
     {
      public static void Main(string[] args)
      {
    //   string prespace = "\t";
    //   string[] name = {"ID","Name","Value"};
    //   string[] type = {"string","string","string"};
       
       ArrayList alname = new ArrayList();
       ArrayList altype = new ArrayList();   
       
       Console.WriteLine("Set Prespace:");
       string prespace = Console.ReadLine();
       string quit;
       do
       {
        Console.WriteLine("Set Name:");
        alname.Add(Console.ReadLine());
        Console.WriteLine("Set Prespace:");
        altype.Add(Console.ReadLine());
        Console.WriteLine("Go on?");
        quit = Console.ReadLine();
       }while (quit != "n" && quit != "N");
       string block  = Property.GetPropertyBlock(prespace, alname, altype);
       Console.WriteLine(block);
       FileManager.ToFile(System.Environment.CurrentDirectory + "/Temp.txt",block);
       //Console.ReadLine();
      }
     }
    }

    日后将对JFrameWork逐步部分进行开放。
    JFrameWork进行中.... ....

  • 相关阅读:
    Building Java Projects with Gradle
    Vert.x简介
    Spring及Spring Boot 国内快速开发框架
    dip vs di vs ioc
    Tools (StExBar vs Cmder)which can switch to command line window on context menu in windows OS
    SSO的定义、原理、组件及应用
    ModSecurity is an open source, cross-platform web application firewall (WAF) module.
    TDD中测试替身学习总结
    Spring事务银行转账示例
    台式机(华硕主板)前面板音频接口(耳机和麦克风)均无声的解决办法
  • 原文地址:https://www.cnblogs.com/bigmouthz/p/332943.html
Copyright © 2011-2022 走看看