ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Delegate Type Casting Extension Methods

These extension methods enable type casting between generic Action, generic Func, EventHandler, generic EventHandler and non-generic Action, non-generic Func, non-generic EventHandler as well as generic EventHandler and non generic EventHandler delegates in mscorlib and System.dll assembly.

Source

using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.IO.Ports;
using System.Net;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;
using System.Timers;

public static class DelegateCastingExtensions
{
    public static AppDomainInitializer ToAppDomainInitializer(
        this Action<string[]> action)
    {
        return new AppDomainInitializer(action.Invoke);
    }

    public static Action<string[]> ToAction(
        this AppDomainInitializer @delegate)
    {
        return new Action<string[]>(@delegate.Invoke);
    }

    public static AssemblyLoadEventHandler ToAssemblyEventHandler(
        this Action<object, AssemblyLoadEventArgs> action)
    {
        return new AssemblyLoadEventHandler(action.Invoke);
    }

    public static Action<object, AssemblyLoadEventArgs> ToAction(
        this AssemblyLoadEventHandler @delegate)
    {
        return new Action<object, AssemblyLoadEventArgs>(@delegate.Invoke);
    }

    public static AsyncCallback ToAsyncCallback(
        this Action<IAsyncResult> action)
    {
        return new AsyncCallback(action.Invoke);
    }

    public static Action<IAsyncResult> ToAction(
        this AsyncCallback @delegate)
    {
        return new Action<IAsyncResult>(@delegate.Invoke);
    }

    public static Comparison<T> ToComparison<T>(
        this Func<T, T, int> function)
    {
        return new Comparison<T>(function.Invoke);
    }

    public static Func<T, T, int> ToFunc<T>(
        this Comparison<T> @delegate)
    {
        return new Func<T, T, int>(@delegate.Invoke);
    }

    public static ConsoleCancelEventHandler ToConsoleCancelEventHandler(
        this Action<object, ConsoleCancelEventArgs> action)
    {
        return new ConsoleCancelEventHandler(action.Invoke);
    }

    public static Action<object, ConsoleCancelEventArgs> ToAction(
        this ConsoleCancelEventHandler @delegate)
    {
        return new Action<object, ConsoleCancelEventArgs>(@delegate.Invoke);
    }

    public static Converter<TInput, TOutput> ToConverter<TInput, TOutput>(
        this Func<TInput, TOutput> func)
    {
        return new Converter<TInput, TOutput>(func.Invoke);
    }

    public static Func<TInput, TOutput> ToFunc<TInput, TOutput>(
        this Converter<TInput, TOutput> @delegate)
    {
        return new Func<TInput, TOutput>(@delegate.Invoke);
    }

    public static CrossAppDomainDelegate ToCrossAppDomainDelegate(
        this Action action)
    {
        return new CrossAppDomainDelegate(action.Invoke);
    }

    public static Action ToAction(
        this CrossAppDomainDelegate @delegate)
    {
        return new Action(@delegate.Invoke);
    }

    public static EventHandler ToEventHandler(
        this Action<object, EventArgs> action)
    {
        return new EventHandler(action.Invoke);
    }

    public static Action<object, EventArgs> ToAction(
        this EventHandler @delegate)
    {
        return new Action<object, EventArgs>(@delegate.Invoke);
    }

    public static EventHandler<T> ToEventHandler<T>(
        this Action<object, T> action)
        where T : EventArgs
    {
        return new EventHandler<T>(action.Invoke);
    }

    public static Action<object, T> ToAction<T>(
        this EventHandler<T> @delegate)
        where T : EventArgs
    {
        return new Action<object, T>(@delegate.Invoke);
    }

    public static Predicate<T> ToPredicate<T>(
        this Func<T, bool> func)
    {
        return new Predicate<T>(func.Invoke);
    }

    public static Func<T, bool> ToFunc<T>(
        this Predicate<T> @delegate)
    {
        return new Func<T, bool>(@delegate.Invoke);
    }

    public static ResolveEventHandler ToResolveEventHandler(
        this Func<object, ResolveEventArgs, Assembly> func)
    {
        return new ResolveEventHandler(func.Invoke);
    }

    public static Func<object, ResolveEventArgs, Assembly> ToFunc(
        this ResolveEventHandler @delegate)
    {
        return new Func<object, ResolveEventArgs, Assembly>(@delegate.Invoke);
    }

    public static UnhandledExceptionEventHandler ToUnhandledExceptionEventHandler(
        this Action<object, UnhandledExceptionEventArgs> action)
    {
        return new UnhandledExceptionEventHandler(action.Invoke);
    }

    public static Action<object, UnhandledExceptionEventArgs> ToAction(
        this UnhandledExceptionEventHandler @delegate)
    {
        return new Action<object, UnhandledExceptionEventArgs>(@delegate.Invoke);
    }

    public static NotifyCollectionChangedEventHandler ToNotifyCollectionChangedEventHandler(
        this Action<object, NotifyCollectionChangedEventArgs> action)
    {
        return new NotifyCollectionChangedEventHandler(action.Invoke);
    }

    public static Action<object, NotifyCollectionChangedEventArgs> ToAction(
        this NotifyCollectionChangedEventHandler @delegate)
    {
        return new Action<object, NotifyCollectionChangedEventArgs>(@delegate.Invoke);
    }

    public static AddingNewEventHandler ToAddingNewEventHandler(
        this Action<object, AddingNewEventArgs> action)
    {
        return new AddingNewEventHandler(action.Invoke);
    }

    public static Action<object, AddingNewEventArgs> ToAction(
        this AddingNewEventHandler @delegate)
    {
        return new Action<object, AddingNewEventArgs>(@delegate.Invoke);
    }

    public static AsyncCompletedEventHandler ToAsyncCompletedEventHandler(
        this Action<object, AsyncCompletedEventArgs> action)
    {
        return new AsyncCompletedEventHandler(action.Invoke);
    }

    public static Action<object, AsyncCompletedEventArgs> ToAction(
        this AsyncCompletedEventHandler @delegate)
    {
        return new Action<object, AsyncCompletedEventArgs>(@delegate.Invoke);
    }

    public static CancelEventHandler ToCancelEventHandler(
        this Action<object, CancelEventArgs> action)
    {
        return new CancelEventHandler(action.Invoke);
    }

    public static Action<object, CancelEventArgs> ToAction(
        this CancelEventHandler @delegate)
    {
        return new Action<object, CancelEventArgs>(@delegate.Invoke);
    }

    public static CollectionChangeEventHandler ToCollectionChangeEventHandler(
        this Action<object, CollectionChangeEventArgs> action)
    {
        return new CollectionChangeEventHandler(action.Invoke);
    }

    public static Action<object, CollectionChangeEventArgs> ToAction(
        this CollectionChangeEventHandler @delegate)
    {
        return new Action<object, CollectionChangeEventArgs>(@delegate.Invoke);
    }

