Wednesday, April 21, 2010

Passing object[] from a webmethod

A PageMethod returning a object[] will be the ugliest of solutions, you would say. Sometimes, you are forced to code in a not-so-elegant style. And here's one such implementation. If any of you think you can make it better, please leave a comment.



Another solution to this will be to wrap all these objects up into a class and have this as the return type.


public class MyReturnType {
public ClassA A { get;set; }
public ClassB B { get;set; }
public ClassC C { get;set; }
}


and return an instance of MyReturnType (or List for multiple values)

Returning this composite MyReturnType object will be the ideal solution. But in my case, the elements of this class are known only at run time. Typically, this class will need to be build at run time. The easier alternate will be to


[WebMethod]
public object[] GetObjects()
{
...
return new object[] { objA, objB, objC };
}

Tuesday, April 13, 2010

Tidy your HTML code on Visual Studio

I, so absolutely love this shortcut! (Next only to Ctrl + k,c)

There's a way to tidy up your HTML source code view on your Visual Studio
- Ctrl + k,d and Ctrl + k,f

While Ctrl + k,d formats the whole page, Ctrl + k,f formats the selected area on the page