On Wed, Jun 27, 2012 at 6:19 PM, Don <don.lavelle.b
...@gmail.com> wrote:
> So after some digging, I found how to get the C# name of a type on
> stackoverflow<
http://stackoverflow.com/questions/4615553/c-sharp-get-user-friendly-...>using
> SparkViewDescriptor descriptor = new SparkViewDescriptor();
>> descriptor.SetLanguage(LanguageType.CSharp);
>> String typeName = new
>> Microsoft.CSharp.CSharpCodeProvider().GetTypeOutput(new
>> System.CodeDom.CodeTypeReference(typeof(RendererView)));
>> SparkSettings settings = new SparkSettings().SetPageBaseType(typeName);
> to get the proper name. It works for me. Would there be any issue if
> someone were to use my assembly with a VB project?
> Thanks,
> Don
> On Tuesday, June 26, 2012 1:15:04 PM UTC-4, Don wrote:
>> I'm trying to use Spark as a general rendering engine, similar to what is
>> done in this example<http://whereslou.com/2008/12/16/using-spark-as-a-general-purpose-temp...>.
>> However, I'd like to be able to use a nested class within a generic as the
>> base type, as in:
>> public class SparkEmailRenderer<DataType>
>>> {
>>> public class RendererView : AbstractSparkView
>>> {
>>> private Guid generatedViewId;
>>> public RendererView() { generatedViewId = Guid.NewGuid(); }
>>> public DataType Model { get; set; }
>>> public override Guid GeneratedViewId { get { return
>>> this.generatedViewId; } }
>>> public override void Render() { throw new NotImplementedException(); }
>>> }
>>> public SparkEmailRenderer(String templateString)
>>> {
>>> this.templateString = templateString;
>>> }
>>> public String Render(DataType data)
>>> {
>>> SparkSettings settings = new SparkSettings().**SetPageBaseType(typeof(**
>>> RendererView));
>>> InMemoryViewFolder templates = new InMemoryViewFolder();
>>> SparkViewEngine engine = new SparkViewEngine(settings) { ViewFolder =
>>> templates };
>>> templates.Add("renderer.spark"**, this.templateString);
>>> SparkViewDescriptor descriptor = new SparkViewDescriptor();
>>> descriptor.AddTemplate("**renderer.spark");
>>> RendererView view = (RendererView) engine.CreateInstance(**descriptor);
>>> // exception here
>>> view.Model = data;
>>> using (StringWriter stringWriter = new StringWriter())
>>> {
>>> view.RenderView(stringWriter);
>>> stringWriter.Flush();
>>> return stringWriter.ToString();
>>> }
>>> }
>> My very simple test case is this:
>> [TestMethod]
>>> public void TestMethod1()
>>> {
>>> SparkEmailRendererFactory<**Int32> factory = new
>>> SparkEmailRendererFactory<**Int32>();
>>> IEmailRenderer<SampleData> renderer = factory.BuildRenderer<**SampleData>(@"This
>>> is some string data: ${Model.StringData}.
>>> <for each='var tuple in Model.ListData'>
>>> - ${tuple.Item1} | ${tuple.Item2}
>>> </for>");
>>> SampleData sampleData = new SampleData
>>> {
>>> StringData = "!@#$%^&*()"
>>> , ListData = Enumerable.Range(1, 9).Select(i => new Tuple<Int32,
>>> Double>(i, i * 1.1)).ToList()
>>> };
>>> String result = renderer.Render(sampleData);
>>> Assert.AreEqual(result,@"This is some string data: !@#$%^&*().
>>> - 1 | 1.1
>>> - 2 | 2.2
>>> - 3 | 3.3
>>> - 4 | 4.4
>>> - 5 | 5.5
>>> - 6 | 6.6
>>> - 7 | 7.7
>>> - 8 | 8.8
>>> - 9 | 9.9");
>>> }
>> I keep getting a dynamic view compilation error on public class
>> View3d480988a882485c98ed589523**d9e8b4 : Full.Name.For.**
>> SparkEmailRenderer`1+**RendererView[[Full.Name.For.**SampleData,
>> Test.Assembly.Name, Version=2.0.2.0, Culture=neutral, PublicKeyToken=**
>> c5e39879b2509991]]
>> If I change the line about SparkSettings settings = new SparkSettings().*
>> *SetPageBaseType(typeof(**RendererView)); to just be the string literal
>> Full."Name.For.**SparkEmailRenderer.**RendererView<Full.Name.For.**SampleDa ta>",
>> it works, but that obviously won't work in the real world.
>> Any ideas on how to get that class name to render correctly? Do I have
>> to do it myself, or is there a way to get Spark to figure it out?
>> Thanks!
> --
> You received this message because you are subscribed to the Google Groups
> "Spark View Engine Dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/spark-dev/-/q7P-bi0hPIEJ.
> To post to this group, send email to spark-dev@googlegroups.com.
> To unsubscribe from this group, send email to
> spark-dev+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/spark-dev?hl=en.