    public static DoWorkEventHandler ToDoWorkEventHandler(
        this Action<object, DoWorkEventArgs> action)
    {
        return new DoWorkEventHandler(action.Invoke);
    }

    public static Action<object, DoWorkEventArgs> ToAction(
        this DoWorkEventHandler @delegate)
    {
        return new Action<object, DoWorkEventArgs>(@delegate.Invoke);
    }

    public static HandledEventHandler ToHandledEventHandler(
        this Action<object, HandledEventArgs> action)
    {
        return new HandledEventHandler(action.Invoke);
    }

    public static Action<object, HandledEventArgs> ToAction(
        this HandledEventHandler @delegate)
    {
        return new Action<object, HandledEventArgs>(@delegate.Invoke);
    }

    public static ListChangedEventHandler ToListChangedEventHandler(
        this Action<object, ListChangedEventArgs> action)
    {
        return new ListChangedEventHandler(action.Invoke);
    }

    public static Action<object, ListChangedEventArgs> ToAction(
        this ListChangedEventHandler @delegate)
    {
        return new Action<object, ListChangedEventArgs>(@delegate.Invoke);
    }

    public static ProgressChangedEventHandler ToProgressChangedEventHandler(
        this Action<object, ProgressChangedEventArgs> action)
    {
        return new ProgressChangedEventHandler(action.Invoke);
    }

    public static Action<object, ProgressChangedEventArgs> ToAction(
        this ProgressChangedEventHandler @delegate)
    {
        return new Action<object, ProgressChangedEventArgs>(@delegate.Invoke);
    }

    public static PropertyChangedEventHandler ToPropertyChangedEventHandler(
        this Action<object, PropertyChangedEventArgs> action)
    {
        return new PropertyChangedEventHandler(action.Invoke);
    }

    public static Action<object, PropertyChangedEventArgs> ToAction(
        this PropertyChangedEventHandler @delegate)
    {
        return new Action<object, PropertyChangedEventArgs>(@delegate.Invoke);
    }

    public static PropertyChangingEventHandler ToPropertyChangingEventHandler(
        this Action<object, PropertyChangingEventArgs> action)
    {
        return new PropertyChangingEventHandler(action.Invoke);
    }

    public static Action<object, PropertyChangingEventArgs> ToAction(
        this PropertyChangingEventHandler @delegate)
    {
        return new Action<object, PropertyChangingEventArgs>(@delegate.Invoke);
    }

    public static RefreshEventHandler ToRefreshEventHandler(
        this Action<RefreshEventArgs> action)
    {
        return new RefreshEventHandler(action.Invoke);
    }

    public static Action<RefreshEventArgs> ToAction(
        this RefreshEventHandler @delegate)
    {
        return new Action<RefreshEventArgs>(@delegate.Invoke);
    }

    public static RunWorkerCompletedEventHandler ToRunWorkerCompletedEventHandler(
        this Action<object, RunWorkerCompletedEventArgs> action)
    {
        return new RunWorkerCompletedEventHandler(action.Invoke);
    }

    public static Action<object, RunWorkerCompletedEventArgs> ToAction(
        this RunWorkerCompletedEventHandler @delegate)
    {
        return new Action<object, RunWorkerCompletedEventArgs>(@delegate.Invoke);
    }

    public static ActiveDesignerEventHandler ToActiveDesignerEventHandler(
        this Action<object, ActiveDesignerEventArgs> action)
    {
        return new ActiveDesignerEventHandler(action.Invoke);
    }

    public static Action<object, ActiveDesignerEventArgs> ToAction(
        this ActiveDesignerEventHandler @delegate)
    {
        return new Action<object, ActiveDesignerEventArgs>(@delegate.Invoke);
    }

    public static ComponentChangedEventHandler ToComponentChangedEventHandler(
        this Action<object, ComponentChangedEventArgs> action)
    {
        return new ComponentChangedEventHandler(action.Invoke);
    }

    public static Action<object, ComponentChangedEventArgs> ToAction(
        this ComponentChangedEventHandler @delegate)
    {
        return new Action<object, ComponentChangedEventArgs>(@delegate.Invoke);
    }

    public static ComponentChangingEventHandler ToComponentChangingEventHandler(
        this Action<object, ComponentChangingEventArgs> action)
    {
        return new ComponentChangingEventHandler(action.Invoke);
    }

    public static ComponentEventHandler ToComponentEventHandler(
        this Action<object, ComponentEventArgs> action)
    {
        return new ComponentEventHandler(action.Invoke);
    }

    public static Action<object, ComponentEventArgs> ToAction(
        this ComponentEventHandler @delegate)
    {
        return new Action<object, ComponentEventArgs>(@delegate.Invoke);
    }

    public static ComponentRenameEventHandler ToComponentRenameEventHandler(
        this Action<object, ComponentRenameEventArgs> action)
    {
        return new ComponentRenameEventHandler(action.Invoke);
    }

    public static Action<object, ComponentRenameEventArgs> ToAction(
        this ComponentRenameEventHandler @delegate)
    {
        return new Action<object, ComponentRenameEventArgs>(@delegate.Invoke);
    }

    public static DesignerEventHandler ToDesignerEventHandler(
        this Action<object, DesignerEventArgs> action)
    {
        return new DesignerEventHandler(action.Invoke);
    }

    public static DesignerTransactionCloseEventHandler ToDesignerTransactionCloseEventHandler(
        this Action<object, DesignerTransactionCloseEventArgs> action)
    {
        return new DesignerTransactionCloseEventHandler(action.Invoke);
    }

    public static Action<object, DesignerTransactionCloseEventArgs> ToAction(
        this DesignerTransactionCloseEventHandler @delegate)
    {
        return new Action<object, DesignerTransactionCloseEventArgs>(@delegate.Invoke);
    }

    public static ServiceCreatorCallback ToServiceCreatorCallback(
        this Func<IServiceContainer, Type, object> func)
    {
        return new ServiceCreatorCallback(func.Invoke);
    }

    public static Func<IServiceContainer, Type, object> ToFunc(
        this ServiceCreatorCallback @delegate)
    {
        return new Func<IServiceContainer, Type, object>(@delegate.Invoke);
    }

    public static ResolveNameEventHandler ToResolveNameEventHandler(
        this Action<object, ResolveNameEventArgs> action)
    {
        return new ResolveNameEventHandler(action.Invoke);
    }

    public static Action<object, ResolveNameEventArgs> ToAction(
        this ResolveNameEventHandler @delegate)
    {
        return new Action<object, ResolveNameEventArgs>(@delegate.Invoke);
    }

    public static SettingChangingEventHandler ToSettingChangingEventHandler(
        this Action<object, SettingChangingEventArgs> action)
    {
        return new SettingChangingEventHandler(action.Invoke);
    }

    public static Action<object, SettingChangingEventArgs> ToAction(
        this SettingChangingEventHandler @delegate)
    {
        return new Action<object, SettingChangingEventArgs>(@delegate.Invoke);
    }

    public static SettingsLoadedEventHandler ToSettingsLoadedEventHandler(
        this Action<object, SettingsLoadedEventArgs> action)
    {
        return new SettingsLoadedEventHandler(action.Invoke);
    }

    public static Action<object, SettingsLoadedEventArgs> ToAction(
        this SettingsLoadedEventHandler @delegate)
    {
        return new Action<object, SettingsLoadedEventArgs>(@delegate.Invoke);
    }

    public static SettingsSavingEventHandler ToSettingsSavingEventHandler(
        this Action<object, CancelEventArgs> action)
    {
        return new SettingsSavingEventHandler(action.Invoke);
    }

    public static Action<object, CancelEventArgs> ToAction(
        this SettingsSavingEventHandler @delegate)
    {
        return new Action<object, CancelEventArgs>(@delegate.Invoke);
    }

    public static DataReceivedEventHandler ToDataReceivedEventHandler(
        this Action<object, DataReceivedEventArgs> action)
    {
        return new DataReceivedEventHandler(action.Invoke);
    }

    public static Action<object, DataReceivedEventArgs> ToAction(
        this DataReceivedEventHandler @delegate)
    {
        return new Action<object, DataReceivedEventArgs>(@delegate.Invoke);
    }

    public static EntryWrittenEventHandler ToEntryWrittenEventHandler(
        this Action<object, EntryWrittenEventArgs> action)
    {
        return new EntryWrittenEventHandler(action.Invoke);
    }

    public static ErrorEventHandler ToErrorEventHandler(
        this Action<object, ErrorEventArgs> action)
    {
        return new ErrorEventHandler(action.Invoke);
    }

    public static Action<object, ErrorEventArgs> ToAction(
        this ErrorEventHandler @delegate)
    {
        return new Action<object, ErrorEventArgs>(@delegate.Invoke);
    }

    public static FileSystemEventHandler ToFileSystemEventHandler(
        this Action<object, FileSystemEventArgs> action)
    {
        return new FileSystemEventHandler(action.Invoke);
    }

    public static Action<object, FileSystemEventArgs> ToAction(
        this FileSystemEventHandler @delegate)
    {
        return new Action<object, FileSystemEventArgs>(@delegate.Invoke);
    }

    public static RenamedEventHandler ToRenamedEventHandler(
        this Action<object, RenamedEventArgs> action)
    {
        return new RenamedEventHandler(action.Invoke);
    }

    public static Action<object, RenamedEventArgs> ToAction(
        this RenamedEventHandler @delegate)
    {
        return new Action<object, RenamedEventArgs>(@delegate.Invoke);
    }

    public static PipeStreamImpersonationWorker ToPipeStreamImpersonationWorker(
        this Action action)
    {
        return new PipeStreamImpersonationWorker(action.Invoke);
    }

    public static Action ToAction(
        this PipeStreamImpersonationWorker @delegate)
    {
        return new Action(@delegate.Invoke);
    }

    public static SerialDataReceivedEventHandler ToSerialDataReceivedEventHandler(
        this Action<object, SerialDataReceivedEventArgs> action)
    {
        return new SerialDataReceivedEventHandler(action.Invoke);
    }

    public static Action<object, SerialDataReceivedEventArgs> ToAction(
        this SerialDataReceivedEventHandler @delegate)
    {
        return new Action<object, SerialDataReceivedEventArgs>(@delegate.Invoke);
    }

    public static SerialErrorReceivedEventHandler ToSerialErrorReceivedEventHandler(
        this Action<object, SerialErrorReceivedEventArgs> action)
    {
        return new SerialErrorReceivedEventHandler(action.Invoke);
    }

    public static Action<object, SerialErrorReceivedEventArgs> ToAction(
        this SerialErrorReceivedEventHandler @delegate)
    {
        return new Action<object, SerialErrorReceivedEventArgs>(@delegate.Invoke);
    }

    public static SerialPinChangedEventHandler ToSerialPinChangedEventHandler(
        this Action<object, SerialPinChangedEventArgs> action)
    {
        return new SerialPinChangedEventHandler(action.Invoke);
    }

    public static Action<object, SerialPinChangedEventArgs> ToAction(
        this SerialPinChangedEventHandler @delegate)
    {
        return new Action<object, SerialPinChangedEventArgs>(@delegate.Invoke);
    }

    public static AuthenticationSchemeSelector ToAuthenticationSchemeSelector(
        this Func<HttpListenerRequest, AuthenticationSchemes> func)
    {
        return new AuthenticationSchemeSelector(func.Invoke);
    }

    public static Func<HttpListenerRequest, AuthenticationSchemes> ToFunc(
        this AuthenticationSchemeSelector @delegate)
    {
        return new Func<HttpListenerRequest, AuthenticationSchemes>(@delegate.Invoke);
    }

    public static BindIPEndPoint ToBindIPEndPoint(
        this Func<ServicePoint, IPEndPoint, int, IPEndPoint> func)
    {
        return new BindIPEndPoint(func.Invoke);
    }

    public static Func<ServicePoint, IPEndPoint, int, IPEndPoint> ToFunc(
        this BindIPEndPoint @delegate)
    {
        return new Func<ServicePoint, IPEndPoint, int, IPEndPoint>(@delegate.Invoke);
    }

    public static DownloadDataCompletedEventHandler ToDownloadDataCompletedEventHandler(
        this Action<object, DownloadDataCompletedEventArgs> action)
    {
        return new DownloadDataCompletedEventHandler(action.Invoke);
    }

    public static Action<object, DownloadDataCompletedEventArgs> ToAction(
        this DownloadDataCompletedEventHandler @delegate)
    {
        return new Action<object, DownloadDataCompletedEventArgs>(@delegate.Invoke);
    }

    public static DownloadProgressChangedEventHandler ToDownloadProgressChangedEventHandler(
        this Action<object, DownloadProgressChangedEventArgs> action)
    {
        return new DownloadProgressChangedEventHandler(action.Invoke);
    }

    public static Action<object, DownloadProgressChangedEventArgs> ToAction(
        this DownloadProgressChangedEventHandler @delegate)
    {
        return new Action<object, DownloadProgressChangedEventArgs>(@delegate.Invoke);
    }

    public static DownloadStringCompletedEventHandler ToDownloadStringCompletedEventHandler(
        this Action<object, DownloadStringCompletedEventArgs> action)
    {
        return new DownloadStringCompletedEventHandler(action.Invoke);
    }

    public static Action<object, DownloadStringCompletedEventArgs> ToAction(
        this DownloadStringCompletedEventHandler @delegate)
    {
        return new Action<object, DownloadStringCompletedEventArgs>(@delegate.Invoke);
    }

    public static HttpContinueDelegate ToHttpContinueDelegate(
        this Action<int, WebHeaderCollection> action)
    {
        return new HttpContinueDelegate(action.Invoke);
    }

