kekekeks / XamlX

General purpose pluggable XAML compiler with no runtime dependencies.
MIT License
319 stars 55 forks source link

IXamlMethod Generic definition #112

Closed workgroupengineering closed 3 months ago

workgroupengineering commented 7 months ago

HI, in the pr https://github.com/AvaloniaUI/Avalonia/pull/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:

What do you think is the best solution?

kekekeks commented 7 months ago

The general idea of our type system abstraction is to mirror SRE APIs, since those are the most convenient to use. So 2+3 would make the most sense.

workgroupengineering commented 6 months ago

Do I add 2+3 to IXamlMethod or create IXamlGenericMethod?

maxkatz6 commented 6 months ago

I would say, adding these to IXamlMethod.