@ -85,10 +85,10 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions
{
{
return transformed ;
return transformed ;
}
}
var lastElement = transformed . Elements . LastOrDefault ( ) ;
var lastElement = transformed . Elements . LastOrDefault ( ) ;
if ( parentNode . Property ? . Getter ? . ReturnType = = context . GetAvaloniaTypes ( ) . ICommand & & lastElement is XamlIlClrMethodPathElementNode methodPathElement )
if ( GetPropertyType ( context , parentNode ) = = context . GetAvaloniaTypes ( ) . ICommand & & lastElement is XamlIlClrMethodPathElementNode methodPathElement )
{
{
IXamlMethod executeMethod = methodPathElement . Method ;
IXamlMethod executeMethod = methodPathElement . Method ;
IXamlMethod canExecuteMethod = executeMethod . DeclaringType . FindMethod ( new FindMethodMethodSignature ( $"Can{executeMethod.Name}" , context . Configuration . WellKnownTypes . Boolean , context . Configuration . WellKnownTypes . Object ) ) ;
IXamlMethod canExecuteMethod = executeMethod . DeclaringType . FindMethod ( new FindMethodMethodSignature ( $"Can{executeMethod.Name}" , context . Configuration . WellKnownTypes . Boolean , context . Configuration . WellKnownTypes . Object ) ) ;
@ -110,6 +110,29 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions
return transformed ;
return transformed ;
}
}
private static IXamlType GetPropertyType ( AstTransformationContext context , XamlPropertyAssignmentNode node )
{
var setterType = context . GetAvaloniaTypes ( ) . Setter ;
if ( node . Property . DeclaringType = = setterType & & node . Property . Name = = "Value" )
{
// The property is a Setter.Value property. We need to get the type of the property that the Setter.Value property is setting.
var setter = context . ParentNodes ( )
. SkipWhile ( x = > x ! = node )
. OfType < XamlAstConstructableObjectNode > ( )
. Take ( 1 )
. FirstOrDefault ( x = > x . Type . GetClrType ( ) = = setterType ) ;
var propertyAssignment = setter ? . Children . OfType < XamlPropertyAssignmentNode > ( )
. FirstOrDefault ( x = > x . Property . GetClrProperty ( ) . Name = = "Property" ) ;
var property = propertyAssignment ? . Values . FirstOrDefault ( ) as IXamlIlAvaloniaPropertyNode ;
if ( property . AvaloniaPropertyType is { } propertyType )
return propertyType ;
}
return node . Property ? . Getter ? . ReturnType ;
}
private static XamlIlBindingPathNode TransformBindingPath ( AstTransformationContext context , IXamlLineInfo lineInfo , Func < IXamlType > startTypeResolver , IXamlType selfType , IEnumerable < BindingExpressionGrammar . INode > bindingExpression )
private static XamlIlBindingPathNode TransformBindingPath ( AstTransformationContext context , IXamlLineInfo lineInfo , Func < IXamlType > startTypeResolver , IXamlType selfType , IEnumerable < BindingExpressionGrammar . INode > bindingExpression )
{
{
List < IXamlIlBindingPathElementNode > transformNodes = new List < IXamlIlBindingPathElementNode > ( ) ;
List < IXamlIlBindingPathElementNode > transformNodes = new List < IXamlIlBindingPathElementNode > ( ) ;