    public static Action<int, WebHeaderCollection> ToAction(
        this HttpContinueDelegate @delegate)
    {
        return new Action<int, WebHeaderCollection>(@delegate.Invoke);
    }

    public static OpenReadCompletedEventHandler ToOpenReadCompletedEventHandler(
        this Action<object, OpenReadCompletedEventArgs> action)
    {
        return new OpenReadCompletedEventHandler(action.Invoke);
    }

    public static Action<object, OpenReadCompletedEventArgs> ToAction(
        this OpenReadCompletedEventHandler @delegate)
    {
        return new Action<object, OpenReadCompletedEventArgs>(@delegate.Invoke);
    }

    public static OpenWriteCompletedEventHandler ToOpenWriteCompletedEventHandler(
        this Action<object, OpenWriteCompletedEventArgs> action)
    {
        return new OpenWriteCompletedEventHandler(action.Invoke);
    }

    public static Action<object, OpenWriteCompletedEventArgs> ToAction(
        this OpenWriteCompletedEventHandler @delegate)
    {
        return new Action<object, OpenWriteCompletedEventArgs>(@delegate.Invoke);
    }

    public static UploadDataCompletedEventHandler ToUploadDataCompletedEventHandler(
        this Action<object, UploadDataCompletedEventArgs> action)
    {
        return new UploadDataCompletedEventHandler(action.Invoke);
    }

    public static Action<object, UploadDataCompletedEventArgs> ToAction(
        this UploadDataCompletedEventHandler @delegate)
    {
        return new Action<object, UploadDataCompletedEventArgs>(@delegate.Invoke);
    }

    public static UploadFileCompletedEventHandler ToUploadFileCompletedEventHandler(
        this Action<object, UploadFileCompletedEventArgs> action)
    {
        return new UploadFileCompletedEventHandler(action.Invoke);
    }

    public static Action<object, UploadFileCompletedEventArgs> ToAction(
        this UploadFileCompletedEventHandler @delegate)
    {
        return new Action<object, UploadFileCompletedEventArgs>(@delegate.Invoke);
    }

    public static UploadProgressChangedEventHandler ToUploadProgressChangedEventHandler(
        this Action<object, UploadProgressChangedEventArgs> action)
    {
        return new UploadProgressChangedEventHandler(action.Invoke);
    }

    public static Action<object, UploadProgressChangedEventArgs> ToAction(
        this UploadProgressChangedEventHandler @delegate)
    {
        return new Action<object, UploadProgressChangedEventArgs>(@delegate.Invoke);
    }

    public static UploadStringCompletedEventHandler ToUploadStringCompletedEventHandler(
        this Action<object, UploadStringCompletedEventArgs> action)
    {
        return new UploadStringCompletedEventHandler(action.Invoke);
    }

    public static Action<object, UploadStringCompletedEventArgs> ToAction(
        this UploadStringCompletedEventHandler @delegate)
    {
        return new Action<object, UploadStringCompletedEventArgs>(@delegate.Invoke);
    }

    public static UploadValuesCompletedEventHandler ToUploadValuesCompletedEventHandler(
        this Action<object, UploadValuesCompletedEventArgs> action)
    {
        return new UploadValuesCompletedEventHandler(action.Invoke);
    }

    public static Action<object, UploadValuesCompletedEventArgs> ToAction(
        this UploadValuesCompletedEventHandler @delegate)
    {
        return new Action<object, UploadValuesCompletedEventArgs>(@delegate.Invoke);
    }

    public static SendCompletedEventHandler ToSendCompletedEventHandler(
        this Action<object, AsyncCompletedEventArgs> action)
    {
        return new SendCompletedEventHandler(action.Invoke);
    }

    public static Action<object, AsyncCompletedEventArgs> ToAction(
        this SendCompletedEventHandler @delegate)
    {
        return new Action<object, AsyncCompletedEventArgs>(@delegate.Invoke);
    }

    public static NetworkAddressChangedEventHandler ToNetworkAddressChangedEventHandler(
        this Action<object, EventArgs> action)
    {
        return new NetworkAddressChangedEventHandler(action.Invoke);
    }

    public static Action<object, EventArgs> ToAction(
        this NetworkAddressChangedEventHandler @delegate)
    {
        return new Action<object, EventArgs>(@delegate.Invoke);
    }

    public static NetworkAvailabilityChangedEventHandler ToNetworkAvailabilityChangedEventHandler(
        this Action<object, NetworkAvailabilityEventArgs> action)
    {
        return new NetworkAvailabilityChangedEventHandler(action.Invoke);
    }

    public static Action<object, NetworkAvailabilityEventArgs> ToAction(
        this NetworkAvailabilityChangedEventHandler @delegate)
    {
        return new Action<object, NetworkAvailabilityEventArgs>(@delegate.Invoke);
    }

    public static PingCompletedEventHandler ToPingCompletedEventHandler(
        this Action<object, PingCompletedEventArgs> action)
    {
        return new PingCompletedEventHandler(action.Invoke);
    }

    public static Action<object, PingCompletedEventArgs> ToAction(
        this PingCompletedEventHandler @delegate)
    {
        return new Action<object, PingCompletedEventArgs>(@delegate.Invoke);
    }

    public static LocalCertificateSelectionCallback ToLocalCertificateSelectionCallback(
        this Func<object, string, X509CertificateCollection, X509Certificate, string[], X509Certificate> func)
    {
        return new LocalCertificateSelectionCallback(func.Invoke);
    }

    public static Func<object, string, X509CertificateCollection, X509Certificate, string[], X509Certificate> ToFunc(
        this LocalCertificateSelectionCallback @delegate)
    {
        return new Func<object, string, X509CertificateCollection, X509Certificate, string[], X509Certificate>(@delegate.Invoke);
    }

    public static RemoteCertificateValidationCallback ToRemoteCertificateValidationCallback(
        this Func<object, X509Certificate, X509Chain, SslPolicyErrors, bool> func)
    {
        return new RemoteCertificateValidationCallback(func.Invoke);
    }

    public static Func<object, X509Certificate, X509Chain, SslPolicyErrors, bool> ToFunc(
        this RemoteCertificateValidationCallback @delegate)
    {
        return new Func<object, X509Certificate, X509Chain, SslPolicyErrors, bool>(@delegate.Invoke);
    }

    public static MemberFilter ToMemberFilter(
        this Func<MemberInfo, object, bool> func)
    {
        return new MemberFilter(func.Invoke);
    }

    public static Func<MemberInfo, object, bool> ToFunc(
        this MemberFilter @delegate)
    {
        return new Func<MemberInfo, object, bool>(@delegate.Invoke);
    }

    public static ModuleResolveEventHandler ToModuleResolveEventHandler(
        this Func<object, ResolveEventArgs, Module> func)
    {
        return new ModuleResolveEventHandler(func.Invoke);
    }

