Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some resharper warnings #3406

Merged
merged 5 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/templates/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
steps:
- #@ template.replace(checkoutCode("recursive", False))
- #@ template.replace(fetchPackageArtifacts("needs.build-packages.outputs.package_version", packages = nugetPackages))
- run: dotnet tool install ilspycmd -g
- run: dotnet tool install ilspycmd -g --version 8.0.0.7345
- name: Verify Namespaces
run: |
$isFailure = $false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ jobs:
with:
name: Realm.UnityWeaver.${{ needs.build-packages.outputs.package_version }}
path: ${{ github.workspace }}/Realm/packages/
- run: dotnet tool install ilspycmd -g
- run: dotnet tool install ilspycmd -g --version 8.0.0.7345
- name: Verify Namespaces
run: |
$isFailure = $false
Expand Down
14 changes: 14 additions & 0 deletions Realm.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=adddefaulttypes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=asyncopentask/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=autoimplemented/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=baasapikey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=baascluster/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=baasdifferentiator/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=baasprivateapikey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=baasprojectid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=baasurl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Banderson/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=BEGINSWITH/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=brfalse/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Brtrue/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=caf_00E9/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Canderson/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ccfeee/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=cing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CLONABLE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=consts/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=corlib/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=criticalhandle/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Danderson/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=databinding/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dereferenced/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DEVDIV/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -25,6 +34,8 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=geowithin/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ienum/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ienumerable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ilen/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=inheritdoc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=inliner/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=irobj/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=keypath/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -37,6 +48,8 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=nomoreuserthread/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=notificationtoken/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nulled/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=paramref/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=parms/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Queryables/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=refcounted/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=refcounting/@EntryIndexedValue">True</s:Boolean>
Expand Down Expand Up @@ -64,6 +77,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Updatei/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=uppercased/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=upserted/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=userpass/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=whidbey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=xcframework/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0020ldfl/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
3 changes: 1 addition & 2 deletions Realm/Realm.PlatformHelpers/Platform.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public static string BundleId
var entryAssembly = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a => a.CustomAttributes.Any(att =>
att.AttributeType.FullName == "Android.Runtime.ResourceDesignerAttribute" &&
att.NamedArguments.FirstOrDefault(arg => arg.MemberName == "IsApplication").TypedValue.Value is bool isApplication &&
isApplication));
att.NamedArguments?.FirstOrDefault(arg => arg.MemberName == "IsApplication").TypedValue.Value is true));

