Merge pull request #129 from unoplatform/dev/jela/is-auto-property

fix: Remove depedency on internal IsAutoProperty, TupleTypeSymbol
This commit is contained in:
Jérôme Laban 2020-07-19 22:13:05 -04:00 коммит произвёл GitHub
Родитель 9ea2eb8d0a 6bdac44752
Коммит 81f6ca7367
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 68 добавлений и 42 удалений

Просмотреть файл

@ -1,33 +1,54 @@
assembly-versioning-scheme: MajorMinorPatch
mode: ContinuousDeployment
next-version: 1.33.0
continuous-delivery-fallback-tag: ""
mode: Mainline
next-version: 1.34.0
branches:
master:
mode: ContinuousDeployment
regex: master
tag: dev
increment: none
increment: Minor
is-source-branch-for: ['beta', 'stable']
pull-request:
regex: ^(pull|pull\-requests|pr)[/-]
mode: ContinuousDeployment
tag: 'PullRequest'
tag-number-pattern: '[/-](?<number>\d+)[-/]'
increment: Inherit
beta:
regex: release/beta/
tag: 'beta'
mode: ContinuousDeployment
regex: ^release/beta/.*
tag: beta
increment: none
source-branches: ['master']
stable:
regex: release/stable/
regex: ^release/stable/.*
tag: ''
increment: none
source-branches: ['master']
increment: Patch
source-branches: ['master','beta']
is-mainline: true
dev:
regex: dev/.*?/(.*?)
mode: ContinuousDeployment
regex: ^dev/.*?/(.*?)
tag: dev.{BranchName}
source-branches: ['master']
source-branches: ['master', 'release', 'projects', 'feature']
increment: none
projects:
tag: proj-{BranchName}
regex: projects/(.*?)
regex: ^projects/(.*?)
source-branches: ['master']
increment: none
feature:
tag: feature.{BranchName}
regex: feature/(.*?)
regex: ^feature/(.*?)
source-branches: ['master']
increment: none
ignore:
sha: []
sha: []

Просмотреть файл

@ -25,7 +25,7 @@ This package is part of the Uno.CodeGen to generate classes lifecycle methods in
<ItemGroup Condition="'$(TargetFramework)'=='net461'">
<PackageReference Include="System.ValueTuple" Version="4.4.0" PrivateAssets="all" />
<PackageReference Include="Uno.RoslynHelpers" Version="1.2.0-dev.10" PrivateAssets="all" />
<PackageReference Include="Uno.SourceGeneration" Version="1.30.0-dev.245" PrivateAssets="all" />
<PackageReference Include="Uno.SourceGeneration" Version="1.30.0-dev.245" PrivateAssets="all" ExcludeAssets="runtime" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -152,10 +152,9 @@ namespace Uno.Helpers
return true;
}
switch (definitionType.GetType().Name)
if (definitionType.IsTupleType)
{
case "TupleTypeSymbol":
return true; // tuples are immutables
return true; // tuples are immutables
}
switch (definitionType.BaseType?.ToString())
@ -339,8 +338,6 @@ namespace Uno.Helpers
return keyType != null;
}
private static MethodInfo _isAutoPropertyGetter;
public static bool IsAutoProperty(this IPropertySymbol symbol)
{
if (symbol.IsWithEvents || symbol.IsIndexer || !symbol.IsReadOnly)
@ -356,28 +353,36 @@ namespace Uno.Helpers
symbol = symbol.OriginalDefinition;
}
var type = symbol.GetType();
switch (type.FullName)
if (symbol.Locations.FirstOrDefault() is Location location)
{
case "Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE.PEPropertySymbol":
return symbol.IsReadOnly; // It's from compiled code. We assume it's an auto-property when "read only"
case "Microsoft.CodeAnalysis.CSharp.Symbols.SourcePropertySymbol":
break; // ok
default:
throw new InvalidOperationException(
"Unable to find the internal property `IsAutoProperty` on implementation of `IPropertySymbol`. " +
"Should be on internal class `PropertySymbol`. Maybe you are using an incompatible version of Roslyn.");
var node = location.SourceTree?.GetRoot()?.FindNode(location.SourceSpan);
if (node != null)
{
// Compute if a property with accessible is having a Body or an ExpressionBody.
// Reference https://github.com/dotnet/roslyn/blob/ba014d9d7728de0d4b5df3859507f9701e7032c0/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs#L205
var isExplicitProperty = node
.DescendantNodesAndSelf()
.OfType<PropertyDeclarationSyntax>()
.Any(prop =>
{
if(prop.AccessorList != null)
{
return prop.AccessorList.Accessors
.Any(a => a.Body != null || a.ExpressionBody != null);
}
// readonly arrow property declaration
return true;
});
return !isExplicitProperty;
}
}
if (_isAutoPropertyGetter == null)
{
_isAutoPropertyGetter = type
.GetProperty("IsAutoProperty", BindingFlags.Instance | BindingFlags.NonPublic)
.GetMethod;
}
var isAuto = _isAutoPropertyGetter.Invoke(symbol, new object[] { });
return (bool)isAuto;
// Source location in unknown, we assume it's an auto-property when "read only"
return true;
}
public static bool IsFromPartialDeclaration(this ISymbol symbol)

Просмотреть файл

@ -21,17 +21,17 @@
<ItemGroup Condition="'$(TargetFramework)'=='net461'">
<PackageReference Include="System.ValueTuple" Version="4.4.0" PrivateAssets="all" />
<PackageReference Include="Uno.RoslynHelpers" Version="1.2.0-dev.10" PrivateAssets="all" />
<PackageReference Include="Uno.SourceGeneration" Version="1.30.0-dev.245" PrivateAssets="all" />
<PackageReference Include="Uno.SourceGeneration" Version="1.30.0-dev.245" PrivateAssets="all" ExcludeAssets="runtime" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.3.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.3.0" PrivateAssets="all" ExcludeAssets="runtime" />
<PackageReference Include="Uno.MonoAnalyzers" Version="1.0.0-dev.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Uno.SourceGenerationTasks" Version="1.30.0-dev.245" PrivateAssets="none">
<NoWarn>NU1701</NoWarn>
<NoWarn>NU1701</NoWarn>
</PackageReference>
</ItemGroup>