    public static Func<object, ResolveEventArgs, Module> ToFunc(
        this ModuleResolveEventHandler @delegate)
    {
        return new Func<object, ResolveEventArgs, Module>(@delegate.Invoke);
    }

    public static TypeFilter ToTypeFilter(
        this Func<Type, object, bool> func)
    {
        return new TypeFilter(func.Invoke);
    }

    public static Func<Type, object, bool> ToFunc(
        this TypeFilter @delegate)
    {
        return new Func<Type, object, bool>(@delegate.Invoke);
    }

    public static ObjectCreationDelegate ToObjectCreationDelegate(
        this Func<IntPtr, IntPtr> func)
    {
        return new ObjectCreationDelegate(func.Invoke);
    }

    public static Func<IntPtr, IntPtr> ToFunc(
        this ObjectCreationDelegate @delegate)
    {
        return new Func<IntPtr, IntPtr>(@delegate.Invoke);
    }

    public static CrossContextDelegate ToCrossContextDelegate(
        this Action action)
    {
        return new CrossContextDelegate(action.Invoke);
    }

    public static Action ToAction(
        this CrossContextDelegate @delegate)
    {
        return new Action(@delegate.Invoke);
    }

    public static HeaderHandler ToHeaderHandler(
        this Func<Header[], object> func)
    {
        return new HeaderHandler(func.Invoke);
    }

    public static Func<Header[], object> ToFunc(
        this HeaderHandler @delegate)
    {
        return new Func<Header[], object>(@delegate.Invoke);
    }

    public static MessageSurrogateFilter ToMessageSurrogateFilter(
        this Func<string, object, bool> func)
    {
        return new MessageSurrogateFilter(func.Invoke);
    }

    public static Func<string, object, bool> ToFunc(
        this MessageSurrogateFilter @delegate)
    {
        return new Func<string, object, bool>(@delegate.Invoke);
    }

    public static MatchEvaluator ToMatchEvaluator(
        this Func<Match, string> func)
    {
        return new MatchEvaluator(func.Invoke);
    }

    public static Func<Match, string> ToFunc(
        this MatchEvaluator @delegate)
    {
        return new Func<Match, string>(@delegate.Invoke);
    }

    public static ContextCallback ToContextCallback(
        this Action<object> action)
    {
        return new ContextCallback(action.Invoke);
    }

    public static Action<object> ToAction(
        this ContextCallback @delegate)
    {
        return new Action<object>(@delegate.Invoke);
    }

    public static ParameterizedThreadStart ToParameterizedThreadStart(
        this Action<object> action)
    {
        return new ParameterizedThreadStart(action.Invoke);
    }

    public static Action<object> ToAction(
        this ParameterizedThreadStart @delegate)
    {
        return new Action<object>(@delegate.Invoke);
    }

    public static SendOrPostCallback ToSendOrPostCallback(
        this Action<object> action)
    {
        return new SendOrPostCallback(action.Invoke);
    }

    public static Action<object> ToAction(
        this SendOrPostCallback @delegate)
    {
        return new Action<object>(@delegate.Invoke);
    }

    public static ThreadExceptionEventHandler ToThreadExceptionEventHandler(
        this Action<object, ThreadExceptionEventArgs> action)
    {
        return new ThreadExceptionEventHandler(action.Invoke);
    }

    public static Action<object, ThreadExceptionEventArgs> ToAction(
        this ThreadExceptionEventHandler @delegate)
    {
        return new Action<object, ThreadExceptionEventArgs>(@delegate.Invoke);
    }

    public static ThreadStart ToThreadStart(
        this Action action)
    {
        return new ThreadStart(action.Invoke);
    }

    public static Action ToAction(
        this ThreadStart @delegate)
    {
        return new Action(@delegate.Invoke);
    }

    public static TimerCallback ToTimerCallback(
        this Action<object> action)
    {
        return new TimerCallback(action.Invoke);
    }

    public static Action<object> ToAction(
        this TimerCallback @delegate)
    {
        return new Action<object>(@delegate.Invoke);
    }

    public static WaitCallback ToWaitCallback(
        this Action<object> action)
    {
        return new WaitCallback(action.Invoke);
    }

    public static Action<object> ToAction(
        this WaitCallback @delegate)
    {
        return new Action<object>(@delegate.Invoke);
    }

    public static WaitOrTimerCallback ToWaitOrTimerCallback(
        this Action<object, bool> action)
    {
        return new WaitOrTimerCallback(action.Invoke);
    }

    public static Action<object, bool> ToAction(
        this WaitOrTimerCallback @delegate)
    {
        return new Action<object, bool>(@delegate.Invoke);
    }

    public static ElapsedEventHandler ToElapsedEventHandler(
        this Action<object, ElapsedEventArgs> action)
    {
        return new ElapsedEventHandler(action.Invoke);
    }

    public static Action<object, ElapsedEventArgs> ToAction(
        this ElapsedEventHandler @delegate)
    {
        return new Action<object, ElapsedEventArgs>(@delegate.Invoke);
    }

    public static AssemblyLoadEventHandler ToAssemblyEventHandler(
        this EventHandler<AssemblyLoadEventArgs> @delegate)
    {
        return new AssemblyLoadEventHandler(@delegate.Invoke);
    }

    public static EventHandler<AssemblyLoadEventArgs> ToEventHandler(
        this AssemblyLoadEventHandler @delegate)
    {
        return new EventHandler<AssemblyLoadEventArgs>(@delegate.Invoke);
    }

