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进行中.... ....

  • 相关阅读:
    Mac OS X从10.7升级到Mountain Lion OS X10.8
    IOS UIView,UIViewController
    ObjectiveC Content list
    Sharepoint 系统管理
    iOS UIViewController use
    WIN10关机常用的三种方法
    svn check build
    ubuntu下搭建android开发环境
    BitmapFactory.Options避免 内存溢出 OutOfMemoryError的优化方法
    ubuntu update source with proxy
  • 原文地址:https://www.cnblogs.com/bigmouthz/p/332943.html
Copyright © 2011-2022 走看看