General property generation

Source: Internet
Author: User

This code is a helper class in the written jframework ,:-)
Very simple. Please enjoy it.

Source code:

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 _" + name [I] + "= value; \ r \ n ");
Block. append (prespace + "\ t} \ r \ n ");
Block. append (prespace + "} \ r \ n ");
Block. append (prespace + "\ r \ n ");
;
}
Return block. tostring ();
}
}
}

Reference Method:
/// <Summary>
/// Convert to a string array 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;
}

Test and reference example:
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 ();
}
}
}

The JFrameWork will be gradually available in the future.
JFrameWork in progress ........

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.