<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Man vs Code : Jasper</title><link>http://blogs.msdn.com/aconrad/archive/tags/Jasper/default.aspx</link><description>Tags: Jasper</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Jasper and C#</title><link>http://blogs.msdn.com/aconrad/archive/2007/05/04/jasper-and-c.aspx</link><pubDate>Fri, 04 May 2007 21:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2413428</guid><dc:creator>aconrad</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/aconrad/comments/2413428.aspx</comments><wfw:commentRss>http://blogs.msdn.com/aconrad/commentrss.aspx?PostID=2413428</wfw:commentRss><description>&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question “&lt;A href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1546644&amp;amp;SiteID=1" mce_href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1546644&amp;amp;SiteID=1"&gt;Is Jasper useable from c#?&lt;/A&gt;” came up on the &lt;A href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1556&amp;amp;SiteID=1" mce_href="http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=1556&amp;amp;SiteID=1"&gt;Jasper forum&lt;/A&gt;. 
&lt;P&gt;The short answer is – We designed Jasper specifically for CLR languages with late-bound facilities such as VB and IronPython.&amp;nbsp; C# doesn’t currently support late-bound calls and hence the answer would be no though some aspects of Jasper may still be applicable. 
&lt;P&gt;The long answer is a lot more interesting. 
&lt;P&gt;Part of the Jasper framework's functionality provided by the Jasper framework is the&amp;nbsp;generation of&amp;nbsp;&amp;nbsp;the data classes (representing the underlying database tables and/ or entities) at runtime.&amp;nbsp; This relieves the developer the burden of writing the data classes themselves or&amp;nbsp;using design time code generation tools.&amp;nbsp; It also means no deployment cost for the data classes and even allows the database to be changed after the app has been deployed.&amp;nbsp; A whole lot of goodness for certain types of database apps that don’t want to pay the tax required by most O/R frameworks that exist today and enables a nice iterative, agile development experience. 
&lt;P&gt;Since these runtime generated data classes are clr types, one must use a CLR language that supports late binding or use reflection to access members of the data classes.&amp;nbsp;&amp;nbsp;&amp;nbsp;The latter is very painful and probably more work then actually writing the data classes themselves. 
&lt;P&gt;Therefor, Jasper works only&amp;nbsp;with CLR languages that support late binding.&amp;nbsp; And since we started working on Jasper when the &lt;A href="http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamic-language-runtime-dlr.aspx" mce_href="http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamic-language-runtime-dlr.aspx"&gt;DLR&lt;/A&gt; was white board talk, we decided to target Python 1.1 and VB 9 (Orcas versions) - the only CLR languages that supported late binding at the time. 
&lt;P&gt;That said, some aspects&amp;nbsp;of the Jasper API can be used from C#.&amp;nbsp; Let me give a little background of why that is the case by looking at how Jasper allows data class customization. 
&lt;P&gt;In Jasper, we wanted a way for users to add the own method/ properties/ fields/ events to the data class generated by Jasper.&amp;nbsp; To support this, we allowed the user to define a base class.&amp;nbsp; Then at type generation time, the Jasper runtime would search the app domain to see if a candidate base type exists to derive the new generated type from.&amp;nbsp; For example, the following type &lt;I&gt;Story&lt;/I&gt; would be used as the base type for the runtime generated Jasper data class based on the &lt;I&gt;Stories&lt;/I&gt; table: 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Class Story&lt;/FONT&gt; 
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp; ' Status is not a column in the Stories table&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Private _status As Boolean&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Function GetTitle(ByVal title As String) As String&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Truncate the title if it is too long&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If title.Length &amp;gt; 200 Then&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return title.Substring(0, 199)&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return title&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End Function&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public Function IsStoryActive() As Boolean&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return _status&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End Function&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End Class&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&lt;/FONT&gt;
&lt;P&gt;Note, the &lt;I&gt;GetTitle&lt;/I&gt; method is an example using the of the GetProperty/ SetProperty naming convention that we use to inject custom methods into the generated property Getter/ Setters.&amp;nbsp; For more information on this see the Project Jasper overview document included with the CTP release.&amp;nbsp; 
&lt;P&gt;The cool thing about using this base class technique is that the methods or properties in the base class can refer to properties that will be added to the generated derived class based on columns in the underlying database table at runtime. 
&lt;P&gt;To allow the user to specify as much (or as little) of the base class as they would like, &amp;nbsp;the Jasper runtime examines the candidate base type to see if any properties or fields are already are part of the base class.&amp;nbsp; If that is true, then the runtime does not generate those fields/ properties for the generated data class.&amp;nbsp; It is even possible to specify abstract properties and have the derived class generate the implementation, for example: 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public MustInherit Class Story&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public MustOverride Property Title() As String&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public MustOverride Property Description() As String&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Class&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT size=2&gt;So the interesting observation here is when the base class specifies the abstract properties, the properties can then be used in C# without requiring reflection:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; abstract public class Story&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abstract public string Title { get; set;}&amp;nbsp; &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abstract public string Description { get; set; }&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abstract public DateTime? PublishedDate { get; set; }&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // can now call&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var stories = myDynamicContext.GetQuery("Stories");&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Story myStory = stories[0]; //get first story&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;myStory.Title = "New Story Title";&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face="Lucida Console" size=2&gt;&lt;/FONT&gt;
&lt;P&gt;So it would be possible to call properties of the &lt;I&gt;Story&lt;/I&gt; instances as long as they were static declared on the Story base type.&amp;nbsp;&amp;nbsp; However, we are not particularly pleased with this design and experience.&amp;nbsp; The new C# feature of &lt;A href="http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx" mce_href="http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx"&gt;automatic properties&lt;/A&gt; may be a bit better and we are still evaluating its use in Jasper. 
&lt;P&gt;That all said, we are actively working on moving Jasper over to the &lt;A href="http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamic-language-runtime-dlr.aspx" mce_href="http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamic-language-runtime-dlr.aspx"&gt;dynamic language runtime&lt;/A&gt; - the freshly announced .Net addition to the runtime designed to extent the CLR for dynamic typed CLR languages (VBX, IronPython, IronRuby).&amp;nbsp; Based on early analysis it is a strong possibility that we move away from the base class mechanism and support a more dynamic model where data class types (or even specific instances!) can be modified at runtime to allow the user to add their own business logic. 
&lt;P&gt;The other consideration with respect to using Jasper in C# is that the autobinding components (AutoDataSource, AutoBinder) - see overview document for more information) included in the Jasper framework.&amp;nbsp; These do not require late binding and/ or a dynamic language to be utilized.&amp;nbsp; So, this part of the framework will function in C# as it does in the dynamic languages. &amp;nbsp;This is possible because the binding protocols are already work in a late bound manner and do not required design types unless on is using the design time support offered by the tools.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2413428" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/aconrad/archive/tags/Jasper/default.aspx">Jasper</category></item></channel></rss>