未验证 提交 3da1a742 编写于 作者: J Jérôme Laban 提交者: GitHub

Merge pull request #11840 from Youssef1313/generator-displaystring

perf: Fix few more occurrences of ToDisplayString
......@@ -143,7 +143,7 @@ namespace Uno.UI.SourceGenerators.XamlGenerator.Utils
return typeName;
}
return typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
return typeSymbol.GetFullyQualifiedTypeIncludingGlobal();
}
public override SyntaxNode? VisitIdentifierName(IdentifierNameSyntax node)
......@@ -197,8 +197,7 @@ namespace Uno.UI.SourceGenerators.XamlGenerator.Utils
{
_contextName = contextName;
_contextTypeSymbol = contextTypeSymbol;
// TODO: Modify after https://github.com/unoplatform/uno/pull/11531 is merged.
_contextTypeString = contextTypeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
_contextTypeString = contextTypeSymbol.GetFullyQualifiedTypeIncludingGlobal();
// We need to take globalNamespace from the compilation itself.
// Walking ContainingNamespaces from contextTypeSymbol or
......
......@@ -30,8 +30,7 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
record XClassName(string Namespace, string ClassName, INamedTypeSymbol? Symbol)
{
public override string ToString()
=> Symbol?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat.WithGlobalNamespaceStyle(SymbolDisplayGlobalNamespaceStyle.Included))
?? Namespace + "." + ClassName;
=> Symbol?.GetFullyQualifiedTypeIncludingGlobal() ?? Namespace + "." + ClassName;
}
private void InitCaches()
......@@ -73,16 +72,16 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
private string GetGlobalizedTypeName(XamlType type)
{
var fullTypeName = type.Name;
var knownType = FindType(type);
if (knownType == null && type.PreferredXamlNamespace.StartsWith("using:", StringComparison.Ordinal))
if (knownType is not null)
{
fullTypeName = type.PreferredXamlNamespace.TrimStart("using:") + "." + type.Name;
return knownType.GetFullyQualifiedTypeIncludingGlobal();
}
if (knownType != null)
var fullTypeName = type.Name;
if (type.PreferredXamlNamespace.StartsWith("using:", StringComparison.Ordinal))
{
// Override the using with the type that was found in the list of loaded assemblies
fullTypeName = knownType.ToDisplayString();
fullTypeName = type.PreferredXamlNamespace.Substring("using:".Length) + "." + type.Name;
}
return GetGlobalizedTypeName(fullTypeName);
......@@ -444,7 +443,7 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
}
var setMethod = type?.GetFirstMethodWithName("Set" + name);
if (setMethod is { IsStatic: true, Parameters: { Length: 2 } })
if (setMethod is { IsStatic: true, Parameters.Length: 2 })
{
return true;
}
......@@ -944,6 +943,6 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
private bool IsTypeImplemented(INamedTypeSymbol type) => _isTypeImplemented(type);
private static bool SourceIsTypeImplemented(INamedTypeSymbol type)
=> type.GetAttributes().None(a => a.AttributeClass?.ToDisplayString() == XamlConstants.Types.NotImplementedAttribute);
=> type.GetAttributes().None(a => a.AttributeClass?.GetFullyQualifiedTypeExcludingGlobal() == XamlConstants.Types.NotImplementedAttribute);
}
}
......@@ -2,7 +2,6 @@
using Uno.Extensions;
using Uno.MsBuildTasks.Utils;
using Uno.MsBuildTasks.Utils.XamlPathParser;
using Uno.UI.SourceGenerators.XamlGenerator.Utils;
using System;
using System.Collections.Generic;
......@@ -22,7 +21,6 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Uno.UI.SourceGenerators.Helpers;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Text;
using Microsoft.CodeAnalysis.Text;
......@@ -1108,7 +1106,6 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
using (writer.BlockInvariant($"Loading += (s, e) => "))
{
if (_isHotReloadEnabled && _xClassName.Symbol != null)
{
writer.AppendLineIndented($"var __that = global::Uno.UI.Helpers.MarkupHelper.GetElementProperty<{_xClassName.Symbol?.GetFullyQualifiedTypeIncludingGlobal()}>(s, \"owner\");");
}
......@@ -3693,18 +3690,12 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
}
// Local function used to build a property/value for any custom MarkupExtensions
void BuildCustomMarkupExtensionPropertyValue(IIndentedStringBuilder writer, XamlMemberDefinition member, string? closure = null)
void BuildCustomMarkupExtensionPropertyValue(IIndentedStringBuilder writer, XamlMemberDefinition member, string closure)
{
Func<string, string> formatLine = assignment => !closure.IsNullOrEmpty()
? $"{closure}.{assignment};\r\n"
: assignment;
var propertyValue = GetCustomMarkupExtensionValue(member, closure);
if (!propertyValue.IsNullOrEmpty())
{
var formatted = formatLine($"{member.Member.Name} = {propertyValue}");
writer.AppendIndented(formatted);
writer.AppendIndented($"{closure}.{member.Member.Name} = {propertyValue};\r\n");
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册