Archive for October, 2008

Microsoft’s Cloud OS: Windows Strata

I just came across this post on Dan Rigsby’s Blog about Microsoft’s new OS concept… I think Microsoft is just teasing people now they have just published its code name… called WINDOWS STRATA..

Technorati Tags:

Leave a comment

Microsoft’s New Enhancements in WCF,WF code name Dublin :)

today while going through my daily blog reading routine, I came across Microsoft Code Name Dublin in Stephen Forte’s Blog.
A major set of enhancements in WCF and its hosting. also developers will be able to develop Rest services via WCF…. also the enhancement will provide ability to develop applications entirely in XAML, from the presentation layer (WPF/SilverLight) to the workflow (WF also supports XAML in Dublin) to the actual WCF services.
The rest base starter kit is going to be released on Codeplex soon.
 
and the CTP for Dublin will be at PDC.
 
more details can be found at his blog


 

kick it on DotNetKicks.com

Share it :

Leave a comment

New Release of Silverlight 2

Microsoft has released version 2 of Silver light today.

The release contains following:

Silverlight 2 SDK Developer Tools and Expression Blend 2

it is available for download and can be found here

Technorati Tags: ,

Leave a comment

Creating instance of object dynamically

Yesterday while refactoring some code written by another developer I came across one thing at a lot of places one method was being used again and again

   1:  Public ClassName GetObject()
   2:  {
   3:  if object == null
   4:  create object
   5:  return object
   6:  }

That was essential logic but why rewrite…. there should be a generic way to accomplish this …

I came up with the idea of using Activator class in dot net…. which provides ability to create instances of objects dynamically.

here was my initial code

   1:   public static object CreateObject(Object obj)
   2:   {
   3:     if (obj == null)
   4:     {
   5:     return
Activator.CreateInstance(obj.GetType(),obj);
   6:     }
   7:    return obj;
   8:  }

but during execution I got following error “can’t get type of null object”, The problem was dot net does not allows to get type of null objects..

what now…. well! no worries at this stage generics comes handy by using generics it was just a piece of cake

Final Code:

   1:  public static T CreateObject<T>(T obj)
   2:  {
   3:  if (obj == null)
   4:  {
   5:  return Activator.CreateInstance<T>();
   6:  }
   7:  return obj; 
   8:  }
 
but what if the object passed, its instance creation 
requires parameterized constructor…
program will throw an exception at runtime in such 
cases… Why not prevent this during code writing

1:public static T CreateObject<T>(T obj)
where T : new()

2:  {
3:  if (obj == null)
4:  {
5:  return Activator.CreateInstance<T>();
6:  }
7:  return obj; 
8:  }
by adding new we have forced that the passed type 
should implement a parameter less constructor.

kick it on DotNetKicks.com Shout it

Leave a comment

Best Ebooks Sites

Leave a comment