WXML starting up

by Alexey Shirshov September 21, 2009 21:03

Today I published new project on codeplex - WXML. In short it is a new xml format to define object models and their mapping to various sources (database, xml, etc). It is similar to edmx or dbml but has some differences

  • XInclude (any part of file can be brought out to external file)
  • Strong types
  • Open and flexible API
  • Differential updates

Feature list:

  • Generating from database
  • Generating SQL scripts from model
  • Generating LINQ to SQL context
  • Generating Worm classes

It combines simplicity (from dbml) and power (from edmx).

Lets compare three files which are define the same model.

WXML

edmx

dbml

And the files

As you can see edmx is very complex and bulky. Dbml is much simplier but has many annoying limitations (lack of xml documentation, m2m relations). WXML has all the features of edmx and brief as dbml.

Expressions has no IdentityEquality operator

by Alexey Shirshov September 19, 2009 19:17

Vb guys always wonder why c# has no identity equality operator like Is and IsNot. In many cases equality operator == make the job in c#. For instance

object d = "hello!";
bool isString = typeof(string) == d.GetType();

Here is the code in vb.net

Dim d As Object = "hello!"
Dim isString As Boolean = GetType(stringIs d.GetType()
'below is regular language construction
Dim isType As Boolean = GetType(stringIs d

The last statement will not work in c#. The only chance is to use ReferenceEquals method

object d = "hello!";
bool isType = ReferenceEquals(typeof(string), d);

So far so good. The bad news is expressions lack of identity equality operator. There is only one enumeration element in ExpressionType enum represents equality - ExpressionType.Equal. Even in CodeDom there are three: IdentityInequality, IdentityEquality and ValueEquality. So if you want to transform Expressions tree to CodeDom tree like I do, you have to think a lot.

In Expressions to CodeDom I create spesial CodeIdentityEqualityExpression class and CodeDom.Is method to simplify usage.

<TestMethod()> Public Sub TestIsOperator()
   Dim c = New CodeDomGenerator()
   c.AddNamespace("Samples").AddClass("cls") _
      .AddMethod(MemberAttributes.Public Or MemberAttributes.Static, Function() "foo", _
         Emit.declare("d1", Function() CodeDom.Is(String.Empty, GetType(String))), _
         Emit.declare("d2", Function() CodeDom.IsNot(String.Empty, GetType(String))) _
   )
   
   Console.WriteLine(c.GenerateCode(CodeDomGenerator.Language.CSharp))
   Console.WriteLine(c.GenerateCode(CodeDomGenerator.Language.VB))

   Dim ass = c.Compile()
   Assert.IsNotNull(ass)
   
   Dim TestClass As Type = ass.GetType("Samples.cls")
   Assert.IsNotNull(TestClass)
End Sub

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen | Modified by Mooglegiant

The Author

My name is Alexey Shirshov. I'm a professional developer with wide specialization. I prefer VB.NET to C#, I hate ASP.NET but there is no better than it. You can contact me by this page.