From b75892e6bc362c0e3fa2120fa2154e9b98bda41b Mon Sep 17 00:00:00 2001 From: "Dr.Rx" Date: Tue, 27 Feb 2018 15:31:36 -0500 Subject: [PATCH] Fix possible null ref in ClassLifecy generation * Fix possible null ref in ClassLifecy generation if the Uno.Core package is not referenced by the target project * Add configuration to ease debugging of the code gen in external projects --- .../Uno.ClassLifecycle.csproj | 1 + .../ClassLifecycleGenerator.cs | 6 +- .../Uno.CodeGen.ClassLifecycle.csproj | 2 + src/Uno.CodeGen/Uno.CodeGen.csproj | 2 + src/Uno.Common.props | 101 +++++------------- src/Uno.Equality/Uno.Equality.csproj | 4 +- src/Uno.Immutables/Uno.Immutables.csproj | 2 + src/crosstargeting_override.props.sample | 32 +++--- 8 files changed, 55 insertions(+), 95 deletions(-) diff --git a/src/Uno.ClassLifecycle/Uno.ClassLifecycle.csproj b/src/Uno.ClassLifecycle/Uno.ClassLifecycle.csproj index 414f9e4..e6cb610 100644 --- a/src/Uno.ClassLifecycle/Uno.ClassLifecycle.csproj +++ b/src/Uno.ClassLifecycle/Uno.ClassLifecycle.csproj @@ -20,4 +20,5 @@ This package is part of the Uno.CodeGen to generate object life cycle methods in https://nv-assets.azurewebsites.net/logos/uno.png + diff --git a/src/Uno.CodeGen.ClassLifecycle/ClassLifecycleGenerator.cs b/src/Uno.CodeGen.ClassLifecycle/ClassLifecycleGenerator.cs index 5a711ad..0d24642 100644 --- a/src/Uno.CodeGen.ClassLifecycle/ClassLifecycleGenerator.cs +++ b/src/Uno.CodeGen.ClassLifecycle/ClassLifecycleGenerator.cs @@ -53,7 +53,7 @@ namespace Uno.CodeGen.ClassLifecycle _finalizerAttribute = context.Compilation.GetTypeByMetadataName("Uno.FinalizerMethodAttribute"); _iDisposable_Dispose = context.Compilation.GetTypeByMetadataName("System.IDisposable").GetMembers("Dispose").Single(); - _extentibleDisposable_RegisterExtension = context.Compilation.GetTypeByMetadataName("Uno.Disposables.IExtensibleDisposable").GetMembers("RegisterExtension").SingleOrDefault(); + _extentibleDisposable_RegisterExtension = context.Compilation.GetTypeByMetadataName("Uno.Disposables.IExtensibleDisposable")?.GetMembers("RegisterExtension").SingleOrDefault(); foreach (var methods in GetLifecycleMethods()) { @@ -356,7 +356,9 @@ namespace Uno.CodeGen.ClassLifecycle .JoinByEmpty(); var iDisposableImplementation = methods.Owner.FindImplementationForInterfaceMember(_iDisposable_Dispose); - var iExtensibleDisposableImplementation = methods.Owner.FindImplementationForInterfaceMember(_extentibleDisposable_RegisterExtension) as IMethodSymbol; + var iExtensibleDisposableImplementation = _extentibleDisposable_RegisterExtension == null + ? default(IMethodSymbol) + : methods.Owner.FindImplementationForInterfaceMember(_extentibleDisposable_RegisterExtension) as IMethodSymbol; var (patternKind, patternMethod) = methods.Owner.GetDisposablePatternImplementation(); var (disposeKind, disposeMethod) = methods.Owner.GetDisposableImplementation(); diff --git a/src/Uno.CodeGen.ClassLifecycle/Uno.CodeGen.ClassLifecycle.csproj b/src/Uno.CodeGen.ClassLifecycle/Uno.CodeGen.ClassLifecycle.csproj index 881f20e..d2475b0 100644 --- a/src/Uno.CodeGen.ClassLifecycle/Uno.CodeGen.ClassLifecycle.csproj +++ b/src/Uno.CodeGen.ClassLifecycle/Uno.CodeGen.ClassLifecycle.csproj @@ -19,6 +19,8 @@ This package is part of the Uno.CodeGen to generate classes lifecycle methods in https://github.com/nventive/Uno.CodeGen https://nv-assets.azurewebsites.net/logos/uno.png + + diff --git a/src/Uno.CodeGen/Uno.CodeGen.csproj b/src/Uno.CodeGen/Uno.CodeGen.csproj index bf231eb..8f89017 100644 --- a/src/Uno.CodeGen/Uno.CodeGen.csproj +++ b/src/Uno.CodeGen/Uno.CodeGen.csproj @@ -13,6 +13,8 @@ This package provides tooling for code generation. Copyright (C) 2015-2018 nventive inc. - all rights reserved + + diff --git a/src/Uno.Common.props b/src/Uno.Common.props index fe64502..1a9da4b 100644 --- a/src/Uno.Common.props +++ b/src/Uno.Common.props @@ -1,81 +1,34 @@ + - - $(UnoDefineConstants);HAS_GEOCOORDINATE_WATCHER;HAS_GEOCOORDINATE;HAS_COMPILED_REGEX;USE_FAST_REPLAYONE - $(UnoDefineConstants);HAS_SEMAPHORE - $(UnoDefineConstants);HAS_FILE_IO - $(UnoDefineConstants);HAS_THREADS - - - - $(UnoDefineConstants);WINDOWS_UAP;WINDOWS_UWP + - $(UnoDefineConstants);HAS_WINDOWS_UI;HAS_TOP_APPBAR;HAS_BOTTOM_APPBAR - $(UnoDefineConstants);HAS_VIEWSIZE_PREFERENCE - $(UnoDefineConstants);HAS_GEOPOSITION - $(UnoDefineConstants);USE_SINGLE_ITEM_COLLECTIONCHANGED + + <_OverrideTargetFramework>$(TargetFramework) + <_TargetNugetFolder Condition="'$(IsTool)'=='true' AND '$(TargetFramework)' == 'net46'">$(USERPROFILE)\.nuget\packages\$(AssemblyName)\$(NugetOverrideVersion)\tools + <_TargetNugetFolder Condition="'$(IsTool)'!='true'">$(USERPROFILE)\.nuget\packages\$(AssemblyName)\$(NugetOverrideVersion)\lib\$(_OverrideTargetFramework) + + + <_OutputFiles Include="@(BuiltProjectOutputGroupOutput)" /> + <_OutputFilesPDB Include="@(_OutputFiles->'%(RootDir)\%(Directory)\%(RecursiveDir)%(Filename).pdb')" Condition="Exists('@(BuiltProjectOutputGroupOutput->'%(RootDir)\%(Directory)\%(RecursiveDir)%(Filename).pdb')')" /> + + + - $(UnoDefineConstants);NETFX_CORE - $(UnoDefineConstants);METRO - $(UnoDefineConstants);WINRT - $(UnoDefineConstants);HAS_WINRT_FILEIO;HAS_QUERYOPTIONS;HAS_CRIPPLEDREFLECTION;HAS_TYPEINFO;USE_FAST_REPLAYONE - $(UnoDefineConstants);HAS_ISTORAGEFILE - $(UnoDefineConstants);HAS_NATIVE_SYSTEMINFO - $(UnoDefineConstants);HAS_ISTORAGEFILE_ADVANCED - $(UnoDefineConstants);HAS_GEOLOCATOR - $(UnoDefineConstants);HAS_SEMAPHORE - $(UnoDefineConstants);HAS_HTTPCLIENT - $(UnoDefineConstants);HAS_DATACONTEXTCHANGED - $(UnoDefineConstants);HAS_HARDWARE_BUTTONS - $(UnoDefineConstants);HAS_TYPEINFO_EXTENSIONS - $(UnoDefineConstants);HAS_CAMERA_CAPTURE_UI - $(UnoDefineConstants);HAS_FILE_IO - - - $(UnoDefineConstants);XAMARIN;XAMARIN_IOS - $(UnoDefineConstants);HAS_COMPILED_REGEX;HAS_CRIPPLEDREFLECTION;USE_FAST_REPLAYONE - $(UnoDefineConstants);HAS_QUERY_OPTIONS - $(UnoDefineConstants);HAS_BROKEN_SEMAPHORE_SLIM - $(UnoDefineConstants);HAS_SEMAPHORE - $(UnoDefineConstants);HAS_NO_CONCURRENT_DICT - - $(UnoDefineConstants);HAS_FILE_IO - $(UnoDefineConstants);HAS_THREADS - $(UnoDefineConstants);NO_DNSENDPOINT - - - $(UnoDefineConstants);XAMARIN;XAMARIN_ANDROID + + - $(UnoDefineConstants);HAS_COMPILED_REGEX;HAS_CRIPPLEDREFLECTION;USE_FAST_REPLAYONE - $(UnoDefineConstants);HAS_BROKEN_SEMAPHORE_SLIM - $(UnoDefineConstants);HAS_SEMAPHORE - $(UnoDefineConstants);HAS_NO_WINDOWS_DISPATCHER - $(UnoDefineConstants);HAS_HTTPCLIENT - $(UnoDefineConstants);HAS_NO_CONCURRENT_DICT - - $(UnoDefineConstants);HAS_FILE_IO - $(UnoDefineConstants);HAS_THREADS - $(UnoDefineConstants);NO_DNSENDPOINT - - - $(UnoDefineConstants);XAMARIN;XAMARIN_ANDROID - - $(UnoDefineConstants);HAS_COMPILED_REGEX;HAS_CRIPPLEDREFLECTION;USE_FAST_REPLAYONE - $(UnoDefineConstants);HAS_BROKEN_SEMAPHORE_SLIM - $(UnoDefineConstants);HAS_SEMAPHORE - $(UnoDefineConstants);HAS_NO_WINDOWS_DISPATCHER - $(UnoDefineConstants);HAS_HTTPCLIENT - $(UnoDefineConstants);HAS_NO_CONCURRENT_DICT - - $(UnoDefineConstants);HAS_FILE_IO - $(UnoDefineConstants);HAS_THREADS - $(UnoDefineConstants);NO_DNSENDPOINT - - - - - - - + + + \ No newline at end of file diff --git a/src/Uno.Equality/Uno.Equality.csproj b/src/Uno.Equality/Uno.Equality.csproj index bb80f08..7809001 100644 --- a/src/Uno.Equality/Uno.Equality.csproj +++ b/src/Uno.Equality/Uno.Equality.csproj @@ -19,5 +19,7 @@ This package is part of the Uno.CodeGen to generate equality members in your pro https://github.com/nventive/Uno.CodeGen https://nv-assets.azurewebsites.net/logos/uno.png - + + + diff --git a/src/Uno.Immutables/Uno.Immutables.csproj b/src/Uno.Immutables/Uno.Immutables.csproj index 33b3fde..8abfa93 100644 --- a/src/Uno.Immutables/Uno.Immutables.csproj +++ b/src/Uno.Immutables/Uno.Immutables.csproj @@ -19,6 +19,8 @@ This package is part of the Uno.CodeGen to generate immutable entities in your p https://nv-assets.azurewebsites.net/logos/uno.png Copyright (C) 2015-2018 nventive inc. - all rights reserved + + diff --git a/src/crosstargeting_override.props.sample b/src/crosstargeting_override.props.sample index c40e7cd..46e3ee8 100644 --- a/src/crosstargeting_override.props.sample +++ b/src/crosstargeting_override.props.sample @@ -1,24 +1,20 @@ - - - Original frameworks: Xamarin.iOS10;MonoAndroid71;uap10.0;net46 + + - net46;Xamarin.iOS10 - - - - + + + \ No newline at end of file