CODECUBE VENTURES

CodeSmith Rocks

Don't know how I missed this before, but I started playing with CodeSmith Studio a few days ago. It's amazing! read on to see a small sample of what it can do.

I needed a dropdown list of disk drives (a: - z:). I figured this would be a good chance to flex my code template muscles (after having worked on another template for something else for a few hours).

<%@ CodeTemplate Language="C#" TargetLanguage="Text" Description="Generate a dropdownlist of drives" %>
<%@ Property Name="Drives" Type="CodeSmith.CustomProperties.StringCollection" Description="List of Drives" %>
<%@ Assembly Name="CodeSmith.CustomProperties" %>
<% foreach(string d in this.Drives) {%>
<asp:ListItem value="<%= d %>"><%= d %></asp:ListItem>
<%}%>

Once you compile that, just put this into the string collection editor

a:
b:
c:
d:
e:
f:
g:
h:
i:
j:
k:
l:
m:
n:
o:
p:
q:
r:
s:
t:
u:
v:
w:
x:
y:
z:

The result is

<asp:ListItem value="a:">a:</asp:ListItem>
<asp:ListItem value="b:">b:</asp:ListItem>
<asp:ListItem value="c:">c:</asp:ListItem>
<asp:ListItem value="d:">d:</asp:ListItem>
<asp:ListItem value="e:">e:</asp:ListItem>
<asp:ListItem value="f:">f:</asp:ListItem>
<asp:ListItem value="g:">g:</asp:ListItem>
<asp:ListItem value="h:">h:</asp:ListItem>
<asp:ListItem value="i:">i:</asp:ListItem>
<asp:ListItem value="j:">j:</asp:ListItem>
<asp:ListItem value="k:">k:</asp:ListItem>
<asp:ListItem value="l:">l:</asp:ListItem>
<asp:ListItem value="m:">m:</asp:ListItem>
<asp:ListItem value="n:">n:</asp:ListItem>
<asp:ListItem value="o:">o:</asp:ListItem>
<asp:ListItem value="p:">p:</asp:ListItem>
<asp:ListItem value="q:">q:</asp:ListItem>
<asp:ListItem value="r:">r:</asp:ListItem>
<asp:ListItem value="s:">s:</asp:ListItem>
<asp:ListItem value="t:">t:</asp:ListItem>
<asp:ListItem value="u:">u:</asp:ListItem>
<asp:ListItem value="v:">v:</asp:ListItem>
<asp:ListItem value="w:">w:</asp:ListItem>
<asp:ListItem value="x:">x:</asp:ListItem>
<asp:ListItem value="y:">y:</asp:ListItem>
<asp:ListItem value="z:">z:</asp:ListItem>

Easy as pie :-) Of worthy note is Leon Bambrick's "World's 2nd Simplest Code Generator"

Latest post: Digging Up the First Version of CodeCube

See more in the archives