Skip to content

Commit

Permalink
fix: XamlGenerator compare symbols instead of names
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Oct 14, 2020
1 parent 8a2e9c8 commit 86a9169
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,33 @@ private bool IsType(XamlType xamlType, string typeName)
break;
}

} while (type.Name != "Object");
} while (!Equals(type, _objectSymbol));
}

return false;
}

private bool IsType(XamlType xamlType, ISymbol typeSymbol)
{
var type = FindType(xamlType);

if (type != null)
{
do
{
if (Equals(type, typeSymbol))
{
return true;
}

type = type.BaseType;

if (type == null)
{
break;
}

} while (!Equals(type, _objectSymbol));
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ internal partial class XamlFileGenerator
private readonly INamedTypeSymbol _dependencyObjectSymbol;
private readonly INamedTypeSymbol _markupExtensionSymbol;
private readonly INamedTypeSymbol _dependencyObjectParseSymbol;
private readonly INamedTypeSymbol _androidContentContextSymbol; // Android.Content.Context
private readonly INamedTypeSymbol _androidViewSymbol; // Android.Views.View

private readonly INamedTypeSymbol _iCollectionSymbol;
private readonly INamedTypeSymbol _iCollectionOfTSymbol;
Expand Down Expand Up @@ -226,6 +228,8 @@ bool isUnoAssembly
_dataBindingSymbol = GetType("Windows.UI.Xaml.Data.Binding");
_styleSymbol = GetType(XamlConstants.Types.Style);
_colorSymbol = GetType(XamlConstants.Types.Color);
_androidContentContextSymbol = GetType("Android.Content.Context");
_androidViewSymbol = GetType("Android.Views.View");

_markupExtensionTypes = _metadataHelper.GetAllTypesDerivingFrom(_markupExtensionSymbol).ToList();
_xamlConversionTypes = _metadataHelper.GetAllTypesAttributedWith(GetType(XamlConstants.Types.CreateFromStringAttribute)).ToList();
Expand Down Expand Up @@ -5113,7 +5117,7 @@ private void BuildChildThroughSubclass(IIndentedStringBuilder writer, XamlMember

private string GenerateConstructorParameters(XamlType xamlType)
{
if (IsType(xamlType, "Android.Views.View"))
if (IsType(xamlType, _androidViewSymbol))
{
// For android, all native control must take a context as their first parameters
// To be able to use this control from the Xaml, we need to generate a constructor
Expand All @@ -5125,7 +5129,7 @@ private string GenerateConstructorParameters(XamlType xamlType)
{
var q = from m in type.Constructors
where m.Parameters.Count() == 1
where m.Parameters.First().Type.ToDisplayString() == "Android.Content.Context"
where Equals(m.Parameters.First().Type, _androidContentContextSymbol)
select m;

var hasContextConstructor = q.Any();
Expand Down

0 comments on commit 86a9169

Please sign in to comment.