zoukankan      html  css  js  c++  java
  • winrt反射

    第一步引用扩展类。

    using System.Reflection.IntrospectionExtensions;

    第二步反射。

    gridView是我定义的GridView控件。ItemClick是它的ItemClick事件。

    var typeInfo = (gridView.GetType()).GetTypeInfo();
                var eventInfo = typeInfo.GetDeclaredEvent("ItemClick");

      

    注意它只能获取自己定的事件,父类定义的要用循环获取。

    EventInfo eventInfo;

    do

    {
                        var typeInfo = type.GetTypeInfo();

           eventInfo = typeInfo.GetDeclaredEvent(eventName);
                        type = typeInfo.BaseType;
                    }
                    while (eventInfo == null && type != null);

    这样就可以获取了。

     //事件替换

    var eventRaisedMethod = this.GetType().GetTypeInfo().GetDeclaredMethod("OnEventRaised");
                    return eventRaisedMethod.CreateDelegate(eventInfo.EventHandlerType, this);

  • 相关阅读:
    services parameters 是如何表现的
    session表有多少条记录?
    php://input 如何用?
    getEditableConfigNames
    UTC + 8 = Beijing Time
    file vs database
    多环境drupal安全install.php
    新建block+cache
    drupal 8 bigpipe lazy_builder
    hook_theme 的重要性
  • 原文地址:https://www.cnblogs.com/wangjinming/p/3683562.html
Copyright © 2011-2022 走看看