Tuesday, April 17, 2012

Going to work on Visual Studio 2010, .Net Framework 4.0

Are you going to work on Visual Studio 2010, .Net Framework 4.0?

Have a look on these links first.

Breaking changes in .NET 4.0:  http://msdn.microsoft.com/en-us/library/ee855831%28VS.100%29.aspx

Breaking changes in ASP.NET 4.0:  http://www.asp.net/whitepapers/aspnet4/breaking-changes

Things we need to be aware of when using named parameters and optional parameters:  http://msdn.microsoft.com/en-us/vstudio/hh913013.aspx

Wednesday, March 7, 2012

Why doesn't C# support multiple inheritance?

This answer is from Chris Brumme via the following post. I've copied the text in here in case the post disappears.
There are a number of reasons we don't implement Multiple Implementation Inheritance directly. (As you know, we support Multiple Interface Inheritance).
However, I should point out that it's possible for compilers to create MI for their types inside the CLR. There are a few rough edges if you go down this path: the result is unverifiable, there is no interop with other languages via the CLS, and in V1 and V1.1 you may run into deadlocks with the OS loader lock. (We're fixing that last problem, but the first two problems remain). The technique is to generate some VTables in RVA-based static fields. In order to deposit the addresses of managed methods (which probably haven't been JITted yet), you use the VTFixup construct. This construct is a table of triplets. The triplets consist of a token to a managed method, an address in your image that should be fixed up (in this case, a slot of the VTable you are creating in the RVA-based static), and some flags. The possible flags are described in corhdr.h and they allow you to specify 32- vs. 64-bit pointer sizes, control over virtual behavior, and whether some reverse-PInvoke behavior should be applied in the form of a thunk that eventually dispatches to the managed method. If we are performing an unmanaged->managed transition, you also have some control over which AppDomain should be selected for us to dispatch the call. However, one of these options (COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN) doesn't exist in V1. We added it in V1.1.
There are several reasons we haven't provided a baked-in, verifiable, CLS-compliant version of multiple implementation inheritance:
1. Different languages actually have different expectations for how MI works. For example, how conflicts are resolved and whether duplicate bases are merged or redundant. Before we can implement MI in the CLR, we have to do a survey of all the languages, figure out the common concepts, and decide how to express them in a language-neutral manner. We would also have to decide whether MI belongs in the CLS and what this would mean for languages that don't want this concept (presumably VB.NET, for example). Of course, that's the business we are in as a common language runtime, but we haven't got around to doing it for MI yet.
2. The number of places where MI is truly appropriate is actually quite small. In many cases, multiple interface inheritance can get the job done instead. In other cases, you may be able to use encapsulation and delegation. If we were to add a slightly different construct, like mixins, would that actually be more powerful?
3. Multiple implementation inheritance injects a lot of complexity into the implementation. This complexity impacts casting, layout, dispatch, field access, serialization, identity comparisons, verifiability, reflection, generics, and probably lots of other places.
It's not at all clear that this feature would pay for itself. It's something we are often asked about. It's something we haven't done due diligence on. But my gut tells me that, after we've done a deep examination, we'll still decide to leave the feature unimplemented.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Now come to the actual implementation part. 


What happens when we implement tow interfaces which are having same signature for a method? Most the developers think this will give compilation error. Some people would say, we should give the interface name as the prefix in the method signature while implementing in the class. 
First of all compiler will not give compilation error. And it is not necessary that you should give the interface name as the prefix. If you just use the same signature, compiler will understand that you are giving the implementation.
But if you give the interface name as the prefix, you cannot access the method directly. You should typecast the object as the interface type to use method.


If you see the following example, you can understand this. 


public class Emp : IA, IB
{
    //1. Either dont mention the interface
    public string methodA()
    {
        return "Class Emp's output";
    }
    string IA.methodA()
    {
        return "Interface IA's output";
    }
    string IB.methodA()
    {
        return "Interface IB's output";
    }
}

Now invoking code looks like

Emp emp = new Emp();
emp.methodA();
IA a = (IA)emp;
a.methodA();
IB b = (IB)emp;
b.methodA();

Now if you print the output of the three method calls you wiil get

Class Emp's output 
Interface IA's output 
Interface IB's output

Thursday, February 16, 2012

ASP.NET Response.Redirect to new window

Method1

You need to add the following to your server side link/button:

OnClientClick="aspnetForm.target ='_blank';"

My entire button code looks something like:

<asp:LinkButton ID="myButton" runat="server" Text="Click Me!" OnClick="myButton_Click" OnClientClick="aspnetForm.target ='_blank';"/>

Method 2


In the server side OnClick I do a Response.Redirect("MyPage.aspx"); and the page is opened in a new window.

The other part you need to add is to fix the form's target otherwise every link will open in a new window. To do so add the following in the header of your POPUP window.

<script type="text/javascript">
        function fixform() {
            if (opener.document.getElementById("aspnetForm").target != "_blank") return;

            opener.document.getElementById("aspnetForm").target = "";
            opener.document.getElementById("aspnetForm").action = opener.location.href;
            }
</script>

and

<body onload="fixform()">