环境:net framework 4.5.2
FileTool ft = new FileTool();
//支持格式
ft["Suffix"] = FileSuffix.Photo;
public abstract class BaseTool : Upload {
/// <summary>
/// 最小文件数量
/// </summary>
public int MinFileCount = 1;
/// <summary>
/// 最大文件上传大小
/// </summary>
public int MaxFileCount = 5;
/// <summary>
/// 最大文件上传大小
/// </summary>
public int MaxFileSize = 10240;
/// <summary>
/// 默认类型
/// </summary>
public FileSuffix Suffix = FileSuffix.Ohter;
/// <summary>
/// 基本目录
/// </summary>
public string BaseDirectory = $"File/{DateTime.Now.ToString("yyyyMMdd")}/";
/// <summary>
/// 自定义属性
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public abstract object this[string key] { get; set; }
public virtual dynamic Down(ControllerBase b, string relativePath, string rename) {
throw new NotImplementedException();
}
public virtual string Up(HttpRequest req, bool rename = true) {
throw new NotImplementedException();
}
}
public override object this[string key] {
get {
return this.GetType().GetField(key).GetValue(this);
}
set {
FieldInfo fieid = null;
try {
fieid = this.GetType().GetField(key);
fieid.SetValue(this, value);
} catch (Exception e) {
throw new Exception($"试图将{value.GetType().ToString()}转{fieid.FieldType.ToString()}失败!");
}
}
}