为什么我的事件处理程序以 c为目标? 另外 – 甚至 c?
遵循创建最小,完整和可validation代码集的规范,请参阅以下内容:
using System; using System.Data; using System.Linq; using System.Windows; namespace WhatIsThis{ /// /// Interaction logic for App.xaml /// public partial class App : Application { private void Application_Startup( object sender, StartupEventArgs e ) { Foo.Bar += ( S, E ) => Console.WriteLine( "Do Something!" ); } protected override void OnActivated( EventArgs e ) { base.OnActivated( e ); Foo.OnBar( ); } } public static class Foo { private static event EventHandler _Bar; internal static void OnBar( ) { if ( _Bar != null ) _Bar.Extension( null, EventArgs.Empty ); } public static event EventHandler Bar { add { _Bar += value; } remove { _Bar -= value; } } private static void Extension( this EventHandler eH, object sender, EventArgs e ) { foreach( EventHandler evnt in eH.GetInvocationList( ).Cast( ) ) { Console.WriteLine( evnt.Target ); evnt( sender, e ); } } } }
我正在使用事件处理程序进行扩展以执行某些操作,并且我需要能够识别事件处理程序所针对的内容(基本上,如果它是System.ComponentModel.ISynchronizeInvoke类型对象(用于处理WinForms应用程序)或者它是一个System.Windows.Threading.DispatcherObject(用于处理WPF应用程序))。
当我在Extension
方法中查看WhatIsThis.App.c
,我发现它是WhatIsThis.App.c
。
我已经尝试将它作为几个不同的东西(包括一个Action)进行投射,但它总是以nullforms出现……这没有用
这是什么类型的对象?
这是什么类型的对象?
该名称由编译器生成。 我发布了一些关于编译器当时使用的名称模式的注释:
哪里可以了解VS调试器’魔术名’
请注意,这些可能会随时更改,自2010年我写完以来,我没有更新答案。正如评论所述,之后添加了更多魔术名称模式。
在你的情况下,虽然它是一个“c”,这是一个为lambda生成的闭包类。