You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

4 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. namespace Apewer.Web
  5. {
  6. internal sealed class ApiApplication
  7. {
  8. internal Dictionary<string, ApiFunction> Functions = null;
  9. internal List<ApiFunction> Items = null;
  10. internal Type Type;
  11. internal string Module;
  12. // 主特性和主要属性。
  13. internal ApiAttribute Attribute;
  14. internal string Name;
  15. internal string Lower;
  16. internal string Caption;
  17. internal string Description;
  18. // 附加特性。
  19. internal bool Independent;
  20. internal bool Hidden;
  21. internal ApiFunction Get(string name)
  22. {
  23. if (string.IsNullOrEmpty(name)) return null;
  24. var lower = name.ToLower();
  25. ApiFunction func;
  26. var exist = Functions.TryGetValue(lower, out func);
  27. return func;
  28. }
  29. internal Json ToJson(ApiOptions options)
  30. {
  31. if (Hidden) return null;
  32. var json = Json.NewObject();
  33. json.SetProperty("name", Name);
  34. if (!string.IsNullOrEmpty(Caption)) json.SetProperty("caption", Caption);
  35. if (!string.IsNullOrEmpty(Description)) json.SetProperty("description", Description);
  36. if (options.WithTypeName) json.SetProperty("type", Type.FullName);
  37. if (options.WithModuleName) json.SetProperty("mudule", Module);
  38. return json;
  39. }
  40. }
  41. }