Repository: dotnet/maui
File: src/Controls/src/BindingSourceGen/ITypeSymbolExtensions.cs (C#)

Code before:
		{
			// Strips the "?" from the type name
			return ((INamedTypeSymbol)typeSymbol).TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
		}

		return typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
	}

	/// <summary>
	/// Checks if a property name could be generated by CommunityToolkit.Mvvm's [RelayCommand] attribute,
	/// and returns the inferred command type if found.
	/// </summary>
	/// <param name="symbol">The type to search</param>
	/// <param name="propertyName">The name of the property to find (should end with "Command")</param>
	/// <param name="compilation">The compilation (can be null)</param>
	/// <param name="commandType">The inferred ICommand type if a RelayCommand method is found</param>
	/// <returns>True if a RelayCommand method was found that would generate this property</returns>
	public static bool TryGetRelayCommandPropertyType(this ITypeSymbol symbol, string propertyName, Compilation? compilation, out ITypeSymbol? commandType)
	{
		commandType = null;

		if (compilation == null)
			return false;

		// Check if the property name ends with "Command"
		if (!propertyName.EndsWith("Command", System.StringComparison.Ordinal) || propertyName.Length <= "Command".Length)
			return false;

		// Extract the method name (property name without "Command" suffix)
		var methodName = propertyName.Substring(0, propertyName.Length - "Command".Length);
		
		// Look for a method with the base name - search in the type and base types
		var methods = GetAllMethods(symbol, methodName);
		
		foreach (var method in methods)
		{
			// Check if the method has the RelayCommand attribute
			var hasRelayCommand = method.GetAttributes().Any(attr =>
				attr.AttributeClass?.Name == "RelayCommandAttribute" ||
				attr.AttributeClass?.ToDisplayString() == "CommunityToolkit.Mvvm.Input.RelayCommandAttribute");

			if (hasRelayCommand)
			{
				// Try to find the ICommand interface type
				var icommandType = compilation.GetTypeByMetadataName("System.Windows.Input.ICommand");
				if (icommandType != null)
				{
					commandType = icommandType;
					return true;
				}
			}

Review comment (suggestion):
is `propertyName.Length <= "Command".Length` needed? if `propertyName` ends with `Command`, the condition will always be evaluated to `false`.

Code after:
		{
			// Strips the "?" from the type name
			return ((INamedTypeSymbol)typeSymbol).TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
		}

		return typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
	}

	/// <summary>
	/// Checks if a property name could be generated by CommunityToolkit.Mvvm's [RelayCommand] attribute,
	/// and returns the inferred command type if found.
	/// </summary>
	/// <param name="symbol">The type to search</param>
	/// <param name="propertyName">The name of the property to find (should end with "Command")</param>
	/// <param name="compilation">The compilation (can be null)</param>
	/// <param name="commandType">The inferred ICommand type if a RelayCommand method is found</param>
	/// <returns>True if a RelayCommand method was found that would generate this property</returns>
	public static bool TryGetRelayCommandPropertyType(this ITypeSymbol symbol, string propertyName, Compilation? compilation, out ITypeSymbol? commandType)
	{
		commandType = null;

		if (compilation == null)
			return false;

		// Check if the property name ends with "Command"
		if (!propertyName.EndsWith("Command", System.StringComparison.Ordinal))
			return false;

		// Extract the method name (property name without "Command" suffix)
		var methodName = propertyName.Substring(0, propertyName.Length - "Command".Length);
		
		// Look for a method with the base name - search in the type and base types
		var methods = GetAllMethods(symbol, methodName);
		
		foreach (var method in methods)
		{
			// Check if the method has the RelayCommand attribute
			var hasRelayCommand = method.GetAttributes().Any(attr =>
				attr.AttributeClass?.Name == "RelayCommandAttribute" ||
				attr.AttributeClass?.ToDisplayString() == "CommunityToolkit.Mvvm.Input.RelayCommandAttribute");

			if (hasRelayCommand)
			{
				// Try to find the ICommand interface type
				var icommandType = compilation.GetTypeByMetadataName("System.Windows.Input.ICommand");
				if (icommandType != null)
				{
					commandType = icommandType;
					return true;
				}
			}