环境:net framework 4.5.2


    1. FileTool ft = new FileTool();
    2. //支持格式
    3. ft["Suffix"] = FileSuffix.Photo;
    1. public abstract class BaseTool : Upload {
    2. /// <summary>
    3. /// 最小文件数量
    4. /// </summary>
    5. public int MinFileCount = 1;
    6. /// <summary>
    7. /// 最大文件上传大小
    8. /// </summary>
    9. public int MaxFileCount = 5;
    10. /// <summary>
    11. /// 最大文件上传大小
    12. /// </summary>
    13. public int MaxFileSize = 10240;
    14. /// <summary>
    15. /// 默认类型
    16. /// </summary>
    17. public FileSuffix Suffix = FileSuffix.Ohter;
    18. /// <summary>
    19. /// 基本目录
    20. /// </summary>
    21. public string BaseDirectory = $"File/{DateTime.Now.ToString("yyyyMMdd")}/";
    22. /// <summary>
    23. /// 自定义属性
    24. /// </summary>
    25. /// <param name="key"></param>
    26. /// <returns></returns>
    27. public abstract object this[string key] { get; set; }
    28. public virtual dynamic Down(ControllerBase b, string relativePath, string rename) {
    29. throw new NotImplementedException();
    30. }
    31. public virtual string Up(HttpRequest req, bool rename = true) {
    32. throw new NotImplementedException();
    33. }
    34. }
    1. public override object this[string key] {
    2. get {
    3. return this.GetType().GetField(key).GetValue(this);
    4. }
    5. set {
    6. FieldInfo fieid = null;
    7. try {
    8. fieid = this.GetType().GetField(key);
    9. fieid.SetValue(this, value);
    10. } catch (Exception e) {
    11. throw new Exception($"试图将{value.GetType().ToString()}转{fieid.FieldType.ToString()}失败!");
    12. }
    13. }
    14. }