Switch to fluid Switch to wfix Switch to fixed

StackPanel

dynamic rants = new Stack();

This is the first post in a series of tips on Visual Studio Extensibility development and Visual Studio in general from Extensibility point of view. You might find better resources that explain these tips elsewhere on the web, and I want to provide links to those, so that this Tip list can act as a reference.

Tip: Add your product title and logo to the Splash screen and Help->About of Visual Studio, when developing VSX Package.

  1. Implement IVsInstalledProduct interface on the VSPackage class
  2. Provide bitmap logo as icon resource in the VSPackage.resx
  3. set the ‘useInterface’ parameter of the InstalledProductRegistration attribute to ‘true’; this attribute is on top of the VSPackage class

A sample code listing for the IVsInstalledProduct interface implementation

#region IVsInstalledProduct Members
//This interface members will provide splash screen,
// help->about related product information
//Thus InstalledProduct attribute on top of the
// VSPackage class has UseInterface set to true
public int IdBmpSplash(out uint pIdBmp)
{
    pIdBmp = 402;
    return VSConstants.S_OK;
}

public int IdIcoLogoForAboutbox(out uint pIdIco)
{
    pIdIco = 402;
    return VSConstants.S_OK;
}

///
/// Show both Product name and version on the splash screen
///
public int OfficialName(out string pbstrName)
{
    pbstrName = GetResourceString("@110");
    return VSConstants.S_OK;
}

public int ProductDetails(out string pbstrProductDetails)
{
    pbstrProductDetails = GetResourceString("@112");
    return VSConstants.S_OK;
}

///
/// ProductId is stored in the VsPackage.resx
/// Please change it everytime you change the release version
///
public int ProductID(out string pbstrPID)
{
    // If we provide the version here, then we can't
    // get the version on the splash screen,
    // as VS only gets the splash screen product string
    // from OfficialName method above
    // So the version has been added to the resource 110
    pbstrPID = GetResourceString("@125");
    return VSConstants.S_OK;
}

///
/// Gets resource string from the VsPackage.resx resource file
///
public string GetResourceString(string resourceName)
{
    string returnValue = String.Empty;
    IVsResourceManager resourceManager =
       (IVsResourceManager)this.GetService(typeof(SVsResourceManager));
    if (null != resourceManager)
    {
        Guid packageGuid = this.GetType().GUID;
        int hresult = resourceManager.LoadResourceString(ref packageGuid,
            -1, resourceName, out returnValue);
    }
    return returnValue;
}
#endregion

Click here to find detailed instructions on this

Providing InnerXml to XElement

Posted by Vin on Aug-20-2008

In my latest project, I dived in to the world of Linq, by using Linq to Sql. As I have loads of XML related application logic I also got to use Linq to XML. We have XElement class given to us from System.Xml.Linq namespace which has loads of usefulness over the old world XmlElement class. So there I go admiring XElement, but wait I don’t have an InnerXml method, that lot of us have gotten used since the MSXML DOM days.

I came up with providing an Extension method InnerXml() on XElement.

public static string InnerXml(this XElement element)
{
    StringBuilder innerXml = new StringBuilder();

    foreach (XNode node in element.Nodes())
    {
        // append node's xml string to innerXml
        innerXml.Append(node.ToString());
    }
    return innerXml.ToString();
}

Someone was exactly looking for this on StackOverflow (the awesome tech QnA site that is in private beta right now)

Same method two interfaces

Posted by Vin on Aug-10-2008

If a C# class that inherits two interfaces is implementing a method. Both the interfaces have the same method with the same signature. What happens?

public class Address : IPersonalAddress, IBusinessAddress
{
    // We don't have no apt here
    public string GetAddress(int building,
        string street,
        string city,
        string state)
    {
        return building.ToString() + ", " +
            street + ", " +
            city + ", " +
            state;
    }
}

interface IPersonalAddress
{
    string GetAddress(int building,
        string street,
        string city,
        string state);
}

interface IBusinessAddress
{
    string GetAddress(int building,
        string street,
        string city,
        string state);
}

a. Compilation error
b. Nothing happens
c. Method from the first interface inherited, gets called
d. Runtime error
e. None of the above

Well the answer is it compiles fine and nothing happens. Why should anything happen? An interface does not have any concrete implementation significance, thus the class that implements the interface becomes more important here. So the method gets called and gets executed as if a normal method of the class.