    public static ConsoleCancelEventHandler ToConsoleCancelEventHandler(
        this EventHandler<ConsoleCancelEventArgs> @delegate)
    {
        return new ConsoleCancelEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ConsoleCancelEventArgs> ToEventHandler(
        this ConsoleCancelEventHandler @delegate)
    {
        return new EventHandler<ConsoleCancelEventArgs>(@delegate.Invoke);
    }

    public static EventHandler ToEventHandler(
        this EventHandler<EventArgs> @delegate)
    {
        return new EventHandler(@delegate.Invoke);
    }

    public static EventHandler<EventArgs> ToEventHandler(
        this EventHandler @delegate)
    {
        return new EventHandler<EventArgs>(@delegate.Invoke);
    }

    public static UnhandledExceptionEventHandler ToUnhandledExceptionEventHandler(
        this EventHandler<UnhandledExceptionEventArgs> @delegate)
    {
        return new UnhandledExceptionEventHandler(@delegate.Invoke);
    }

    public static EventHandler<UnhandledExceptionEventArgs> ToEventHandler(
        this UnhandledExceptionEventHandler @delegate)
    {
        return new EventHandler<UnhandledExceptionEventArgs>(@delegate.Invoke);
    }

    public static NotifyCollectionChangedEventHandler ToNotifyCollectionChangedEventHandler(
        this EventHandler<NotifyCollectionChangedEventArgs> @delegate)
    {
        return new NotifyCollectionChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<NotifyCollectionChangedEventArgs> ToEventHandler(
        this NotifyCollectionChangedEventHandler @delegate)
    {
        return new EventHandler<NotifyCollectionChangedEventArgs>(@delegate.Invoke);
    }

    public static AddingNewEventHandler ToAddingNewEventHandler(
        this EventHandler<AddingNewEventArgs> @delegate)
    {
        return new AddingNewEventHandler(@delegate.Invoke);
    }

    public static EventHandler<AddingNewEventArgs> ToEventHandler(
        this AddingNewEventHandler @delegate)
    {
        return new EventHandler<AddingNewEventArgs>(@delegate.Invoke);
    }

    public static AsyncCompletedEventHandler ToAsyncCompletedEventHandler(
        this EventHandler<AsyncCompletedEventArgs> @delegate)
    {
        return new AsyncCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<AsyncCompletedEventArgs> ToEventHandler(
        this AsyncCompletedEventHandler @delegate)
    {
        return new EventHandler<AsyncCompletedEventArgs>(@delegate.Invoke);
    }

    public static CancelEventHandler ToCancelEventHandler(
        this EventHandler<CancelEventArgs> @delegate)
    {
        return new CancelEventHandler(@delegate.Invoke);
    }

    public static EventHandler<CancelEventArgs> ToEventHandler(
        this CancelEventHandler @delegate)
    {
        return new EventHandler<CancelEventArgs>(@delegate.Invoke);
    }

    public static CollectionChangeEventHandler ToCollectionChangeEventHandler(
        this EventHandler<CollectionChangeEventArgs> @delegate)
    {
        return new CollectionChangeEventHandler(@delegate.Invoke);
    }

    public static EventHandler<CollectionChangeEventArgs> ToEventHandler(
        this CollectionChangeEventHandler @delegate)
    {
        return new EventHandler<CollectionChangeEventArgs>(@delegate.Invoke);
    }

    public static DoWorkEventHandler ToDoWorkEventHandler(
        this EventHandler<DoWorkEventArgs> @delegate)
    {
        return new DoWorkEventHandler(@delegate.Invoke);
    }

    public static EventHandler<DoWorkEventArgs> ToEventHandler(
        this DoWorkEventHandler @delegate)
    {
        return new EventHandler<DoWorkEventArgs>(@delegate.Invoke);
    }

    public static HandledEventHandler ToHandledEventHandler(
        this EventHandler<HandledEventArgs> @delegate)
    {
        return new HandledEventHandler(@delegate.Invoke);
    }

    public static EventHandler<HandledEventArgs> ToEventHandler(
        this HandledEventHandler @delegate)
    {
        return new EventHandler<HandledEventArgs>(@delegate.Invoke);
    }

    public static ListChangedEventHandler ToListChangedEventHandler(
        this EventHandler<ListChangedEventArgs> @delegate)
    {
        return new ListChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ListChangedEventArgs> ToEventHandler(
        this ListChangedEventHandler @delegate)
    {
        return new EventHandler<ListChangedEventArgs>(@delegate.Invoke);
    }

    public static ProgressChangedEventHandler ToProgressChangedEventHandler(
        this EventHandler<ProgressChangedEventArgs> @delegate)
    {
        return new ProgressChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ProgressChangedEventArgs> ToEventHandler(
        this ProgressChangedEventHandler @delegate)
    {
        return new EventHandler<ProgressChangedEventArgs>(@delegate.Invoke);
    }

    public static PropertyChangedEventHandler ToPropertyChangedEventHandler(
        this EventHandler<PropertyChangedEventArgs> @delegate)
    {
        return new PropertyChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<PropertyChangedEventArgs> ToEventHandler(
        this PropertyChangedEventHandler @delegate)
    {
        return new EventHandler<PropertyChangedEventArgs>(@delegate.Invoke);
    }

    public static PropertyChangingEventHandler ToPropertyChangingEventHandler(
        this EventHandler<PropertyChangingEventArgs> @delegate)
    {
        return new PropertyChangingEventHandler(@delegate.Invoke);
    }

    public static EventHandler<PropertyChangingEventArgs> ToEventHandler(
        this PropertyChangingEventHandler @delegate)
    {
        return new EventHandler<PropertyChangingEventArgs>(@delegate.Invoke);
    }

    public static RunWorkerCompletedEventHandler ToRunWorkerCompletedEventHandler(
        this EventHandler<RunWorkerCompletedEventArgs> @delegate)
    {
        return new RunWorkerCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<RunWorkerCompletedEventArgs> ToEventHandler(
        this RunWorkerCompletedEventHandler @delegate)
    {
        return new EventHandler<RunWorkerCompletedEventArgs>(@delegate.Invoke);
    }

    public static ActiveDesignerEventHandler ToActiveDesignerEventHandler(
        this EventHandler<ActiveDesignerEventArgs> @delegate)
    {
        return new ActiveDesignerEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ActiveDesignerEventArgs> ToEventHandler(
        this ActiveDesignerEventHandler @delegate)
    {
        return new EventHandler<ActiveDesignerEventArgs>(@delegate.Invoke);
    }

    public static ComponentChangedEventHandler ToComponentChangedEventHandler(
        this EventHandler<ComponentChangedEventArgs> @delegate)
    {
        return new ComponentChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ComponentChangedEventArgs> ToEventHandler(
        this ComponentChangedEventHandler @delegate)
    {
        return new EventHandler<ComponentChangedEventArgs>(@delegate.Invoke);
    }

    public static ComponentChangingEventHandler ToComponentChangingEventHandler(
        this EventHandler<ComponentChangingEventArgs> @delegate)
    {
        return new ComponentChangingEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ComponentChangingEventArgs> ToEventHandler(
        this ComponentChangingEventHandler @delegate)
    {
        return new EventHandler<ComponentChangingEventArgs>(@delegate.Invoke);
    }

    public static ComponentEventHandler ToComponentEventHandler(
        this EventHandler<ComponentEventArgs> @delegate)
    {
        return new ComponentEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ComponentEventArgs> ToEventHandler(
        this ComponentEventHandler @delegate)
    {
        return new EventHandler<ComponentEventArgs>(@delegate.Invoke);
    }

    public static ComponentRenameEventHandler ToComponentRenameEventHandler(
        this EventHandler<ComponentRenameEventArgs> @delegate)
    {
        return new ComponentRenameEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ComponentRenameEventArgs> ToEventHandler(
        this ComponentRenameEventHandler @delegate)
    {
        return new EventHandler<ComponentRenameEventArgs>(@delegate.Invoke);
    }

    public static DesignerEventHandler ToDesignerEventHandler(
        this EventHandler<DesignerEventArgs> @delegate)
    {
        return new DesignerEventHandler(@delegate.Invoke);
    }

    public static EventHandler<DesignerEventArgs> ToEventHandler(
        this DesignerEventHandler @delegate)
    {
        return new EventHandler<DesignerEventArgs>(@delegate.Invoke);
    }

    public static DesignerTransactionCloseEventHandler ToDesignerTransactionCloseEventHandler(
        this EventHandler<DesignerTransactionCloseEventArgs> @delegate)
    {
        return new DesignerTransactionCloseEventHandler(@delegate.Invoke);
    }

    public static EventHandler<DesignerTransactionCloseEventArgs> ToEventHandler(
        this DesignerTransactionCloseEventHandler @delegate)
    {
        return new EventHandler<DesignerTransactionCloseEventArgs>(@delegate.Invoke);
    }

    public static ResolveNameEventHandler ToResolveNameEventHandler(
        this EventHandler<ResolveNameEventArgs> @delegate)
    {
        return new ResolveNameEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ResolveNameEventArgs> ToEventHandler(
        this ResolveNameEventHandler @delegate)
    {
        return new EventHandler<ResolveNameEventArgs>(@delegate.Invoke);
    }

    public static SettingChangingEventHandler ToSettingChangingEventHandler(
        this EventHandler<SettingChangingEventArgs> @delegate)
    {
        return new SettingChangingEventHandler(@delegate.Invoke);
    }

    public static EventHandler<SettingChangingEventArgs> ToEventHandler(
        this SettingChangingEventHandler @delegate)
    {
        return new EventHandler<SettingChangingEventArgs>(@delegate.Invoke);
    }

    public static SettingsLoadedEventHandler ToSettingsLoadedEventHandler(
        this EventHandler<SettingsLoadedEventArgs> @delegate)
    {
        return new SettingsLoadedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<SettingsLoadedEventArgs> ToEventHandler(
        this SettingsLoadedEventHandler @delegate)
    {
        return new EventHandler<SettingsLoadedEventArgs>(@delegate.Invoke);
    }

    public static SettingsSavingEventHandler ToSettingsSavingEventHandler(
        this EventHandler<CancelEventArgs> @delegate)
    {
        return new SettingsSavingEventHandler(@delegate.Invoke);
    }

    public static EventHandler<CancelEventArgs> ToEventHandler(
        this SettingsSavingEventHandler @delegate)
    {
        return new EventHandler<CancelEventArgs>(@delegate.Invoke);
    }

    public static SettingsSavingEventHandler ToSettingsSavingEventHandler(
        this CancelEventHandler @delegate)
    {
        return new SettingsSavingEventHandler(@delegate.Invoke);
    }

    public static CancelEventHandler ToCancelEventHandler(
        this SettingsSavingEventHandler @delegate)
    {
        return new CancelEventHandler(@delegate.Invoke);
    }

    public static DataReceivedEventHandler ToDataReceivedEventHandler(
        this EventHandler<DataReceivedEventArgs> @delegate)
    {
        return new DataReceivedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<DataReceivedEventArgs> ToEventHandler(
        this DataReceivedEventHandler @delegate)
    {
        return new EventHandler<DataReceivedEventArgs>(@delegate.Invoke);
    }

    public static EntryWrittenEventHandler ToEntryWrittenEventHandler(
        this EventHandler<EntryWrittenEventArgs> @delegate)
    {
        return new EntryWrittenEventHandler(@delegate.Invoke);
    }

    public static EventHandler<EntryWrittenEventArgs> ToEventHandler(
        this EntryWrittenEventHandler @delegate)
    {
        return new EventHandler<EntryWrittenEventArgs>(@delegate.Invoke);
    }

    public static ErrorEventHandler ToErrorEventHandler(
        this EventHandler<ErrorEventArgs> @delegate)
    {
        return new ErrorEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ErrorEventArgs> ToEventHandler(
        this ErrorEventHandler @delegate)
    {
        return new EventHandler<ErrorEventArgs>(@delegate.Invoke);
    }

    public static FileSystemEventHandler ToFileSystemEventHandler(
        this EventHandler<FileSystemEventArgs> @delegate)
    {
        return new FileSystemEventHandler(@delegate.Invoke);
    }

    public static RenamedEventHandler ToRenamedEventHandler(
        this EventHandler<RenamedEventArgs> @delegate)
    {
        return new RenamedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<RenamedEventArgs> ToEventHandler(
        this RenamedEventHandler @delegate)
    {
        return new EventHandler<RenamedEventArgs>(@delegate.Invoke);
    }

    public static SerialDataReceivedEventHandler ToSerialDataReceivedEventHandler(
        this EventHandler<SerialDataReceivedEventArgs> @delegate)
    {
        return new SerialDataReceivedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<SerialDataReceivedEventArgs> ToEventHandler(
        this SerialDataReceivedEventHandler @delegate)
    {
        return new EventHandler<SerialDataReceivedEventArgs>(@delegate.Invoke);
    }

    public static SerialErrorReceivedEventHandler ToSerialErrorReceivedEventHandler(
        this EventHandler<SerialErrorReceivedEventArgs> @delegate)
    {
        return new SerialErrorReceivedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<SerialErrorReceivedEventArgs> ToEventHandler(
        this SerialErrorReceivedEventHandler @delegate)
    {
        return new EventHandler<SerialErrorReceivedEventArgs>(@delegate.Invoke);
    }

    public static SerialPinChangedEventHandler ToSerialPinChangedEventHandler(
        this EventHandler<SerialPinChangedEventArgs> @delegate)
    {
        return new SerialPinChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<SerialPinChangedEventArgs> ToEventHandler(
        this SerialPinChangedEventHandler @delegate)
    {
        return new EventHandler<SerialPinChangedEventArgs>(@delegate.Invoke);
    }

    public static DownloadDataCompletedEventHandler ToDownloadDataCompletedEventHandler(
        this EventHandler<DownloadDataCompletedEventArgs> @delegate)
    {
        return new DownloadDataCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<DownloadDataCompletedEventArgs> ToEventHandler(
        this DownloadDataCompletedEventHandler @delegate)
    {
        return new EventHandler<DownloadDataCompletedEventArgs>(@delegate.Invoke);
    }

    public static DownloadProgressChangedEventHandler ToDownloadProgressChangedEventHandler(
        this EventHandler<DownloadProgressChangedEventArgs> @delegate)
    {
        return new DownloadProgressChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<DownloadProgressChangedEventArgs> ToEventHandler(
        this DownloadProgressChangedEventHandler @delegate)
    {
        return new EventHandler<DownloadProgressChangedEventArgs>(@delegate.Invoke);
    }

    public static DownloadStringCompletedEventHandler ToDownloadStringCompletedEventHandler(
        this EventHandler<DownloadStringCompletedEventArgs> @delegate)
    {
        return new DownloadStringCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<DownloadStringCompletedEventArgs> ToEventHandler(
        this DownloadStringCompletedEventHandler @delegate)
    {
        return new EventHandler<DownloadStringCompletedEventArgs>(@delegate.Invoke);
    }

    public static OpenReadCompletedEventHandler ToOpenReadCompletedEventHandler(
        this EventHandler<OpenReadCompletedEventArgs> @delegate)
    {
        return new OpenReadCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<OpenReadCompletedEventArgs> ToEventHandler(
        this OpenReadCompletedEventHandler @delegate)
    {
        return new EventHandler<OpenReadCompletedEventArgs>(@delegate.Invoke);
    }

    public static OpenWriteCompletedEventHandler ToOpenWriteCompletedEventHandler(
        this EventHandler<OpenWriteCompletedEventArgs> @delegate)
    {
        return new OpenWriteCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<OpenWriteCompletedEventArgs> ToEventHandler(
        this OpenWriteCompletedEventHandler @delegate)
    {
        return new EventHandler<OpenWriteCompletedEventArgs>(@delegate.Invoke);
    }

    public static UploadDataCompletedEventHandler ToUploadDataCompletedEventHandler(
        this EventHandler<UploadDataCompletedEventArgs> @delegate)
    {
        return new UploadDataCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<UploadDataCompletedEventArgs> ToEventHandler(
        this UploadDataCompletedEventHandler @delegate)
    {
        return new EventHandler<UploadDataCompletedEventArgs>(@delegate.Invoke);
    }

    public static UploadFileCompletedEventHandler ToUploadFileCompletedEventHandler(
        this EventHandler<UploadFileCompletedEventArgs> @delegate)
    {
        return new UploadFileCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<UploadFileCompletedEventArgs> ToEventHandler(
        this UploadFileCompletedEventHandler @delegate)
    {
        return new EventHandler<UploadFileCompletedEventArgs>(@delegate.Invoke);
    }

    public static UploadProgressChangedEventHandler ToUploadProgressChangedEventHandler(
        this EventHandler<UploadProgressChangedEventArgs> @delegate)
    {
        return new UploadProgressChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<UploadProgressChangedEventArgs> ToEventHandler(
        this UploadProgressChangedEventHandler @delegate)
    {
        return new EventHandler<UploadProgressChangedEventArgs>(@delegate.Invoke);
    }

    public static UploadStringCompletedEventHandler ToUploadStringCompletedEventHandler(
        this EventHandler<UploadStringCompletedEventArgs> @delegate)
    {
        return new UploadStringCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<UploadStringCompletedEventArgs> ToEventHandler(
        this UploadStringCompletedEventHandler @delegate)
    {
        return new EventHandler<UploadStringCompletedEventArgs>(@delegate.Invoke);
    }

    public static UploadValuesCompletedEventHandler ToUploadValuesCompletedEventHandler(
        this EventHandler<UploadValuesCompletedEventArgs> @delegate)
    {
        return new UploadValuesCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<UploadValuesCompletedEventArgs> ToEventHandler(
        this UploadValuesCompletedEventHandler @delegate)
    {
        return new EventHandler<UploadValuesCompletedEventArgs>(@delegate.Invoke);
    }

    public static SendCompletedEventHandler ToSendCompletedEventHandler(
        this EventHandler<AsyncCompletedEventArgs> @delegate)
    {
        return new SendCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<AsyncCompletedEventArgs> ToEventHandler(
        this SendCompletedEventHandler @delegate)
    {
        return new EventHandler<AsyncCompletedEventArgs>(@delegate.Invoke);
    }

    public static SendCompletedEventHandler ToSendCompletedEventHandler(
        this AsyncCompletedEventHandler @delegate)
    {
        return new SendCompletedEventHandler(@delegate.Invoke);
    }

    public static AsyncCompletedEventHandler ToAsyncCompletedEventHandler(
        this SendCompletedEventHandler @delegate)
    {
        return new AsyncCompletedEventHandler(@delegate.Invoke);
    }

    public static NetworkAddressChangedEventHandler ToNetworkAddressChangedEventHandler(
        this EventHandler<EventArgs> @delegate)
    {
        return new NetworkAddressChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<EventArgs> ToEventHandler(
        this NetworkAddressChangedEventHandler @delegate)
    {
        return new EventHandler<EventArgs>(@delegate.Invoke);
    }

    public static NetworkAddressChangedEventHandler ToNetworkAddressChangedEventHandler(
        this EventHandler @delegate)
    {
        return new NetworkAddressChangedEventHandler(@delegate.Invoke);
    }

    public static NetworkAvailabilityChangedEventHandler ToNetworkAvailabilityChangedEventHandler(
        this EventHandler<NetworkAvailabilityEventArgs> @delegate)
    {
        return new NetworkAvailabilityChangedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<NetworkAvailabilityEventArgs> ToEventHandler(
        this NetworkAvailabilityChangedEventHandler @delegate)
    {
        return new EventHandler<NetworkAvailabilityEventArgs>(@delegate.Invoke);
    }

    public static PingCompletedEventHandler ToPingCompletedEventHandler(
        this EventHandler<PingCompletedEventArgs> @delegate)
    {
        return new PingCompletedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<PingCompletedEventArgs> ToEventHandler(
        this PingCompletedEventHandler @delegate)
    {
        return new EventHandler<PingCompletedEventArgs>(@delegate.Invoke);
    }

    public static ThreadExceptionEventHandler ToThreadExceptionEventHandler(
        this EventHandler<ThreadExceptionEventArgs> @delegate)
    {
        return new ThreadExceptionEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ThreadExceptionEventArgs> ToEventHandler(
        this ThreadExceptionEventHandler @delegate)
    {
        return new EventHandler<ThreadExceptionEventArgs>(@delegate.Invoke);
    }

    public static ElapsedEventHandler ToElapsedEventHandler(
        this EventHandler<ElapsedEventArgs> @delegate)
    {
        return new ElapsedEventHandler(@delegate.Invoke);
    }

    public static EventHandler<ElapsedEventArgs> ToEventHandler(
        this ElapsedEventHandler @delegate)
    {
        return new EventHandler<ElapsedEventArgs>(@delegate.Invoke);
    }
}

Example

static event EventHandler<CancelEventArgs> CustomCancelEvent;
static event CancelEventHandler CustomCancelEvent2;

static void Main()
{
    CustomCancelEvent += new CancelEventHandler((s, e) => {
        Console.WriteLine("Wrapped cancel event handler invoked.");
    }).ToEventHandler();

    CustomCancelEvent(new Object(), new CancelEventArgs(false));

    CustomCancelEvent2 += new EventHandler<CancelEventArgs>((s, e) =>
    {
        Console.WriteLine("Wrapped cancel event type 2 handler invoked.");
    }).ToCancelEventHandler();

    CustomCancelEvent2(new Object(), new CancelEventArgs(true));
}

Author: rkttu

Submitted on: 7 feb. 2016

Language: C#

Type: DelegateCastingExtensions

Views: 4515