我正在尝试将我自己编写的 IsImage 属性添加到 HttpPostedFile 类中,这样如果用户正在上传文件,我可以执行如下操作:
FileUpload1.PostedFile.IsImage
我如何在 C# 中做到这一点?
最佳答案
您可以使用 extension methods为此目的。
public static class HttpPostedFileExtension
{
public static bool IsImage(this HttpPostedFile file)
{
/*your method code goes here*/
}
}
关于c# - 使用继承向内置类添加函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2485603/