bundleId = entryAssembly?.GetName().Name;
}
Expand Down
94 changes: 47 additions & 47 deletions Realm/Realm.SourceGenerator/ClassCodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Realms.SourceGenerator
{
internal class ClassCodeBuilder
{
private readonly string[] _defaultNamespaces = new string[]
private readonly string[] _defaultNamespaces =
{
"System",
"System.Collections.Generic",
Expand Down Expand Up @@ -315,7 +315,7 @@ private string GeneratePartialClass(string interfaceString, string managedAccess
public int BacklinksCount => Accessor.BacklinksCount;

{(_classInfo.ObjectType != ObjectType.EmbeddedObject ? string.Empty :
$@"/// <inheritdoc />
@"/// <inheritdoc />
[IgnoreDataMember, XmlIgnore]
public Realms.IRealmObjectBase? Parent => Accessor.GetParent();")}

Expand Down Expand Up @@ -348,31 +348,31 @@ void ISettableManagedAccessor.SetManagedAccessor(Realms.IRealmAccessor managedAc
partial void OnManaged();

{(_classInfo.HasPropertyChangedEvent ? string.Empty :
$@"private event PropertyChangedEventHandler? _propertyChanged;
@"private event PropertyChangedEventHandler? _propertyChanged;

/// <inheritdoc />
public event PropertyChangedEventHandler? PropertyChanged
{{
{
add
{{
{
if (_propertyChanged == null)
{{
{
SubscribeForNotifications();
}}
}

_propertyChanged += value;
}}
}

remove
{{
{
_propertyChanged -= value;

if (_propertyChanged == null)
{{
{
UnsubscribeFromNotifications();
}}
}}
}}
}
}
}

/// <summary>
/// Called when a property has changed on this class.
Expand All @@ -385,17 +385,17 @@ public event PropertyChangedEventHandler? PropertyChanged
/// <example>
/// <code>
/// class MyClass : IRealmObject
/// {{
/// public int StatusCodeRaw {{ get; set; }}
/// {
/// public int StatusCodeRaw { get; set; }
/// public StatusCodeEnum StatusCode => (StatusCodeEnum)StatusCodeRaw;
/// partial void OnPropertyChanged(string propertyName)
/// {{
/// {
/// if (propertyName == nameof(StatusCodeRaw))
/// {{
/// {
/// RaisePropertyChanged(nameof(StatusCode));
/// }}
/// }}
/// }}
/// }
/// }
/// }
/// </code>
/// Here, we have a computed property that depends on a persisted one. In order to notify any <see cref=""PropertyChanged""/>
/// subscribers that <c>StatusCode</c> has changed, we implement <see cref=""OnPropertyChanged""/> and
Expand All @@ -404,20 +404,20 @@ public event PropertyChangedEventHandler? PropertyChanged
partial void OnPropertyChanged(string? propertyName);

private void RaisePropertyChanged([CallerMemberName] string propertyName = """")
{{
{
_propertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
OnPropertyChanged(propertyName);
}}
}

private void SubscribeForNotifications()
{{
{
Accessor.SubscribeForNotifications(RaisePropertyChanged);
}}
}

private void UnsubscribeFromNotifications()
{{
{
Accessor.UnsubscribeFromNotifications();
}}")}
}")}

/// <summary>
/// Converts a <see cref=""Realms.RealmValue""/> to <see cref=""{_classInfo.Name}""/>. Equivalent to <see cref=""Realms.RealmValue.AsNullableRealmObject{{T}}""/>.
Expand Down Expand Up @@ -445,38 +445,38 @@ private void UnsubscribeFromNotifications()
public TypeInfo GetTypeInfo() => Accessor.GetTypeInfo(this);

{(_classInfo.OverridesEquals ? string.Empty :
$@"/// <inheritdoc />
@"/// <inheritdoc />
public override bool Equals(object? obj)
{{
{
if (obj is null)
{{
{
return false;
}}
}

if (ReferenceEquals(this, obj))
{{
{
return true;
}}
}

if (obj is InvalidObject)
{{
{
return !IsValid;
}}
}

if (obj is not Realms.IRealmObjectBase iro)
{{
{
return false;
}}
}

return Accessor.Equals(iro.Accessor);
}}")}
}")}

{(_classInfo.OverridesGetHashCode ? string.Empty :
$@"/// <inheritdoc />
@"/// <inheritdoc />
public override int GetHashCode() => IsManaged ? Accessor.GetHashCode() : base.GetHashCode();")}

{(_classInfo.OverridesToString ? string.Empty :
$@"/// <inheritdoc />
@"/// <inheritdoc />
public override string? ToString() => Accessor.ToString();")}";

var classString = $@"[Generated]
Expand Down Expand Up @@ -638,7 +638,7 @@ private string GenerateUnmanagedAccessor()

if (property.IsPrimaryKey)
{
setValueLines.AppendLine($@"throw new InvalidOperationException(""Cannot set the value of a primary key property with SetValue. You need to use SetValueUnique"");".Indent());
setValueLines.AppendLine(@"throw new InvalidOperationException(""Cannot set the value of a primary key property with SetValue. You need to use SetValueUnique"");".Indent());

setValueUniqueLines.Append($@"if (propertyName != ""{stringName}"")
{{
Expand All @@ -660,13 +660,13 @@ private string GenerateUnmanagedAccessor()

if (getValueLines.Length == 0)
{
getValueBody = $@"throw new MissingMemberException($""The object does not have a gettable Realm property with name {{propertyName}}"");";
getValueBody = @"throw new MissingMemberException($""The object does not have a gettable Realm property with name {propertyName}"");";
}
else
{
getValueBody = $@"return propertyName switch
{{
{getValueLines.Indent(1, trimNewLines: true)}
{getValueLines.Indent(trimNewLines: true)}
_ => throw new MissingMemberException($""The object does not have a gettable Realm property with name {{propertyName}}""),
}};";
}
Expand All @@ -676,13 +676,13 @@ private string GenerateUnmanagedAccessor()

if (setValueLines.Length == 0)
{
setValueBody = $@"throw new MissingMemberException($""The object does not have a settable Realm property with name {{propertyName}}"");";
setValueBody = @"throw new MissingMemberException($""The object does not have a settable Realm property with name {propertyName}"");";
}
else
{
setValueBody = $@"switch (propertyName)
{{
{setValueLines.Indent(1, trimNewLines: true)}
{setValueLines.Indent(trimNewLines: true)}
default:
throw new MissingMemberException($""The object does not have a settable Realm property with name {{propertyName}}"");
}}";
Expand All @@ -699,7 +699,7 @@ private string GenerateUnmanagedAccessor()

if (getListValueLines.Length == 0)
{
getListValueBody = $@"throw new MissingMemberException($""The object does not have a Realm list property with name {{propertyName}}"");";
getListValueBody = @"throw new MissingMemberException($""The object does not have a Realm list property with name {propertyName}"");";
}
else
{
Expand All @@ -715,7 +715,7 @@ private string GenerateUnmanagedAccessor()

if (getSetValueLines.Length == 0)
{
getSetValueBody = $@"throw new MissingMemberException($""The object does not have a Realm set property with name {{propertyName}}"");";
getSetValueBody = @"throw new MissingMemberException($""The object does not have a Realm set property with name {propertyName}"");";
}
else
{
Expand All @@ -731,7 +731,7 @@ private string GenerateUnmanagedAccessor()

if (getDictionaryValueLines.Length == 0)
{
getDictionaryValueBody = $@"throw new MissingMemberException($""The object does not have a Realm dictionary property with name {{propertyName}}"");";
getDictionaryValueBody = @"throw new MissingMemberException($""The object does not have a Realm dictionary property with name {propertyName}"");";
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions Realm/Realm.SourceGenerator/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public ParsingResults Parse(IEnumerable<RealmClassDefinition> realmClasses)
classInfo.Diagnostics.Add(Diagnostics.ClassWithBaseType(classSymbol.Name, firstClassDeclarationSyntax.GetIdentifierLocation()));
}

var implementingObjectTypes = classSymbol.ImplementingObjectTypes();
var implementingObjectTypes = classSymbol.ImplementingObjectTypes().ToArray();

if (implementingObjectTypes.Count() > 1)
if (implementingObjectTypes.Length > 1)
{
classInfo.Diagnostics.Add(Diagnostics.ClassUnclearDefinition(classSymbol.Name, firstClassDeclarationSyntax.GetIdentifierLocation()));
}
Expand Down Expand Up @@ -219,7 +219,7 @@ private IEnumerable<PropertyInfo> GetProperties(ClassInfo classInfo, IEnumerable

var isSameType = SymbolEqualityComparer.Default.Equals(inversePropertyTypeInfo?.TypeSymbol, classInfo.TypeSymbol);
var isCollectionOfSameType = inversePropertyTypeInfo?.IsListOrSet == true
&& SymbolEqualityComparer.Default.Equals(inversePropertyTypeInfo?.InternalType.TypeSymbol, classInfo.TypeSymbol);
&& SymbolEqualityComparer.Default.Equals(inversePropertyTypeInfo.InternalType.TypeSymbol, classInfo.TypeSymbol);

if (inversePropertyTypeInfo == null || (!isSameType && !isCollectionOfSameType))
{
Expand Down Expand Up @@ -288,7 +288,7 @@ private PropertyTypeInfo GetPropertyTypeInfo(ClassInfo classInfo, PropertyInfo p
return propertyTypeInfo;
}

if (propertySymbol is INamedTypeSymbol namedSymbol && namedSymbol.SpecialType == SpecialType.System_DateTime)
if (propertySymbol is INamedTypeSymbol { SpecialType: SpecialType.System_DateTime })
{
classInfo.Diagnostics.Add(Diagnostics.DateTimeNotSupported(classInfo.Name, propertySymbol.Name, propertyLocation));
}
Expand All @@ -308,7 +308,7 @@ private PropertyTypeInfo GetPropertyTypeInfo(ClassInfo classInfo, PropertyInfo p
{
var argument = propertyTypeInfo.TypeSymbol.AsNamed().TypeArguments.Single();

if (!argument.IsValidRealmIntgerType())
if (!argument.IsValidRealmIntegerType())
{
classInfo.Diagnostics.Add(Diagnostics.RealmIntegerTypeUnsupported(classInfo.Name, propertySymbol.Name,
argument.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), propertyLocation));
Expand Down Expand Up @@ -463,7 +463,7 @@ INamedTypeSymbol when typeSymbol.IsAnyRealmObjectType() => PropertyTypeInfo.Obje

private static bool HasParameterlessConstructor(List<ClassDeclarationSyntax> classDeclarations)
{
var constructors = classDeclarations.SelectMany(cd => cd.ChildNodes().OfType<ConstructorDeclarationSyntax>());
var constructors = classDeclarations.SelectMany(cd => cd.ChildNodes().OfType<ConstructorDeclarationSyntax>()).ToArray();
return !constructors.Any() || constructors.Any(c => !c.ParameterList.Parameters.Any());
}

Expand Down
Loading