[stringtemplate-interest] Antwort: Packaging C# StringTemplate in an assembly
Jim Idle
jimi at temporal-wave.com
Fri Oct 9 06:52:03 PDT 2009
Thanks for replying - I did in fact already work this out. I will put this in the docs or on the wiki somewhere.
Jim
From: lars.vonwedel at bayertechnology.com [mailto:lars.vonwedel at bayertechnology.com]
Sent: Wednesday, October 07, 2009 11:55 PM
To: Jim Idle
Cc: stringtemplate-interest at antlr.org; stringtemplate-interest-bounces at antlr.org
Subject: Antwort: [stringtemplate-interest] Packaging C# StringTemplate in an assembly
Dear Jim,
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.
In your code, you can use something like this:
private StringTemplateGroup GetTemplateFromResource( string resource )
{
StringTemplateGroup group = null;
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream( resource );
if( stream != null )
{
var reader = new StreamReader( stream );
group = new StringTemplateGroup( reader );
}
// else: template not found !
return group;
}
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.
Freundliche Grüße / Best Regards
Lars von Wedel
_________________________________________
Bayer Technology Services GmbH
BTS-PT-PD-ES
Leverkusen, E 41
Phone: +49 214 30 56456
Fax: +49 214 30 62677
E-mail: lars.vonwedel at bayertechnology.com
Web: www.bayertechnology.com
Geschäftsführer: Achim Noack
Aufsichtsratsvorsitzender: Dr. Wolfgang Plischke
Sitz der Gesellschaft: Leverkusen | Eintragung: Amtsgericht Köln, HRB 49896
"Jim Idle" <jimi at temporal-wave.com>
Gesendet von: stringtemplate-interest-bounces at antlr.org
07.10.2009 21:06
An
"stringtemplate-interest at antlr.org" <stringtemplate-interest at antlr.org>
Kopie
Thema
[stringtemplate-interest] Packaging C# StringTemplate in an assembly
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?
Cheers,
Jim_______________________________________________
stringtemplate-interest mailing list
stringtemplate-interest at antlr.org
http://www.antlr.org/mailman/listinfo/stringtemplate-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20091009/904d7ac5/attachment-0001.html
More information about the stringtemplate-interest
mailing list