Generic restrictions

Tuesday, March 18, 2014

Generic restrictions can you predict the output of the following code snippet? Code Snippet static void Main(string args) {     var b = new B();     var g = new General<B>();     g.Exec(b); }   public class A {     public void Print()     {         Console.WriteLine("A");     } } public class B:A {     public void Print()     {         Console.WriteLine("B");     } }   public class General<T>     where T:A {     public void Exec(T t)     {         t.Print();     } } first try to predict before F5 and then give it a try. you might not expect to see so...
no comments

Google API

Sunday, June 30, 2013

Google API Google exposing their API though a .NET portable library. .NET developer can consume Google API directly from .NET. Eyal Peled‎‏ who's working for Google this days, was posting this announcement in his Facebook. it is a great opportunity for .NET developer to consume Google services though a convenient API. read more in here.
tags: , , , ,
no comments

The problem of animals and foods

Friday, February 8, 2013

The problem of animals and foods this is a short post that is dealing with a classic riddle. I was thinking on this riddle when I was trying to figure out a Scala feature. we are having (at Sela Group) a small Scala study group led by Israel Tabadi and while we were going over Scala's abstract type (which is by the way a cool implementation) I was thinking about the .NET equivalent solution. I will use the problem of "animals and foods" (taken from here) as an anchor's point. The problem: assuming an Animal...
no comments

Weak Event

Friday, July 20, 2012

Weak Event there is no doubted that event handler is the number one reason of memory leak under .NET framework. recently I was part of a team which was tracing a memory leak out of a dump file, as expected the main issue was happens to be the prime suspect (event handler). you can find plenty of resources on how and why careless usage of event handler can cause a memory leak (just Google it). in this post I will present a general solution for this problem (which can be use when applicable)....

Enum.HasFlag: good or bad?

Friday, January 28, 2011

Enum.HasFlag: good or bad? .NET 4 give us nice elegant way of checking whether enums contain a value.   assuming that we have the following enum: Code Snippet public enum MyEnum {     None = 0,     A = 1,     B = 2,     C = 4,     D = 8 } we can use the bitwise for checking whether instantiation of the enum contain a value, as shown in the next snippet: Code Snippet var options = MyEnum.A | MyEnum.B;...
no comments

Testing and Debugging MEF, Tips – Part 1

Friday, July 9, 2010

Testing and Debugging MEF, Tips - Part 1 this is the first post of a series that will offer some tips about testing and debugging your MEF-able component and application.   in this post we will focus about exporting Mock objects.   the code sample for this post can be download from here.   Prerequisite if you are not familiar with Mocks you better read more about this subject before proceeding with this post (in short Mocks are fake object which is use for separate...

T 4 beginners – part 4

Saturday, May 22, 2010

T 4 beginners – part 4 this is the 4rd post on this series. in this post we will focus on T4 Class feature control blocks. you can download the code for this post here. the series TOC is available here.   What is class feature control block? class feature control block is one of the T4 extension mechanism that enable reuse of T4 sections. using class feature control block you can defines helper properties or methods, that can be used from different T4...
tags: , , , ,
no comments

T 4 beginners – part 3

Friday, May 21, 2010

T 4 beginners – part 3 this is the 3rd post on this series. in this post we will focus on basics T4 Control blocks. you can download the code sample from here. the series TOC is available here.   T4 Control blocks is where dynamic text is added into the template output, this is the heart of T4 concept (C# is the default language but you can change it to VB).   Standard control blocks A standard control block is a section of...
tags: , , , ,
no comments

T 4 beginners – part 2

T 4 beginners – part 2 this is the second post on this series. in this post we will focus on basics T4 Directives. you can use the code sample of the previous post here. the series TOC is available here.   Directive syntax: any of the directives is using the following syntax: <#@ DirectiveName #> it start with <#@ follow with the directive name, includes zero or more name value parameters and end with #> All parameter values...
tags: , , , ,
no comments