Skip to content

Instantly share code, notes, and snippets.

Created December 25, 2014 04:26
Show Gist options
  • Save anonymous/ef3aaa7fde9cd54d4f80 to your computer and use it in GitHub Desktop.
Save anonymous/ef3aaa7fde9cd54d4f80 to your computer and use it in GitHub Desktop.
clasShells();
<h1 align="center"><font color="red">codeShells();</font></h1>
<br/>
<div id="simple">
<label>Class name:</label><br/>
<input type="text" id="className" value="MyTestClass" size="50"/>
<br/></br>
<label>Property names:</label><br/>
<input type="text" value="TestProp1, TestProp2" size="50" id="properties"/>
<br/><br/>
<label>Method names:</label><br/>
<input type="text" value="TestMeth1,TestMeth2" size="50" id="methods"/>
<br/></br>
<input type="checkbox">Include constructors</input>
<br/></br>
<button id="btnGenerate">Test</button>
</div>
<br/><br/>
<div><textarea id="vbCode" rows="10" cols="50">
VB code displays here!
</textarea></div>
<div><textarea id="csCode" rows="10" cols="50">
C# code displays here!
</textarea></div>
var type;
var language;
$( document ).ready(function(){
var type = "simple";
var language = "c#";
});
$("#simple").on("click", function(){
ShowSimple();
});
$("#advanced").on("click", function(){
ShowAdvanced();
});
$("#btnGenerate").on("click", function(){
//Testing only. Remove later.
type = "simple";
language = "vb";
Generate(type, language);
})
function ShowSimple(){
}
function ShowAdvanced(){
}
function Generate(type){
switch(type)
{
case "simple":
GenSimple();
break;
case "advanced":
GenAdvanced();
break;
}
}
function GenSimple(){
//0. split method names at commas
var methods = $("#methods").val();
var methodList = new Array();
methods = methods.split(',');
//1. create a new MethodShell for each array "methods" elements
$.each(methods, function (count){
methods[count] = $.trim(methods[count]);
var mShell = new MethodShell();
mShell.MethodName = methods[count];
mShell.Arguments = {}; //ignore for GenSimple();
mShell.ReturnsValue = false; //ignore for GenSimple();
methodList.push(mShell);
})
//2. split property names at commas
var properties = $("#properties").val();
var propertyList = new Array();
properties = properties.split(',');
//3. create a new PropertyShell for each array "properties" elements
$.each(properties, function (count){
properties[count] = $.trim(properties[count]);
var pShell = new PropertyShell();
pShell.PropertyName = properties[count];
pShell.PropertyType = ""; //ignore for GenSimple();
pShell.IncludeGetter = false; //ignore for GenSimple();
pShell.IncludeSetter = false; //ignore for GenSimple();
propertyList.push(pShell);
})
//4. create a new ClassShell and assign it the values from methods/properties arrays
var cShell = new ClassShell();
cShell.ClassName = $("#className").val();
cShell.Methods = methodList;
cShell.Properties = propertyList;
if($("#incConstructor").is(':checked')){
cShell.IncludeConstructor = true;
} else {
cShell.IncludeConstructor = false;
}
DisplayVB(cShell);
DisplayCS(cShell);
}
function GenAdvanced(){
}
function ClassShell(){
this.ClassName = "";
this.Methods = {};
this.Properties = {};
this.IncludeConstructor = false;
}
function MethodShell(){
this.MethodName = "";
this.Arguments = {};
this.ReturnsValue = false;
}
function PropertyShell(){
this.PropertyName = "";
this.PropertyType = "";
this.IncludeGetter = false;
this.IncludeSetter = false;
}
function DisplayVB(_code){
//0. Class start
//1. Properties[] start ...
//2. Properties[] end
//3. Methods[] start ...
//4. Methods[] end
//5. Constructors[] start ...
//6. Constructors[] end
//7. Class end
var code = new ClassShell;
code = _code;
var shell = "Public Class " + code.ClassName + '\n' + '\n';
$.each(code.Properties, function(count){
shell = shell + " "; //indent3
shell = shell + "Private " + code.Properties[count].PropertyName + " As String" + '\n' + '\n';
shell = shell + " "; //indent3
shell = shell + "Public Property " + code.Properties[count].PropertyName + " As String " + '\n';
shell = shell + " "; //indent6
shell = shell + "Get" + '\n';
shell = shell + " "; //indent9
shell = shell + "Return " + code.Properties[count].PropertyName + '\n';
shell = shell + " "; //indent6
shell = shell + "End Get" + '\n';
shell = shell + " "; //indent6
shell = shell + "Set(ByVal Value As String)" + '\n';
shell = shell + " "; //indent9
shell = shell + code.Properties[count].PropertyName + " = Value" + '\n';
shell = shell + " "; //indent6
shell = shell + "End Set" + '\n';
shell = shell + " "; //indent3
shell = shell + "End Property " + '\n' + '\n';
})
$.each(code.Methods, function(count){
shell = shell + " "; //indent3
shell = shell + "Public Sub " + code.Methods[count].MethodName + "(ByVal Value As String) As String" + '\n' + '\n';
shell = shell + " "; //indent3
shell = shell + "End Sub " + '\n' + '\n';
})
if(code.IncludeConstructor == true){
shell = shell + " "; //indent3
shell = shell + "Public Sub New()" + '\n' + '\n';
shell = shell + " "; //indent3
shell = shell + "End Sub" + '\n' + '\n';
}
shell = shell + "End Class";
$("#vbCode").text(shell);
}
function DisplayCS(_code){
//0. Class start
//1. Properties[] start ...
//2. Properties[] end
//3. Methods[] start ...
//4. Methods[] end
//5. Constructors[] start ...
//6. Constructors[] end
//7. Class end
var code = new ClassShell;
code = _code;
var shell = "public class " + code.ClassName + '\n' + '{' + '\n';
$.each(code.Properties, function(count){
shell = shell + " "; //indent3
shell = shell + "public string " + code.Properties[count].PropertyName + " { get; set; }" + '\n';
});
$.each(code.Methods, function(count){
shell = shell + '\n' + " "; //indent3
shell = shell + "public void " + code.Methods[count].MethodName + '\n';
shell = shell + " "; //indent3
shell = shell + '{';
shell = shell + " " + '\n' + '\n'; //indent3
shell = shell + " "; //indent3
shell = shell + "}" + '\n';
});
if(code.IncludeConstructor == true){
shell = shell + '\n' + " "; //indent3
shell = shell + "public " + code.ClassName + "()" + '\n';
shell = shell + " "; //indent3
shell = shell + '{' + '\n';
shell = shell + '\n' + " "; //indent3
shell = shell + "}" + '\n';
}
shell = shell + '}';
$("#csCode").text(shell);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment