SubscriptionAttribute.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Aitex.Core.Util
  6. {
  7. [AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field)]
  8. public class SubscriptionAttribute : Attribute
  9. {
  10. public enum FLAG
  11. {
  12. SaveDB = 0x00,
  13. IgnoreSaveDB = 0x01,
  14. }
  15. public string ModuleKey { get { return string.IsNullOrEmpty(Module) ? Key : (Module + "." + Key); } }
  16. public readonly string Key;
  17. public readonly string Module;
  18. public readonly string Method;
  19. public readonly int Flag;
  20. public SubscriptionAttribute(string key, int flag = 0, string module="")
  21. {
  22. if (string.IsNullOrWhiteSpace(key))
  23. throw new ArgumentNullException("key");
  24. Key = key;
  25. Flag = flag;
  26. Module = module;
  27. }
  28. public SubscriptionAttribute(string key, string module)
  29. {
  30. if (string.IsNullOrWhiteSpace(key))
  31. throw new ArgumentNullException("key");
  32. Key = key;
  33. Flag = (int)FLAG.SaveDB;
  34. Module = module;
  35. }
  36. public SubscriptionAttribute(object key, string module)
  37. {
  38. if (string.IsNullOrWhiteSpace(key.ToString()))
  39. throw new ArgumentNullException("key");
  40. Key = key.ToString();
  41. Flag = (int)FLAG.IgnoreSaveDB;
  42. Module = module;
  43. }
  44. public SubscriptionAttribute(string key, string module, string deviceName, string deviceType)
  45. {
  46. if (string.IsNullOrWhiteSpace(key))
  47. throw new ArgumentNullException("key");
  48. Key = string.Format("{0}.{1}.{2}", deviceType, deviceName, key);
  49. Flag = (int)FLAG.SaveDB;
  50. Module = module;
  51. }
  52. public SubscriptionAttribute(string module, string method, params object[] args)
  53. {
  54. if (string.IsNullOrWhiteSpace(module))
  55. throw new ArgumentNullException("module");
  56. Module = module;
  57. Method = method;
  58. }
  59. }
  60. }