How Can I Make Extension Method For System.IO.Path Class what i mean that i need something like below:
Path.GetExtension(sFilePath)
i want to make method:
Path.GetMimeType(sFilePath)
Extension Method:
public static string GetMIMEType(this Path sPath,string sFilePath)
{
string sExtension = Path.GetExtension(sFilePath).ToLowerInvariant();
if (sExtension.Length > 0 && dicMIMETypes.ContainsKey(sExtension.Remove(0, 1)))
{
return dicMIMETypes[sExtension.Remove(0, 1)];
}
return "unknown/unknown";
}
but when compile above code method get error ('System.IO.Path': static types cannot be used as parameters).
Thanks All,
Path
is static, and therefore you cannot create an extension method for it. Extension methods require an instance of an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With