Skip to content

IXamlMethod Generic definition #112

@workgroupengineering

Description

@workgroupengineering

HI,
in the pr AvaloniaUI/Avalonia#15274. I have need to retrieve Interactive.AddHandler<TEventArgs> method. To do this, I tried using IXamlType.FindMethod and checking if the method name is AddHandler`1 without success.

After investigation I found following workaround

https://github.com/AvaloniaUI/Avalonia/blob/3f82e64c469198d3e80557b7c3c5071a8c29d806/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs#L155-L163

                AddHandlerT = Interactive.FindMethod(m => m.IsPublic
                    && !m.IsStatic
                    && m.Name == "AddHandler"
                    && m.Parameters.Count == 4
                    && RoutedEvent.IsAssignableFrom(m.Parameters[0])
                    && m.Parameters[0].GenericArguments?.Count == 1 // This is specific this case  workaround to check is generici method
                    && (cfg.WellKnownTypes.Delegate).IsAssignableFrom(m.Parameters[1])
                    && m.Parameters[2].IsEnum
                    && m.Parameters[3].Equals(cfg.WellKnownTypes.Boolean) == true

I would like to make a PR that makes it easier to identify the generic method. There are a few possibilities:

  • Add `n to the end of name of generic method, where n is number of generic arguments
  • Add property IsGenericDef to IXamlMethod
  • Expose GenericArguments and GenericParameters
  • All three previous proposed solutions

What do you think is the best solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions