diff --git a/tests/xtro-sharpie/xtro-report/xtro-report.csproj b/tests/xtro-sharpie/xtro-report/xtro-report.csproj
index 8e905ed0a453..9bcdb596b75e 100644
--- a/tests/xtro-sharpie/xtro-report/xtro-report.csproj
+++ b/tests/xtro-sharpie/xtro-report/xtro-report.csproj
@@ -5,6 +5,9 @@
enable
enable
false
+
+ Nullable
+ true
diff --git a/tests/xtro-sharpie/xtro-sanity/Sanitizer.cs b/tests/xtro-sharpie/xtro-sanity/Sanitizer.cs
index d55625cf3ef9..2afdc4d6d6d4 100644
--- a/tests/xtro-sharpie/xtro-sanity/Sanitizer.cs
+++ b/tests/xtro-sharpie/xtro-sanity/Sanitizer.cs
@@ -374,7 +374,7 @@ static List GetAllFrameworks ()
static Frameworks GetFrameworks (string platform)
{
- return Frameworks.GetFrameworks (ApplePlatformExtensions.Parse (platform), false);
+ return Frameworks.GetFrameworks (ApplePlatformExtensions.Parse (platform), false)!;
}
static List GetFrameworks (IEnumerable platforms)
diff --git a/tests/xtro-sharpie/xtro-sanity/xtro-sanity.csproj b/tests/xtro-sharpie/xtro-sanity/xtro-sanity.csproj
index 8440e1f6e294..2a9d8b0f507e 100644
--- a/tests/xtro-sharpie/xtro-sanity/xtro-sanity.csproj
+++ b/tests/xtro-sharpie/xtro-sanity/xtro-sanity.csproj
@@ -5,6 +5,9 @@
enable
enable
false
+
+ Nullable
+ true
diff --git a/tests/xtro-sharpie/xtro-sharpie/AttributeHelpers.cs b/tests/xtro-sharpie/xtro-sharpie/AttributeHelpers.cs
index 03a25f5adfb1..1fe2e1d2773a 100644
--- a/tests/xtro-sharpie/xtro-sharpie/AttributeHelpers.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/AttributeHelpers.cs
@@ -1,3 +1,4 @@
+using System.Diagnostics.CodeAnalysis;
using Sharpie.Bind;
namespace Extrospection {
@@ -10,7 +11,7 @@ static bool Skip (ICustomAttributeProvider item)
}
// These both return out Version and bool as you can have an an attribute with no version (null) which is different no matching attribute at all
- public static bool FindDeprecated (ICustomAttributeProvider item, out Version version)
+ public static bool FindDeprecated (ICustomAttributeProvider item, [NotNullWhen (true)] out Version? version)
{
version = null;
@@ -23,7 +24,7 @@ public static bool FindDeprecated (ICustomAttributeProvider item, out Version ve
return false;
}
- public static bool FindObsolete (ICustomAttributeProvider item, out Version version)
+ public static bool FindObsolete (ICustomAttributeProvider item, [NotNullWhen (true)] out Version? version)
{
version = null;
@@ -70,7 +71,7 @@ public static bool HasObsolete (CustomAttribute attribute, Platforms platform)
return attribute.Constructor.DeclaringType.Name == "ObsoleteAttribute";
}
- static bool GetPlatformVersion (CustomAttribute attribute, out Version version)
+ static bool GetPlatformVersion (CustomAttribute attribute, out Version? version)
{
// Three different Attribute flavors
// (PlatformName platform, PlatformArchitecture architecture = PlatformArchitecture.None, string message = null)
@@ -95,7 +96,7 @@ public static bool FindObjcDeprecated (IEnumerable attrs, out VersionTuple
{
var attr = attrs.GetAvailabilityAttributes ().FirstOrDefault (x => x.AvailabilityAttributeDeprecated.HasValue && !x.AvailabilityAttributeDeprecated.Value.IsEmptyVersionTuple && x.AvailabilityAttributePlatformIdentifierName == Helpers.ClangPlatformName);
if (attr is not null) {
- version = attr.AvailabilityAttributeDeprecated.Value;
+ version = attr.AvailabilityAttributeDeprecated!.Value;
return true;
} else {
version = VersionTuple.Empty;
@@ -111,7 +112,7 @@ public static bool HasAnyDeprecationForCurrentPlatform (ICustomAttributeProvider
// Properties are a special case as it is generated on the property itself and not the individual get_ \ set_ methods
// Cecil does not have a link between the MethodDefinition we have and the hosting PropertyDefinition, so we have to dig to find the match
if (item is MethodDefinition method) {
- PropertyDefinition property = method.DeclaringType.Properties.FirstOrDefault (p => p.GetMethod == method || p.SetMethod == method);
+ var property = method.DeclaringType.Properties.FirstOrDefault (p => p.GetMethod == method || p.SetMethod == method);
if (property is not null && HasAnyDeprecationForCurrentPlatform (property)) {
return true;
}
@@ -159,7 +160,7 @@ public static bool HasAnyAdvice (ICustomAttributeProvider item)
// Properties are a special case for [Advice], as it is generated on the property itself and not the individual get_ \ set_ methods
// Cecil does not have a link between the MethodDefinition we have and the hosting PropertyDefinition, so we have to dig to find the match
if (item is MethodDefinition method) {
- PropertyDefinition property = method.DeclaringType.Properties.FirstOrDefault (p => p.GetMethod == method || p.SetMethod == method);
+ var property = method.DeclaringType.Properties.FirstOrDefault (p => p.GetMethod == method || p.SetMethod == method);
if (property is not null && HasAdviced (property.CustomAttributes))
return true;
}
diff --git a/tests/xtro-sharpie/xtro-sharpie/DeprecatedCheck.cs b/tests/xtro-sharpie/xtro-sharpie/DeprecatedCheck.cs
index 21b8b19e2131..9c3e326442a6 100644
--- a/tests/xtro-sharpie/xtro-sharpie/DeprecatedCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/DeprecatedCheck.cs
@@ -45,7 +45,7 @@ public override void EndVisit ()
void ProcessObjcEntry (string objcClassName, VersionTuple objcVersion)
{
- TypeDefinition managedType = ManagedTypes.FirstOrDefault (x => Helpers.GetName (x) == objcClassName && x.IsPublic);
+ var managedType = ManagedTypes.FirstOrDefault (x => Helpers.GetName (x) == objcClassName && x.IsPublic);
if (managedType is not null) {
var framework = Helpers.GetFramework (managedType);
if (framework is not null)
@@ -60,7 +60,7 @@ void ProcessObjcSelector (string fullname, VersionTuple objcVersion)
string objcClassName = fullname.Substring (class_method ? 1 : 0, n);
string selector = fullname.Substring (n + 2);
- TypeDefinition managedType = ManagedTypes.FirstOrDefault (x => Helpers.GetName (x) == objcClassName);
+ var managedType = ManagedTypes.FirstOrDefault (x => Helpers.GetName (x) == objcClassName);
if (managedType is not null) {
var framework = Helpers.GetFramework (managedType);
if (framework is null)
@@ -92,7 +92,7 @@ void ProcessCFunction (string fullname, VersionTuple objcVersion)
}
}
- public void ProcessItem (ICustomAttributeProvider item, string itemName, VersionTuple objcVersion, string framework)
+ public void ProcessItem (ICustomAttributeProvider item, string? itemName, VersionTuple objcVersion, string framework)
{
// Our bindings do not need have [Deprecated] for ancient versions we don't support anymore
if (VersionHelpers.VersionTooOldToCare (objcVersion))
@@ -114,8 +114,7 @@ public void ProcessItem (ICustomAttributeProvider item, string itemName, Version
}
// Some APIs have both a [Deprecated] and [Obsoleted]. Bias towards [Obsoleted].
- Version managedVersion;
- bool foundObsoleted = AttributeHelpers.FindObsolete (item, out managedVersion);
+ bool foundObsoleted = AttributeHelpers.FindObsolete (item, out var managedVersion);
if (foundObsoleted) {
if (managedVersion is not null && !ManagedBeforeOrEqualToObjcVersion (objcVersion, managedVersion))
Log.On (framework).Add ($"!deprecated-attribute-wrong! {itemName} has {managedVersion} not {objcVersion} on [Obsoleted] attribute");
diff --git a/tests/xtro-sharpie/xtro-sharpie/DesignatedInitializerCheck.cs b/tests/xtro-sharpie/xtro-sharpie/DesignatedInitializerCheck.cs
index 5869a2844138..b58d73526e27 100644
--- a/tests/xtro-sharpie/xtro-sharpie/DesignatedInitializerCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/DesignatedInitializerCheck.cs
@@ -24,13 +24,13 @@ public DesignatedInitializerCheck (BindingResult bindingResult)
static Dictionary types = new Dictionary ();
static Dictionary methods = new Dictionary ();
- static TypeDefinition GetType (ObjCInterfaceDecl decl)
+ static TypeDefinition? GetType (ObjCInterfaceDecl decl)
{
types.TryGetValue (decl.Name, out var td);
return td;
}
- static MethodDefinition GetMethod (ObjCMethodDecl decl)
+ static MethodDefinition? GetMethod (ObjCMethodDecl decl)
{
methods.TryGetValue (decl.GetName (), out var md);
return md;
@@ -51,7 +51,7 @@ public override void VisitManagedMethod (MethodDefinition method)
public override void VisitObjCMethodDecl (ObjCMethodDecl decl)
{
// don't process methods (or types) that are unavailable for the current platform
- if (!decl.IsAvailable () || !(decl.DeclContext as Decl).IsAvailable ())
+ if (!decl.IsAvailable () || !(((Decl) decl.DeclContext!).IsAvailable ()))
return;
var method = GetMethod (decl);
diff --git a/tests/xtro-sharpie/xtro-sharpie/EnumCheck.cs b/tests/xtro-sharpie/xtro-sharpie/EnumCheck.cs
index 40c02a9d8841..d85e49bd7e46 100644
--- a/tests/xtro-sharpie/xtro-sharpie/EnumCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/EnumCheck.cs
@@ -2,8 +2,8 @@ namespace Extrospection {
class EnumCheck : BaseVisitor {
class ManagedValue {
- public FieldDefinition Field;
- public EnumConstantDecl Decl;
+ public required FieldDefinition Field;
+ public EnumConstantDecl? Decl;
}
Dictionary enums = new Dictionary (StringComparer.InvariantCultureIgnoreCase);
diff --git a/tests/xtro-sharpie/xtro-sharpie/FieldCheck.cs b/tests/xtro-sharpie/xtro-sharpie/FieldCheck.cs
index 65e32c45d8e6..b12415a92c94 100644
--- a/tests/xtro-sharpie/xtro-sharpie/FieldCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/FieldCheck.cs
@@ -57,10 +57,10 @@ void CheckAttributes (string memberName, ICustomAttributeProvider p)
&& ca.Constructor.DeclaringType.Name != "FieldAttribute`1")
continue;
- var name = ca.ConstructorArguments [0].Value as string;
+ var name = (string) ca.ConstructorArguments [0].Value!;
if (!fields.TryGetValue (name, out var mr))
- fields.Add (name, p as MemberReference);
+ fields.Add (name, (MemberReference) p);
else {
// not critical and quite noisy with current API profile
// Console.WriteLine ("!duplicate-field-name! {0} [Field] exists as both {1} and {2}", name, memberName, mr.FullName);
diff --git a/tests/xtro-sharpie/xtro-sharpie/Helpers.cs b/tests/xtro-sharpie/xtro-sharpie/Helpers.cs
index 59ec697da80f..11f62b971db8 100644
--- a/tests/xtro-sharpie/xtro-sharpie/Helpers.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/Helpers.cs
@@ -1,3 +1,5 @@
+using System.Diagnostics.CodeAnalysis;
+
namespace Extrospection {
public enum Platforms {
@@ -252,7 +254,9 @@ static bool IsStatic (this TypeDefinition self)
return (self.IsSealed && self.IsAbstract);
}
- public static string GetName (this ObjCMethodDecl self)
+
+ [return: NotNullIfNotNull (nameof (self))]
+ public static string? GetName (this ObjCMethodDecl? self)
{
if (self is null)
return null;
@@ -263,7 +267,7 @@ public static string GetName (this ObjCMethodDecl self)
if (self.DeclContext is ObjCCategoryDecl category) {
sb.Append (category.ClassInterface.Name);
} else {
- sb.Append ((self.DeclContext as NamedDecl).Name);
+ sb.Append (((NamedDecl) self.DeclContext!).Name);
}
sb.Append ("::");
var sel = self.Selector.ToString ();
@@ -271,7 +275,7 @@ public static string GetName (this ObjCMethodDecl self)
return sb.ToString ();
}
- public static string GetName (this TypeDefinition self)
+ public static string? GetName (this TypeDefinition? self)
{
if ((self is null) || !self.HasCustomAttributes)
return null;
@@ -309,13 +313,13 @@ public static string GetName (this TypeDefinition self)
return null;
}
- public static string GetName (this MethodDefinition self)
+ public static string? GetName (this MethodDefinition? self)
{
if (self is null)
return null;
var type = self.DeclaringType;
- string tname = self.DeclaringType.GetName ();
+ string? tname = self.DeclaringType.GetName ();
// a static type is not used for static selectors
bool is_static = !type.IsStatic () && self.IsStatic;
@@ -340,7 +344,7 @@ public static string GetName (this MethodDefinition self)
return sb.ToString ();
}
- public static string GetSelector (this MethodDefinition self)
+ public static string? GetSelector (this MethodDefinition self)
{
if ((self is null) || !self.HasCustomAttributes)
return null;
@@ -375,9 +379,12 @@ public static bool IsObsolete (this ICustomAttributeProvider provider)
return false;
}
- public static PropertyDefinition FindProperty (this MethodReference method)
+ public static PropertyDefinition? FindProperty (this MethodReference? method)
{
- var def = method?.Resolve ();
+ if (method is null)
+ return null;
+
+ var def = method.Resolve ();
if (def is null)
return null;
@@ -409,7 +416,7 @@ public static string GetFramework (TypeReference type)
public static string GetFramework (MethodDefinition method)
{
- string framework = null;
+ string? framework = null;
if (method.HasPInvokeInfo)
framework = Path.GetFileNameWithoutExtension (method.PInvokeInfo.Module.Name);
else
@@ -423,7 +430,7 @@ public static string GetFramework (MemberReference member)
return MapFramework (framework);
}
- public static string GetFramework (Decl decl)
+ public static string? GetFramework (Decl decl)
{
var header_file = decl.PresumedLoc?.FileName;
if (header_file is null)
@@ -469,7 +476,7 @@ public static string MapFramework (string candidate)
}
}
- public static (T, T) Sort (T o1, T o2)
+ public static (T, T) Sort (T o1, T o2) where T : notnull
{
if (StringComparer.Ordinal.Compare (o1.ToString (), o2.ToString ()) < 0)
return (o2, o1);
diff --git a/tests/xtro-sharpie/xtro-sharpie/Log.cs b/tests/xtro-sharpie/xtro-sharpie/Log.cs
index a899ea9b7809..1c591f81910e 100644
--- a/tests/xtro-sharpie/xtro-sharpie/Log.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/Log.cs
@@ -1,12 +1,11 @@
namespace Extrospection {
static class Log {
- static Dictionary> lists = new Dictionary> (StringComparer.OrdinalIgnoreCase);
+ static Dictionary> lists = new (StringComparer.OrdinalIgnoreCase);
public static IList On (string fx)
{
- List list;
- if (!lists.TryGetValue (fx, out list)) {
+ if (!lists.TryGetValue (fx, out var list)) {
list = new List ();
lists.Add (fx, list);
}
diff --git a/tests/xtro-sharpie/xtro-sharpie/NullabilityCheck.cs b/tests/xtro-sharpie/xtro-sharpie/NullabilityCheck.cs
index fcbec45a3096..bd3276488531 100644
--- a/tests/xtro-sharpie/xtro-sharpie/NullabilityCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/NullabilityCheck.cs
@@ -27,13 +27,13 @@ public NullabilityCheck (BindingResult bindingResult)
{
}
- static TypeDefinition GetType (ObjCInterfaceDecl decl)
+ static TypeDefinition? GetType (ObjCInterfaceDecl decl)
{
types.TryGetValue (decl.Name, out var td);
return td;
}
- static MethodDefinition GetMethod (ObjCMethodDecl decl)
+ static MethodDefinition? GetMethod (ObjCMethodDecl decl)
{
methods.TryGetValue (decl.GetName (), out var md);
return md;
@@ -91,7 +91,7 @@ static Null [] GetNullable (ICustomAttributeProvider cap)
// Type is `System.Byte[]` and value is a `CustomAttributeArgument[]`
// each with a `Type` of `System.Byte` and where value is a `byte`
case "System.Byte[]":
- var caa = first.Value as CustomAttributeArgument [];
+ var caa = (CustomAttributeArgument []) first.Value;
var length = caa.Length;
var values = new Null [length];
for (int i = 0; i < length; i++)
@@ -106,11 +106,11 @@ static Null [] GetNullable (ICustomAttributeProvider cap)
public override void VisitObjCMethodDecl (ObjCMethodDecl decl)
{
// don't process methods (or types) that are unavailable for the current platform
- if (!decl.IsAvailable () || !(decl.DeclContext as Decl).IsAvailable ())
+ if (!decl.IsAvailable () || !(((Decl) decl.DeclContext!).IsAvailable ()))
return;
// don't process deprecated methods (or types)
- if (decl.IsDeprecated () || (decl.DeclContext as Decl).IsDeprecated ())
+ if (decl.IsDeprecated () || (((Decl) decl.DeclContext!).IsDeprecated ()))
return;
var method = GetMethod (decl);
@@ -203,7 +203,7 @@ public override void VisitObjCMethodDecl (ObjCMethodDecl decl)
ICustomAttributeProvider cap;
// the managed attributes are on the property, not the special methods
if (method.IsGetter) {
- var property = method.FindProperty ();
+ var property = method.FindProperty ()!;
// also `null_resettable` will only show something (natively) on the setter (since it does not return null, but accept it)
// in this case we'll trust xtro checking the setter only (if it exists, if not then it can't be `null_resettable`)
if (property.SetMethod is not null)
diff --git a/tests/xtro-sharpie/xtro-sharpie/ObjCInterfaceCheck.cs b/tests/xtro-sharpie/xtro-sharpie/ObjCInterfaceCheck.cs
index e0e0921085c7..5d0fbaa6645f 100644
--- a/tests/xtro-sharpie/xtro-sharpie/ObjCInterfaceCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/ObjCInterfaceCheck.cs
@@ -15,7 +15,7 @@ public override void VisitManagedType (TypeDefinition type)
if (!type.HasCustomAttributes)
return;
- string rname = null;
+ string? rname = null;
bool wrapper = true;
bool skip = false;
@@ -24,7 +24,7 @@ public override void VisitManagedType (TypeDefinition type)
case "RegisterAttribute":
rname = type.Name;
if (ca.HasConstructorArguments) {
- rname = (ca.ConstructorArguments [0].Value as string);
+ rname = (string?) ca.ConstructorArguments [0].Value;
if (ca.ConstructorArguments.Count > 1)
wrapper = (bool) ca.ConstructorArguments [1].Value;
}
@@ -47,8 +47,7 @@ public override void VisitManagedType (TypeDefinition type)
}
}
if (!skip && wrapper && !String.IsNullOrEmpty (rname)) {
- TypeDefinition td;
- if (!type_map.TryGetValue (rname, out td)) {
+ if (!type_map.TryGetValue (rname, out var td)) {
type_map.Add (rname, type);
type_map_copy.Add (rname, type);
} else {
@@ -149,22 +148,22 @@ public override void EndVisit ()
}
// - version check
- bool ImplementProtocol (string protocol, TypeDefinition td)
+ bool ImplementProtocol (string protocol, TypeDefinition? td)
{
if (td is null)
return false;
if (td.HasInterfaces) {
foreach (var intf in td.Interfaces) {
TypeReference ifaceType;
- ifaceType = intf?.InterfaceType;
- if (protocol == GetProtocolName (ifaceType?.Resolve ()))
+ ifaceType = intf.InterfaceType;
+ if (protocol == GetProtocolName (ifaceType.Resolve ()))
return true;
}
}
return ImplementProtocol (protocol, td.BaseType?.Resolve ());
}
- public static string GetProtocolName (TypeDefinition td)
+ public static string? GetProtocolName (TypeDefinition td)
{
if (!td.HasCustomAttributes)
return null;
diff --git a/tests/xtro-sharpie/xtro-sharpie/ObjCProtocolCheck.cs b/tests/xtro-sharpie/xtro-sharpie/ObjCProtocolCheck.cs
index aaff81f0f2a7..4ad4fbb17d50 100644
--- a/tests/xtro-sharpie/xtro-sharpie/ObjCProtocolCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/ObjCProtocolCheck.cs
@@ -43,7 +43,7 @@ public override void VisitManagedType (TypeDefinition type)
return;
}
- string pname = null;
+ string? pname = null;
bool informal = false;
foreach (var ca in type.CustomAttributes) {
@@ -82,8 +82,7 @@ public override void VisitObjCProtocolDecl (ObjCProtocolDecl decl)
return;
var name = decl.Name;
- TypeDefinition td;
- if (!protocol_map.TryGetValue (name, out td)) {
+ if (!protocol_map.TryGetValue (name, out var td)) {
if (!decl.IsDeprecated ())
Log.On (framework).Add ($"!missing-protocol! {name} not bound");
// other checks can't be done without an actual protocol to inspect
@@ -93,9 +92,9 @@ public override void VisitObjCProtocolDecl (ObjCProtocolDecl decl)
// build type selector-required map
var map = new Dictionary ();
foreach (var ca in td.CustomAttributes) {
- string export = null;
- string g_export = null;
- string s_export = null;
+ string? export = null;
+ string? g_export = null;
+ string? s_export = null;
bool is_required = false;
bool is_property = false;
bool is_static = false;
@@ -143,7 +142,7 @@ public override void VisitObjCProtocolDecl (ObjCProtocolDecl decl)
}
}
- var deprecatedProtocol = (decl.DeclContext as Decl).IsDeprecated ();
+ var deprecatedProtocol = ((Decl) decl.DeclContext!).IsDeprecated ();
// don't report anything for deprecated protocols
// (we still report some errors for deprecated members of non-deprecated protocols - because abstract/non-abstract can
@@ -196,7 +195,7 @@ public override void VisitObjCProtocolDecl (ObjCProtocolDecl decl)
protocol_map.Remove (name);
}
- static string GetSelector (ObjCMethodDecl method)
+ static string? GetSelector (ObjCMethodDecl method)
{
var result = method.Selector.ToString ();
if (result is not null)
diff --git a/tests/xtro-sharpie/xtro-sharpie/ReleaseAttributeCheck.cs b/tests/xtro-sharpie/xtro-sharpie/ReleaseAttributeCheck.cs
index 4870d88cc7a9..9a0cc9f77651 100644
--- a/tests/xtro-sharpie/xtro-sharpie/ReleaseAttributeCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/ReleaseAttributeCheck.cs
@@ -28,8 +28,8 @@ public override void VisitManagedMethod (MethodDefinition method)
if (method.ReturnType.IsValueType)
return;
- string family = null;
- string selector = null;
+ string? family = null;
+ string? selector = null;
bool hasReleaseAttribute = false;
if (method.MethodReturnType.HasCustomAttributes) {
diff --git a/tests/xtro-sharpie/xtro-sharpie/RequiresSuperCheck.cs b/tests/xtro-sharpie/xtro-sharpie/RequiresSuperCheck.cs
index 3a162e51fc0d..1944d0a692c2 100644
--- a/tests/xtro-sharpie/xtro-sharpie/RequiresSuperCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/RequiresSuperCheck.cs
@@ -19,7 +19,7 @@ public RequiresSuperCheck (BindingResult bindingResult)
{
}
- static MethodDefinition GetMethod (ObjCMethodDecl decl)
+ static MethodDefinition? GetMethod (ObjCMethodDecl decl)
{
methods.TryGetValue (decl.GetName (), out var md);
return md;
@@ -50,7 +50,7 @@ public override void VisitObjCMethodDecl (ObjCMethodDecl decl)
void Visit (ObjCMethodDecl decl)
{
// don't process methods (or types) that are unavailable for the current platform
- if (!decl.IsAvailable () || !(decl.DeclContext as Decl).IsAvailable ())
+ if (!decl.IsAvailable () || !((Decl) decl.DeclContext!).IsAvailable ())
return;
var method = GetMethod (decl);
diff --git a/tests/xtro-sharpie/xtro-sharpie/Runner.cs b/tests/xtro-sharpie/xtro-sharpie/Runner.cs
index a8fc41f13624..ac6f316dbdc3 100644
--- a/tests/xtro-sharpie/xtro-sharpie/Runner.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/Runner.cs
@@ -132,7 +132,7 @@ public SharpieVisitor (BindingResult bindingResult)
public void Load (string filename, IEnumerable searchDirectories)
{
resolver.AddSearchDirectory (searchDirectories.ToArray ());
- resolver.AddSearchDirectory (Path.GetDirectoryName (filename));
+ resolver.AddSearchDirectory (Path.GetDirectoryName (filename)!);
assemblies.Add (resolver.Load (filename));
}
diff --git a/tests/xtro-sharpie/xtro-sharpie/SelectorCheck.cs b/tests/xtro-sharpie/xtro-sharpie/SelectorCheck.cs
index e31701909bb6..af12bcd6bdf7 100644
--- a/tests/xtro-sharpie/xtro-sharpie/SelectorCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/SelectorCheck.cs
@@ -92,11 +92,11 @@ public override void VisitObjCMethodDecl (ObjCMethodDecl decl)
return;
// don't process methods (or types) that are unavailable for the current platform
- if (!decl.IsAvailable () || !(decl.DeclContext as Decl).IsAvailable ())
+ if (!decl.IsAvailable () || !((Decl) decl.DeclContext!).IsAvailable ())
return;
// don't process deprecated methods (or types)
- if (decl.IsDeprecated () || (decl.DeclContext as Decl).IsDeprecated ())
+ if (decl.IsDeprecated () || ((Decl) decl.DeclContext!).IsDeprecated ())
return;
var framework = Helpers.GetFramework (decl);
diff --git a/tests/xtro-sharpie/xtro-sharpie/SimdCheck.cs b/tests/xtro-sharpie/xtro-sharpie/SimdCheck.cs
index b3dd890463d0..c2fea1c947dd 100644
--- a/tests/xtro-sharpie/xtro-sharpie/SimdCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/SimdCheck.cs
@@ -6,8 +6,8 @@ class SimdCheck : BaseVisitor {
// A dictionary of native type -> managed type mapping.
class NativeSimdInfo {
- public string Managed;
- public string InvalidManaged;
+ public required string Managed;
+ public string? InvalidManaged;
}
static Dictionary type_mapping = new Dictionary () {
@@ -85,7 +85,7 @@ static SimdCheck ()
}
class ManagedSimdInfo {
- public MethodDefinition Method;
+ public required MethodDefinition Method;
public bool ContainsInvalidMappingForSimd;
}
Dictionary managed_methods = new Dictionary ();
@@ -131,8 +131,7 @@ public override void VisitManagedMethod (MethodDefinition method)
return;
}
- ManagedSimdInfo existing;
- if (managed_methods.TryGetValue (key, out existing)) {
+ if (managed_methods.TryGetValue (key, out var existing)) {
if (very_strict) {
var sorted = Helpers.Sort (existing.Method, method);
var framework = sorted.Item1.DeclaringType.Namespace;
@@ -218,7 +217,7 @@ bool IsExtVector (Decl decl, ClangSharp.Type type, ref string simd_type)
var typeName = type.ToString ();
if (!rv && typeName.Contains ("simd")) {
- var framework = Helpers.GetFramework (decl);
+ var framework = Helpers.GetFramework (decl)!;
Log.On (framework).Add ($"!unknown-simd-type! Could not detect that {typeName} is a Simd type, but its name contains 'simd'. Something needs fixing in SimdCheck.cs");
}
@@ -239,7 +238,7 @@ bool IsSimdType (Decl decl, ClangSharp.Type type, ref string simd_type, ref bool
}
if (IsExtVector (decl, type, ref simd_type)) {
- var framework = Helpers.GetFramework (decl);
+ var framework = Helpers.GetFramework (decl)!;
Log.On (framework).Add ($"!unknown-simd-type-mapping! The Simd type {simd_type} does not have a mapping to a managed type. Please add one in SimdCheck.cs");
}
@@ -339,7 +338,7 @@ void CheckMarshalDirective (MethodDefinition method, string simd_type, bool only
public override void VisitObjCMethodDecl (ObjCMethodDecl decl)
{
// don't process methods (or types) that are unavailable for the current platform
- if (!decl.IsAvailable () || !(decl.DeclContext as Decl).IsAvailable ())
+ if (!decl.IsAvailable () || !((Decl) decl.DeclContext!).IsAvailable ())
return;
var framework = Helpers.GetFramework (decl);
@@ -351,8 +350,7 @@ public override void VisitObjCMethodDecl (ObjCMethodDecl decl)
var only_return_type_is_simd = true;
var native_simd = ContainsSimdTypes (decl, ref simd_type, ref requires_marshal_directive, ref only_return_type_is_simd);
- ManagedSimdInfo info;
- managed_methods.TryGetValue (decl.GetName (), out info);
+ managed_methods.TryGetValue (decl.GetName (), out var info);
var method = info?.Method;
if (!native_simd) {
@@ -392,7 +390,7 @@ public override void VisitObjCMethodDecl (ObjCMethodDecl decl)
return;
}
- if (!info.ContainsInvalidMappingForSimd) {
+ if (!info!.ContainsInvalidMappingForSimd) {
// The managed method does not have any types that are incorrect for Simd.
if (requires_marshal_directive)
CheckMarshalDirective (method, simd_type, only_return_type_is_simd);
diff --git a/tests/xtro-sharpie/xtro-sharpie/UIAppearanceCheck.cs b/tests/xtro-sharpie/xtro-sharpie/UIAppearanceCheck.cs
index 47d3895f77e4..ef23f37aea9f 100644
--- a/tests/xtro-sharpie/xtro-sharpie/UIAppearanceCheck.cs
+++ b/tests/xtro-sharpie/xtro-sharpie/UIAppearanceCheck.cs
@@ -21,7 +21,7 @@ public UIAppearanceCheck (BindingResult bindingResult)
{
}
- static MethodDefinition GetMethod (ObjCMethodDecl decl)
+ static MethodDefinition? GetMethod (ObjCMethodDecl decl)
{
methods.TryGetValue (decl.GetName (), out var md);
return md;
@@ -49,7 +49,7 @@ public override void VisitManagedMethod (MethodDefinition method)
public override void VisitObjCPropertyDecl (ObjCPropertyDecl decl)
{
// don't process methods (or types) that are unavailable for the current platform
- if (!decl.IsAvailable () || !(decl.DeclContext as Decl).IsAvailable ())
+ if (!decl.IsAvailable () || !(((Decl) decl.DeclContext!).IsAvailable ()))
return;
// does not look exposed, but part of the dump
@@ -67,7 +67,7 @@ public override void VisitObjCPropertyDecl (ObjCPropertyDecl decl)
public override void VisitObjCMethodDecl (ObjCMethodDecl decl)
{
// don't process methods (or types) that are unavailable for the current platform
- if (!decl.IsAvailable () || !(decl.DeclContext as Decl).IsAvailable ())
+ if (!decl.IsAvailable () || !(((Decl) decl.DeclContext!).IsAvailable ()))
return;
// does not look exposed, but part of the dump
diff --git a/tests/xtro-sharpie/xtro-sharpie/xtro-sharpie.csproj b/tests/xtro-sharpie/xtro-sharpie/xtro-sharpie.csproj
index 6f6eba16dbe4..46a03e54fe0f 100644
--- a/tests/xtro-sharpie/xtro-sharpie/xtro-sharpie.csproj
+++ b/tests/xtro-sharpie/xtro-sharpie/xtro-sharpie.csproj
@@ -10,6 +10,10 @@
osx-arm64
false
+
+ enable
+ Nullable
+ true