Sasha Sydoruk

Building a better mousetrap with XHTML, AJAX and RSS

Archive for November, 2006

Enterprise Library will have a new block – Validation Application Block

It looks like the new version of the Enterprise Library will have a new block – Validation Application Block. It will provide common validation rules that apply to primitive data types.

What a great idea, hopefully this would be as easy and nice as BO validation in RoR. One of my problems with ASP.NET validators is that they force you to put business logic into UI. And this leads to the duplication of the validation logic. Now you have to write your validation logic in your business object and in your UI. That is if you ever do… I have seen so many examples where people just put all their validation into UI and never replicate it on the BLL. Not cool… I like the Rails way better. You always start out by coding validation logic in your BO, and UI knows how to pick up all the validation errors and display them to the user.

From the post:

The Validation Application Block will include a comprehensive library of common validation rules that apply to primitive data types. For example, we’ll include rules like string length, numeric range, date range, regular expressions and so on. However your applications will typically deal with more complex objects such as Customers or Orders (yes, here at Microsoft we assume every application is based on Northwind ;-), so while the built-in Validators should be great building blocks, you’ll need to do some additional work to specify how these primitive rules apply to more complex objects. We plan on letting you do this in two primary ways: in configuration (which is ideal if you want the rules to be easily changed after deployment), or in code (which allows better encapsulation of rules and ensures the behavior won’t change unless the code does).

The complete post is here.

No comments

Fun with C#’s yield and Fibonnaci numbers

   1:  using System;
   2:  using System.Collections;
   3:   
   4:  namespace TestConsoleApplication
   5:  {
   6:      internal class Program
   7:      {
   8:          private static void Main(string[] args)
   9:          {
  10:              foreach (int x in GetFibonacciNumbers(20))
  11:              {
  12:                  Console.WriteLine(x);
  13:              }
  14:   
  15:              Console.ReadKey();
  16:          }
  17:   
  18:   
  19:          public static IEnumerable GetFibonacciNumbers(int n)
  20:          {
  21:              int p1 = 1;
  22:              int p2 = 0;
  23:   
  24:              yield return 0;
  25:              yield return 1;
  26:   
  27:              for (int i = 0; i < n; i++)
  28:              {
  29:                  int sum = p1 + p2;
  30:                  yield return sum;
  31:                  p2 = p1;
  32:                  p1 = sum;
  33:              }
  34:          }
  35:      }
  36:  }
No comments

IXmlSerializable and sgen.exe

If you really have to control your XmlSerialization - use IXmlSerializable.

I always knew that you can use xsd.exe to generate CS classes from XML schema, but I have never heard of sgen.exe.

From MSDN: The XML Serializer Generator(sgen.exe) creates an XML serialization assembly for types in a specified assembly in order to improve the startup performance of a XmlSerializer when it serializes or deserializes objects of the specified types.

Pretty awesome if you ask me.

No comments

70-536 – passed! My score – 92%

On November 19th, I took and passed 70-536 exam. The exam was not very difficult. Of course there were some questions that made me think for a while, but other than that the exam was quite good. The question breakdown from MSDN was quite accurate; so make sure that you pay good attention to security, data compression, file IO and serialization.

For my exam preparation I used the following materials:
1. The book
2. Transcender
3. A lot of hours reading MSDN. A lot of the information can be found only there.

My next step is 70-528. I already have the book and already past chapter 2.

2 comments