I’ve tried to do this in several different forms and this is just the most recent. I usually bumble for several hours and never get anywhere so I’d like to put the question out here with my real-world example.
I have Web Services which I write XML from so that people can pull information from our server, so I have:
(namespace)
public static class WebServices
{
public static void WriteXML(this WebService svc, DataSet results)
{
if (results != null)
HttpContext.Current.Response.Write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><xsl:stylesheet version=\"1.0\" " +
"xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns=\"http://www.w3.org/1999/xhtml\">" + results.GetXml() + "</xsl:stylesheet>");
}
}
Unforunately, that’s only accessible doing:
using (namespace)
....
this.WriteXML(DataSet);
When I want
using (namespace)
....
WriteXML(DataSet);
What am I missing to do so?
you wrote an extension method for
WebService– your first parameter isthis WebService svcwhich in turn means that your extension methodWriteXMLcan only be called on an instance ofWebService.