Skip to content

Commit

Permalink
Allow generic types in x:Type
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrozsival committed Feb 15, 2024
1 parent a76dd1c commit 73c7894
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
20 changes: 6 additions & 14 deletions src/Controls/src/Build.Tasks/XmlTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,17 @@ static IList<XmlnsDefinitionAttribute> GatherXmlnsDefinitionAttributes(ModuleDef
return xmlnsDefinitions;
}

public static TypeReference GetTypeReference(XamlCache cache, string xmlType, ModuleDefinition module, BaseNode node)
public static TypeReference GetTypeReference(XamlCache cache, string typeName, ModuleDefinition module, BaseNode node)
{
var split = xmlType.Split(':');
if (split.Length > 2)
throw new BuildException(BuildExceptionCode.InvalidXaml, node as IXmlLineInfo, null, xmlType);

string prefix, name;
if (split.Length == 2)
try
{
prefix = split[0];
name = split[1];
XmlType xmlType = TypeArgumentsParser.ParseSingle(typeName, node.NamespaceResolver, (IXmlLineInfo)node);
return GetTypeReference(xmlType, cache, module, node as IXmlLineInfo);
}
else
catch (XamlParseException)
{
prefix = "";
name = split[0];
throw new BuildException(BuildExceptionCode.InvalidXaml, node as IXmlLineInfo, null, typeName);
}
var namespaceuri = node.NamespaceResolver.LookupNamespace(prefix) ?? "";
return GetTypeReference(new XmlType(namespaceuri, name, null), cache, module, node as IXmlLineInfo);
}

public static TypeReference GetTypeReference(XamlCache cache, string namespaceURI, string typename, ModuleDefinition module, IXmlLineInfo xmlInfo)
Expand Down
27 changes: 2 additions & 25 deletions src/Controls/src/Xaml/XamlServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,38 +199,15 @@ internal bool TryResolve(XmlType xmlType, out Type type)

Type Resolve(string qualifiedTypeName, IServiceProvider serviceProvider, out XamlParseException exception)
{
exception = null;
var split = qualifiedTypeName.Split(':');
if (split.Length > 2)
return null;

string prefix, name;
if (split.Length == 2)
{
prefix = split[0];
name = split[1];
}
else
{
prefix = "";
name = split[0];
}

IXmlLineInfo xmlLineInfo = null;
if (serviceProvider != null)
{
if (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) is IXmlLineInfoProvider lineInfoProvider)
xmlLineInfo = lineInfoProvider.XmlLineInfo;
}

var namespaceuri = namespaceResolver.LookupNamespace(prefix);
if (namespaceuri == null)
{
exception = new XamlParseException($"No xmlns declaration for prefix \"{prefix}\"", xmlLineInfo);
return null;
}

return getTypeFromXmlName(new XmlType(namespaceuri, name, null), xmlLineInfo, currentAssembly, out exception);
var xmlType = TypeArgumentsParser.ParseSingle(qualifiedTypeName, namespaceResolver, xmlLineInfo);
return getTypeFromXmlName(xmlType, xmlLineInfo, currentAssembly, out exception);
}

internal delegate Type GetTypeFromXmlName(XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly, out XamlParseException exception);
Expand Down

0 comments on commit 73c7894

Please sign in to comment.