<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
tt
        {mso-style-priority:99;
        font-family:"Courier New";}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Thanks for replying – I did in fact already work this out. I
will put this in the docs or on the wiki somewhere.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Jim<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'>
<div>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> lars.vonwedel@bayertechnology.com
[mailto:lars.vonwedel@bayertechnology.com] <br>
<b>Sent:</b> Wednesday, October 07, 2009 11:55 PM<br>
<b>To:</b> Jim Idle<br>
<b>Cc:</b> stringtemplate-interest@antlr.org;
stringtemplate-interest-bounces@antlr.org<br>
<b>Subject:</b> Antwort: [stringtemplate-interest] Packaging C# StringTemplate
in an assembly<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Dear Jim,</span>
<br>
<br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>this is quite
easy to achieve using an "embedded ressource" for the template. Add
the file in VS to your project and select "Embedded Resource" as a
build option in the properties of the file.</span> <br>
<br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>In your code,
you can use something like this:</span> <br>
<br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
private StringTemplateGroup GetTemplateFromResource( string
resource )</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
{</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
StringTemplateGroup group = null;</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
Assembly assembly =
Assembly.GetExecutingAssembly();</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
Stream stream = assembly.GetManifestResourceStream(
resource );</span> <br>
<br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
if( stream != null )</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
{</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
var reader = new StreamReader( stream
);</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
group = new StringTemplateGroup(
reader );</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
}</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
// else: template not found !</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
return group;</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>
}</span> <br>
<br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>The resource
parameter is the fully qualified name of the embedded resource, e.g.
"Xyz.Template.stg" if Xyz is the standard namespace of the project
and Template.stg is the name of the template file. Be aware that you need to
recompile when changing the template.</span> <br>
<span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><br>
Freundliche Grüße / Best Regards<br>
Lars von Wedel<br>
_________________________________________<br>
<br>
Bayer Technology Services GmbH<br>
BTS-PT-PD-ES<br>
Leverkusen, E 41<br>
Phone: +49 214 30 56456<br>
Fax: +49 214 30 62677<br>
E-mail: lars.vonwedel@bayertechnology.com<br>
Web: www.bayertechnology.com<br>
<br>
Geschäftsführer: Achim Noack<br>
Aufsichtsratsvorsitzender: Dr. Wolfgang Plischke<br>
Sitz der Gesellschaft: Leverkusen | Eintragung: Amtsgericht Köln,
HRB 49896<br>
</span><br>
<br>
<o:p></o:p></p>
<table class=MsoNormalTable border=0 cellpadding=0 width="100%"
style='width:100.0%'>
<tr>
<td width="40%" valign=top style='width:40.0%;padding:.75pt .75pt .75pt .75pt'>
<p class=MsoNormal><b><span style='font-size:7.5pt;font-family:"Arial","sans-serif"'>"Jim
Idle" <jimi@temporal-wave.com></span></b><span style='font-size:
7.5pt;font-family:"Arial","sans-serif"'> </span><br>
<span style='font-size:7.5pt;font-family:"Arial","sans-serif"'>Gesendet von:
stringtemplate-interest-bounces@antlr.org</span> <o:p></o:p></p>
<p><span style='font-size:7.5pt;font-family:"Arial","sans-serif"'>07.10.2009
21:06</span> <o:p></o:p></p>
</td>
<td width="59%" valign=top style='width:59.0%;padding:.75pt .75pt .75pt .75pt'>
<table class=MsoNormalTable border=0 cellpadding=0 width="100%"
style='width:100.0%'>
<tr>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'>
<p class=MsoNormal align=right style='text-align:right'><span
style='font-size:7.5pt;font-family:"Arial","sans-serif"'>An</span><o:p></o:p></p>
</td>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'>
<p class=MsoNormal><span style='font-size:7.5pt;font-family:"Arial","sans-serif"'>"stringtemplate-interest@antlr.org"
<stringtemplate-interest@antlr.org></span> <o:p></o:p></p>
</td>
</tr>
<tr>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'>
<p class=MsoNormal align=right style='text-align:right'><span
style='font-size:7.5pt;font-family:"Arial","sans-serif"'>Kopie</span><o:p></o:p></p>
</td>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'></td>
</tr>
<tr>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'>
<p class=MsoNormal align=right style='text-align:right'><span
style='font-size:7.5pt;font-family:"Arial","sans-serif"'>Thema</span><o:p></o:p></p>
</td>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'>
<p class=MsoNormal><span style='font-size:7.5pt;font-family:"Arial","sans-serif"'>[stringtemplate-interest]
Packaging C# StringTemplate in an assembly</span><o:p></o:p></p>
</td>
</tr>
</table>
<p class=MsoNormal><o:p> </o:p></p>
<table class=MsoNormalTable border=0 cellpadding=0>
<tr>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'></td>
<td valign=top style='padding:.75pt .75pt .75pt .75pt'></td>
</tr>
</table>
</td>
</tr>
</table>
<p class=MsoNormal style='margin-bottom:12.0pt'><br>
<br>
<br>
<span style='font-family:"Calibri","sans-serif"'>So I can’t find any example
(maybe I am blind) of how to add a .stg file into my C# project so that it goes
in to the assembly and can be loaded at runtime. Anyone got an example of
loading from the .Net assembly?</span> <br>
<span style='font-family:"Calibri","sans-serif"'> </span> <br>
<span style='font-family:"Calibri","sans-serif"'>Cheers,</span> <br>
<span style='font-family:"Calibri","sans-serif"'> </span> <br>
<span style='font-family:"Calibri","sans-serif"'>Jim</span><tt><span
style='font-size:10.0pt'>_______________________________________________</span></tt><span
style='font-size:10.0pt;font-family:"Courier New"'><br>
<tt>stringtemplate-interest mailing list</tt><br>
<tt>stringtemplate-interest@antlr.org</tt><br>
<tt>http://www.antlr.org/mailman/listinfo/stringtemplate-interest</tt></span><o:p></o:p></p>
</div>
</div>
</body>
</html>