Skip to content

Commit

Permalink
Bugfix - Nullable reference type
Browse files Browse the repository at this point in the history
  • Loading branch information
rrmanzano committed Dec 7, 2022
1 parent 3ac5cfd commit d620fdb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void ProcessBindableProperty(CodeWriter w, IFieldSymbol fieldSymbol, ISy
var applyHidesUnderlying = fieldSymbol.GetValue<bool>(attributeSymbol, AutoBindableConstants.AttrHidesUnderlyingProperty);
var hidesUnderlying = applyHidesUnderlying ? " new" : string.Empty;
var declaringType = fieldType.WithNullableAnnotation(NullableAnnotation.None);
var parameters = $"nameof({propertyName}),typeof({declaringType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)}),typeof({classSymbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)}){customParameters}".Split(',');
var parameters = $"nameof({propertyName}),typeof({declaringType.ToDisplayString(CommonSymbolDisplayFormat.DefaultFormat)}),typeof({classSymbol.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)}){customParameters}".Split(',');

w._(AttributeBuilder.GetAttrGeneratedCodeString());
w._($@"public static{hidesUnderlying} readonly {AutoBindableConstants.FullNameMauiControls}.BindableProperty {bindablePropertyName} =");
Expand All @@ -116,9 +116,9 @@ private void ProcessBindableProperty(CodeWriter w, IFieldSymbol fieldSymbol, ISy

w._();
AttributeBuilder.WriteAllAttrGeneratedCodeStrings(w);
using (w.B(@$"public{hidesUnderlying} {fieldType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} {propertyName}"))
using (w.B(@$"public{hidesUnderlying} {fieldType.ToDisplayString(CommonSymbolDisplayFormat.DefaultFormat)} {propertyName}"))
{
w._($@"get => ({fieldType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)})GetValue({bindablePropertyName});");
w._($@"get => ({fieldType.ToDisplayString(CommonSymbolDisplayFormat.DefaultFormat)})GetValue({bindablePropertyName});");
if (this.ExistsBodySetter())
{
using (w.B(@$"set"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public string ProcessBindableParameters()
return default;
});

return defaultValue != null ? $"defaultValue: {defaultValue}" : $"defaultValue: default({fieldType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)})";
return defaultValue != null ? $"defaultValue: {defaultValue}" : $"defaultValue: default({fieldType.ToDisplayString(CommonSymbolDisplayFormat.DefaultFormat)})";
}

public void ProcessBodySetter(CodeWriter w)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void ProcessImplementationLogic(CodeWriter w)
var methods = this.GetMethodsToCall(methodName);
if (methods.Any())
{
w._($@"var ctrl = ({this.ClassSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)})bindable;");
w._($@"var ctrl = ({this.ClassSymbol.ToDisplayString(CommonSymbolDisplayFormat.DefaultFormat)})bindable;");
methods.ToList().ForEach(m => {
var count = m.Parameters.Count();
if (count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void ProcessImplementationLogic(CodeWriter w)
AttributeBuilder.WriteAllAttrGeneratedCodeStrings(w);
using (w.B(methodDefinition))
{
w._($@"var ctrl = ({this.ClassSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)})bindable;");
w._($@"var ctrl = ({this.ClassSymbol.ToDisplayString(CommonSymbolDisplayFormat.DefaultFormat)})bindable;");
w._($@"return ctrl.{methodName}(ctrl, ({this.FieldSymbol.Type})value);");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.CodeAnalysis;

namespace Maui.BindableProperty.Generator.Helpers;

internal static class CommonSymbolDisplayFormat
{
public static SymbolDisplayFormat DefaultFormat { get; } =
new SymbolDisplayFormat(
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included,
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
miscellaneousOptions:
SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
SymbolDisplayMiscellaneousOptions.UseSpecialTypes |
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Description>Source generator that automatically transforms fields into BindableProperties that can be used in MAUI</Description>
<PackageTags>MAUI;BindableProperty;Source Generator</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<VersionPrefix>0.9.2</VersionPrefix>
<VersionPrefix>0.9.3</VersionPrefix>
<PackageProjectUrl>https://github.com/rrmanzano/maui-bindableproperty-generator</PackageProjectUrl>
<RepositoryUrl>https://github.com/rrmanzano/maui-bindableproperty-generator</RepositoryUrl>
<PackageId>M.BindableProperty.Generator</PackageId>
Expand Down

0 comments on commit d620fdb

Please sign in to comment.