ControlAttribute.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //############################################################
  2. // https://github.com/yuzhengyang
  3. // author:yuzhengyang
  4. //############################################################
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace Y.Utils.ReflectionUtils.AttributeUtils
  13. {
  14. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
  15. public class ControlAttribute : Attribute
  16. {
  17. public string Widget { get; set; }
  18. public string Click { get; set; }
  19. public ControlAttributeEvent Event { get; set; }
  20. public static void Band(Form form)
  21. {
  22. //string buttonName = "ShowMsg";
  23. //Type type = form.GetType();
  24. //FieldInfo fieldShowMsg = type.GetField(buttonName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
  25. //ControlAttribute controlAttribute = (ControlAttribute)fieldShowMsg.GetCustomAttribute(typeof(ControlAttribute));
  26. //FieldInfo fieldButton1 = type.GetField(controlAttribute.Widget, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
  27. //fieldShowMsg.SetValue(form, fieldButton1.GetValue(form));
  28. //MethodInfo method = type.GetMethod(controlAttribute.Click, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
  29. //EventInfo evt = fieldShowMsg.FieldType.GetEvent("Click", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
  30. //evt.AddEventHandler(fieldShowMsg.GetValue(form), Delegate.CreateDelegate(typeof(EventHandler), form, method));
  31. //int a = 0;
  32. }
  33. }
  34. }