当前位置: 首页>>代码示例>>C#>>正文


C# Wrapper.WrapObjectReplacer方法代码示例

本文整理汇总了C#中Wrapper.WrapObjectReplacer方法的典型用法代码示例。如果您正苦于以下问题:C# Wrapper.WrapObjectReplacer方法的具体用法?C# Wrapper.WrapObjectReplacer怎么用?C# Wrapper.WrapObjectReplacer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Wrapper的用法示例。


在下文中一共展示了Wrapper.WrapObjectReplacer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RegisterPattern

        private static void RegisterPattern(CustomPatternSchemaBase schema)
        {
            var automationPeerType = typeof(AutomationPeer);
            // The only purpose of this method is to construct and correctly execute these lines of code:
            //
            //   var wrapper = new Wrapper(schema.PatternProviderInterface);
            //   var wrapObject = new AutomationPeer.WrapObject(wrapper.WrapObjectReplacer);
            //   AutomationPeer.s_patternInfo[schema.PatternId]
            //      = new AutomationPeer.PatternInfo(schema.PatternId,
            //                                       wrapObject,
            //                                       (PatternInterface)schema.PatternId);
            //   AutomationPattern.Register(schema.PatternGuid, schema.PatternName);
            //
            //   The problem here is that AutomationPeer.WrapObject, AutomationPeer.s_patternInfo, AutomationPattern.Register
            // and AutomationPeer.PatternInfo are not public, so we need some hardcore reflection.
            //   Now, to be very clear, casting patternId to PatternInterface is not totally correct,
            // but customly registered patterns get IDs near 50000 and max PatternInterface value is
            // something about 20, so they won't intersect ever. On the other hand, after several hours
            // studying AutomationPeer sources it seems unfeasible to get what we need in other way
            // because AutomationPeer wasn't written with extensibility in mind.
            var patternInfoHashtableField = automationPeerType.GetField("s_patternInfo", BindingFlags.NonPublic | BindingFlags.Static);

            // from AutomationPeer.cs: private delegate object WrapObject(AutomationPeer peer, object iface);
            var wrapObjectDelegateType = automationPeerType.GetNestedType("WrapObject", BindingFlags.NonPublic);
            var wrapper = new Wrapper(schema.PatternProviderInterface);
            var wrapObjectReplacerMethodInfo = ReflectionUtils.GetMethodInfo(() => wrapper.WrapObjectReplacer(null, null));
            var wrapObject = Delegate.CreateDelegate(wrapObjectDelegateType, wrapper, wrapObjectReplacerMethodInfo);

            // from AutomationPeer.cs:
            //private class PatternInfo
            //{
            //  internal int Id;
            //  internal AutomationPeer.WrapObject WrapObject;
            //  internal PatternInterface PatternInterface;

            //  internal PatternInfo(int id, AutomationPeer.WrapObject wrapObject, PatternInterface patternInterface)
            //  {
            //    this.Id = id;
            //    this.WrapObject = wrapObject;
            //    this.PatternInterface = patternInterface;
            //  }
            //}
            var patternInfoType = automationPeerType.GetNestedType("PatternInfo", BindingFlags.NonPublic);
            var patternInfoTypeCtor = patternInfoType.GetConstructor(
                BindingFlags.NonPublic | BindingFlags.Instance,
                binder: null,
                types: new[] {typeof(int), wrapObjectDelegateType, typeof(PatternInterface)},
                modifiers: null);
            var patternInfo = patternInfoTypeCtor.Invoke(new object[] {schema.PatternId, wrapObject, (PatternInterface)schema.PatternId});

            var automationPatternType = typeof(AutomationPattern);
            var registerMethod = automationPatternType.GetMethod("Register", BindingFlags.NonPublic | BindingFlags.Static);

            using (Dispatcher.CurrentDispatcher.DisableProcessing())
            {
                var patternInfoHashtable = (Hashtable)patternInfoHashtableField.GetValue(null);
                if (patternInfoHashtable.Contains(schema.PatternId)) return;
                patternInfoHashtable[schema.PatternId] = patternInfo;
                registerMethod.Invoke(null, new object[] {schema.PatternGuid, schema.PatternName});
            }
        }
开发者ID:TestStack,项目名称:uia-custom-pattern-managed,代码行数:61,代码来源:AutomationPeerAugmentationHelper.cs


注:本文中的Wrapper.WrapObjectReplacer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。