Skip to content

Commit

Permalink
Added support to "Nullable Reference Types"
Browse files Browse the repository at this point in the history
  • Loading branch information
rrmanzano committed Jun 29, 2022
1 parent 9e72cc1 commit f4f8727
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ public partial class HeaderControl : ContentView
#pragma warning disable CS0169

[AutoBindable(OnChanged = nameof(UpdateDisplayName))]
private readonly string _firstName;
private readonly string _firstName = string.Empty;

[AutoBindable(PropertyName = "LastName", OnChanged = nameof(UpdateDisplayName))]
private readonly string _l;
private readonly string? _l;

[AutoBindable(DefaultValue = "DateTime.Now", OnChanged = nameof(OnDateTimeChanged))]
private readonly DateTime _birthDate;
private readonly DateTime? _birthDate;

[AutoBindable(DefaultValue = "USA")]
private readonly string _country;
private readonly string? _country;

[AutoBindable]
private readonly string _displayName;
private readonly string? _displayName;

[AutoBindable(HidesUnderlyingProperty = true, DefaultValue = "Color.FromArgb(\"#bdbde6\")")]
private readonly Color _backgroundColor;
private readonly Color? _backgroundColor;

#pragma warning restore CS0169

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@

<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>Maui.BindableProperty.Generator.Demo</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>Maui.BindableProperty.Generator.Demo</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.companyname.maui.bindableproperty.generator.demo</ApplicationId>
<ApplicationId Condition="$(TargetFramework.Contains('-windows'))">56B93871-1567-4D86-A631-1A7B77E4A84D</ApplicationId>
<ApplicationIdGuid>56B93871-1567-4D86-A631-1A7B77E4A84D</ApplicationIdGuid>

<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -46,24 +50,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="1.0.0-pre9" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview3" />
<PackageReference Include="CommunityToolkit.Maui" Version="1.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MAUI.BindableProperty.Generator\Maui.BindableProperty.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<Compile Update="CustomControls\HeaderControl.xaml.cs">
<DependentUpon>HeaderControl.xaml</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<MauiXaml Update="CustomControls\HeaderControl.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class MainViewModel : ObservableObject

public MainViewModel(){}

[ICommand]
[RelayCommand]
private void LogClicked()
{
System.Diagnostics.Debug.WriteLine(@$"FirstName -> {this.FirstName}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ private void ProcessBindableProperty(CodeWriter w, IFieldSymbol fieldSymbol, ISy
var customParameters = this.ProcessBindableParameters();
var applyHidesUnderlying = fieldSymbol.GetValue<bool>(attributeSymbol, AutoBindableConstants.AttrHidesUnderlyingProperty);
var hidesUnderlying = applyHidesUnderlying ? " new" : string.Empty;
var parameters = $"nameof({propertyName}),typeof({fieldType}),typeof({classSymbol.Name}){customParameters}".Split(',');
var declaringType = fieldType.WithNullableAnnotation(NullableAnnotation.None);
var parameters = $"nameof({propertyName}),typeof({declaringType}),typeof({classSymbol.Name}){customParameters}".Split(',');
w._(AutoBindableConstants.AttrGeneratedCodeString);
w._($@"public static{hidesUnderlying} readonly {AutoBindableConstants.FullNameMauiControls}.BindableProperty {bindablePropertyName} =");
w._($"{w.GetIndentString(6)}{AutoBindableConstants.FullNameMauiControls}.BindableProperty.Create(");
Expand Down
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.7.0</VersionPrefix>
<VersionPrefix>0.8.0</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 f4f8727

Please sign in to comment.