Search Results for

    Show / Hide Table of Contents
    View Source

    Class EventNameExtractor

    There is actually no way to discover an event name in c# at the time of raising the event. It is possible to get the event name from the handler that is being executed based on the event being raised, however that is not what we want in this case. We need to find the event name before it is being raised - you would think that it's possible with reflection or anything but that is not the case, the delegate that defines an event has no info attached to it, it is literally just an event. So what this does is take the sender and event args objects, looks up all public/static events on the sender that have a generic event handler with generic arguments (but only) one, then we match the type of event arguments with the ones being passed in. As it turns out, in our services this will work for the majority of our events! In some cases it may not work and we'll have to supply a string but hopefully this saves a bit of magic strings. We can also write tests to validate these are all working correctly for all services.

    Inheritance
    System.Object
    Namespace: Umbraco.Cms.Core.Events
    Assembly: Umbraco.Core.dll
    Syntax
    public class EventNameExtractor

    Methods

    View Source

    FindEvent(Object, Object, Func<String, Boolean>)

    Finds the event name on the sender that matches the args type

    Declaration
    public static Attempt<EventNameExtractorResult> FindEvent(object sender, object args, Func<string, bool> exclude)
    Parameters
    Type Name Description
    System.Object sender
    System.Object args
    Func<System.String, System.Boolean> exclude

    A filter to exclude matched event names, this filter should return true to exclude the event name from being matched

    Returns
    Type Description
    Attempt<EventNameExtractorResult>

    null if not found or an ambiguous match

    View Source

    FindEvent(Type, Type, Func<String, Boolean>)

    Finds the event name on the sender that matches the args type

    Declaration
    public static Attempt<EventNameExtractorResult> FindEvent(Type senderType, Type argsType, Func<string, bool> exclude)
    Parameters
    Type Name Description
    Type senderType
    Type argsType
    Func<System.String, System.Boolean> exclude

    A filter to exclude matched event names, this filter should return true to exclude the event name from being matched

    Returns
    Type Description
    Attempt<EventNameExtractorResult>

    null if not found or an ambiguous match

    View Source

    FindEvents(Type, Type, Func<String, Boolean>)

    Declaration
    public static string[] FindEvents(Type senderType, Type argsType, Func<string, bool> exclude)
    Parameters
    Type Name Description
    Type senderType
    Type argsType
    Func<System.String, System.Boolean> exclude
    Returns
    Type Description
    System.String[]
    View Source

    MatchIngNames(String)

    Return true if the event is named with an ING name such as "Saving" or "RollingBack"

    Declaration
    public static bool MatchIngNames(string eventName)
    Parameters
    Type Name Description
    System.String eventName
    Returns
    Type Description
    System.Boolean
    View Source

    MatchNonIngNames(String)

    Return true if the event is not named with an ING name such as "Saving" or "RollingBack"

    Declaration
    public static bool MatchNonIngNames(string eventName)
    Parameters
    Type Name Description
    System.String eventName
    Returns
    Type Description
    System.Boolean
    • Improve this Doc
    • View Source
    In This Article
    • Methods
      • FindEvent(Object, Object, Func<String, Boolean>)
      • FindEvent(Type, Type, Func<String, Boolean>)
      • FindEvents(Type, Type, Func<String, Boolean>)
      • MatchIngNames(String)
      • MatchNonIngNames(String)
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX