Skip to content

Commit

Permalink
fix some nullability warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 9, 2025
1 parent bbce070 commit b4f8c6f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal static void SetAppDomainFrameworkVersionBasedOnTestSource(AppDomainSetu
{
if (GetTargetFrameworkVersionFromVersionString(frameworkVersionString).CompareTo(Version45) > 0)
{
PropertyInfo pInfo = typeof(AppDomainSetup).GetProperty(Constants.TargetFrameworkName);
PropertyInfo? pInfo = typeof(AppDomainSetup).GetProperty(Constants.TargetFrameworkName);
pInfo?.SetValue(setup, frameworkVersionString, null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private static Task<Document> SwapArgumentsAsync(Document document, SyntaxNode r

SeparatedSyntaxList<ArgumentSyntax> arguments = invocationExpr.ArgumentList.Arguments;

ArgumentSyntax expectedArg = arguments.FirstOrDefault(IsExpectedArgument);
ArgumentSyntax actualArg = arguments.FirstOrDefault(IsActualArgument);
ArgumentSyntax? expectedArg = arguments.FirstOrDefault(IsExpectedArgument);
ArgumentSyntax? actualArg = arguments.FirstOrDefault(IsActualArgument);

// Handle positional arguments if named arguments are not found
if (expectedArg == null || actualArg == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
}

// Find the method declaration identified by the diagnostic.
MethodDeclarationSyntax methodDeclaration = syntaxToken.Parent.AncestorsAndSelf().OfType<MethodDeclarationSyntax>().FirstOrDefault();
MethodDeclarationSyntax? methodDeclaration = syntaxToken.Parent.AncestorsAndSelf().OfType<MethodDeclarationSyntax>().FirstOrDefault();
if (methodDeclaration == null)
{
return;
Expand All @@ -64,7 +64,7 @@ private static async Task<Document> ReplaceTestInitializeWithConstructorAsync(Do
// Find the class containing the method
if (testInitializeMethod.Parent is ClassDeclarationSyntax containingClass)
{
ConstructorDeclarationSyntax existingConstructor = containingClass.Members
ConstructorDeclarationSyntax? existingConstructor = containingClass.Members
.OfType<ConstructorDeclarationSyntax>()
.FirstOrDefault();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
}

// Find the TestCleanup method declaration identified by the diagnostic.
MethodDeclarationSyntax testCleanupMethod = syntaxToken.Parent.AncestorsAndSelf().OfType<MethodDeclarationSyntax>().FirstOrDefault();
MethodDeclarationSyntax? testCleanupMethod = syntaxToken.Parent.AncestorsAndSelf().OfType<MethodDeclarationSyntax>().FirstOrDefault();
if (testCleanupMethod == null ||
!IsTestCleanupMethodValid(testCleanupMethod) ||
testCleanupMethod.Parent is not TypeDeclarationSyntax containingType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
}

// Find the constructor declaration identified by the diagnostic.
ConstructorDeclarationSyntax constructorDeclaration = syntaxToken.Parent.AncestorsAndSelf().OfType<ConstructorDeclarationSyntax>().FirstOrDefault();
ConstructorDeclarationSyntax? constructorDeclaration = syntaxToken.Parent.AncestorsAndSelf().OfType<ConstructorDeclarationSyntax>().FirstOrDefault();
if (constructorDeclaration == null)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void ChildDomainResolutionPathsShouldHaveSearchDirectoriesSpecifiedInRuns

// Creating instance of SampleProjectForAssemblyResolution should not throw.
// It is present in <Directory path = ".\ComponentTests" /> specified in runsettings
AppDomainUtilities.CreateInstance(_testSourceHost.AppDomain, type, null);
AppDomainUtilities.CreateInstance(_testSourceHost.AppDomain!, type, null);
}

public void DisposeShouldUnloadChildAppDomain()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ReflectionUtilityTests()

public void GetCustomAttributesShouldReturnAllAttributes()
{
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestBaseClass").GetMethod("DummyVTestMethod1");
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestBaseClass").GetMethod("DummyVTestMethod1")!;

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, false);

Expand All @@ -51,7 +51,7 @@ public void GetCustomAttributesShouldReturnAllAttributes()

public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance()
{
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1");
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1")!;

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, false);

Expand All @@ -64,7 +64,7 @@ public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance(

public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance()
{
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1");
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1")!;

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, true);

Expand Down Expand Up @@ -117,7 +117,7 @@ public void GetCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritanc

public void GetSpecificCustomAttributesShouldReturnAllAttributes()
{
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestBaseClass").GetMethod("DummyVTestMethod1");
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestBaseClass").GetMethod("DummyVTestMethod1")!;

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(TestCategoryAttribute), false);

Expand All @@ -130,7 +130,7 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributes()

public void GetSpecificCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance()
{
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1");
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1")!;

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(TestCategoryAttribute), false);

Expand All @@ -144,7 +144,7 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributesIgnoringBaseInhe
public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInheritance()
{
MethodInfo methodInfo =
_testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1");
_testAsset.GetType("TestProjectForDiscovery.AttributeTestClass").GetMethod("DummyVTestMethod1")!;

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(TestCategoryAttribute), true);

Expand All @@ -157,7 +157,7 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInherita

public void GetCustomAttributesShouldReturnAllAttributesIncludingUserDefinedAttributes()
{
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyVTestMethod1");
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyVTestMethod1")!;

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, null, true);

Expand All @@ -170,7 +170,7 @@ public void GetCustomAttributesShouldReturnAllAttributesIncludingUserDefinedAttr

public void GetSpecificCustomAttributesShouldReturnAllAttributesIncludingUserDefinedAttributes()
{
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyVTestMethod1");
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyVTestMethod1")!;

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(TestPropertyAttribute), true);

Expand All @@ -183,7 +183,7 @@ public void GetSpecificCustomAttributesShouldReturnAllAttributesIncludingUserDef

public void GetSpecificCustomAttributesShouldReturnArrayAttributesAsWell()
{
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyTestMethod2");
MethodInfo methodInfo = _testAsset.GetType("TestProjectForDiscovery.AttributeTestClassWithCustomAttributes").GetMethod("DummyTestMethod2")!;

IReadOnlyList<object> attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(CategoryArrayAttribute), true);

Expand Down

0 comments on commit b4f8c6f

Please sign in to comment.