So first off, you shouldn't have to type the namespace as that would end up being a using statement at the top of your code.
For example, this should be an allowable usage for your format.
using MyNameSpace;
namespace MyProgram
{
public class Program
{
public void Main(string[] args)
{
var helper = new DataHelpers();
helper.SysnamePath("");
}
}
}
However, you mention that you'd like to do this as an extension method, in which case you need to label your class and method as both static. So it would look something like this
namespace MyNamespace
{
public static class DataHelpers
{
public static string SysnamePath ( string db , string schema , string table )
{
return "[ " + db + " ].[ " + schema + " ].[ " + table + " ]";
}
}
}
However your extension method needs to reference a variable that it extends off of using the
this
keyword. So your
SysnamePath
method needs to use 1 variable with the
this
keyword.
So maybe you'd implement it something like this
namespace MyNamespace
{
public static class DataHelpers
{
public static string SysnamePath ( this string db , string schema , string table )
{
return "[ " + db + " ].[ " + schema + " ].[ " + table + " ]";
}
}
}
So now your usage could look something like this
using MyNameSpace;
namespace MyProgram
{
public class Program
{
public void Main(string[] args)
{
var myDb = "Databasename";
myDb.SysnamePath("dbo", "my table name");
}
}
}
I would caution not extenion method-anizing all the things as it can be hard to understand propery usage if they are used on common types like string...in my opinion of course.