nullable-reference-types Questions

1

Solved

In C# it's trivial to determine whether a value type is nullable. Specifically, you can obtain this information from the Type itself; for example: public static bool IsNullable(this Type type) =&gt...
Chaparajos asked 9/9 at 12:41

4

Solved

In C# 8 with nullable enabled, is there a way to identify a nullable reference type for generic type? For nullable value type, there is a section dedicated to it. https://learn.microsoft.com/en-us...
Openhanded asked 3/6, 2020 at 4:31

2

Solved

The extension method GetOrCreateAsync for IMemoryCache: public static async Task<TItem?> GetOrCreateAsync<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, Task<TItem&...
Cashier asked 12/1, 2023 at 8:22

1

Solved

I know it's an issue in the past since you can search the web and SO for so many questions about getting warning from EF Core model. Today I first use EF Core for .NET 8 and I just realized the war...

4

I'm trying to embrace C# 8's nullable references types in my project and make it smoothly work with EF Core. Following this guide, I made my entity classes have constructors accepting all data nee...

7

I have solution with couple .NET Standard projects in all I wanted to enable c# 8 and nullable like below: <PropertyGroup> <TargetFramework>netstandard2.1</TargetFramework> <...
Epidemic asked 17/6, 2019 at 18:36

3

In WinForms it is common that a common initialization function is initializing reference variables (for example) class SomeClass : Form { Button b; SomeClass() { InitializeComponents(); } S...
Thorrlow asked 25/3, 2019 at 12:32

7

Solved

I have a question regarding nullable reference type system available since C# 8. Suppose we have a C# domain model class with a mutable reference type property like below: public class Person { p...
Annora asked 16/3, 2020 at 6:19

7

Solved

I've recently seen the following code: public class Person { //line 1 public string FirstName { get; } //line 2 public string LastName { get; } = null!; //assign null is possible public str...
Alberic asked 16/2, 2019 at 14:53

2

MSTest offers a [ClassInitialize] attribute, which can be placed on a static method to provide one-time initialization. Assume I have a static member in a test class that I wish to initialize in su...
Meekins asked 7/2, 2021 at 17:23

2

Solved

I am trying to analyze with roslyn if a type declaration is a "Nullable Reference" type (C#8) I was planing on looking if the TypeSyntex was a NullableTypeSyntax and if the ITypeSymbol.IsReference...

5

When I use Fluent assertions to test if a property is not null, the analysers still complain about subsequent lines which dereference that line as possibly null. Is there any way to get the compile...
Pansie asked 22/9, 2021 at 11:15

6

Solved

I have a console app to try out the C# 8 null reference types. Switched the project to build with lang ver C# 8. Then the following code results in a warning. class Program { static void Main(stri...
Repertoire asked 3/4, 2019 at 9:53

6

Solved

Suppose I have List<MyObject?> list = ...; I want to turn it into List<MyObject>, but I have not been able to drop the nullable reference. Below is an MCVE. In my project I have nul...
Nightshirt asked 20/12, 2019 at 21:34

4

Solved

Using Visual Studio 2019 v16.3.2 with a .NET Core 3.0 project set to C# 8 and nullable reference types enabled. <PropertyGroup> <TargetFramework>netcoreapp3.0</TargetFramework> ...
Calculous asked 2/10, 2019 at 3:52

4

Solved

I am confused. I thought enabling c# 8 and nullable reference types will prevent the assignment of null to a non nullable reference types, but apparently it is only a warning at compile time, I kno...
Rebutter asked 6/5, 2020 at 4:49

2

Solved

I tried to use init-only properties to force client code to initialize my class when they create it, but without a constructor. It's not working as I planned. Here's the class, stripped down to ill...
Petard asked 20/12, 2021 at 22:38

5

Solved

Consider the following code: using System; #nullable enable namespace Demo { public sealed class TestClass { public string Test() { bool isNull = _test == null; if (isNull) return ""; e...
Philender asked 12/12, 2019 at 14:27

2

Possible Duplicate, but I've been unable to find anything on this. I have an asp.net core MVC project, which makes use of normal views using Razor. I have some ViewModel objects with nullable refer...
Unwilled asked 1/11, 2020 at 21:40

1

Solved

With C# 8's nullable reference types, we can write (for reference types): T x = ...; T? y = x; However, I'm having trouble understanding the conversion rules for multidimensional and jagged arrays...
Alfrediaalfredo asked 2/2, 2021 at 22:49

0

Of course, C# supports unidimensional and multidimensional arrays, and supports arrays of arrays. Famously, if, in an array of arrays, the inner array type has a different rank (dimension count) th...

2

Solved

If I have a DbContext as follows (which is a standard db context): public class MyContext : DbContext, IAudit { public MyContext(DbContextOptions options) : base(options) { } public DbSet<Au...

9

Solved

I activated this feature in a project having data transfer object (DTO) classes, as given below: public class Connection { public string ServiceUrl { get; set; } public string? UserName { get; ...
Py asked 30/11, 2019 at 16:52

1

If I have a function bool Foo(string? input), then I can annotate it to indicate that if the return is true then input is not null: public static bool Foo([NotNullWhen(true)] string? input) Is it ...
Hardener asked 27/11, 2020 at 11:51

3

When I create a new Console App (.NET Framework 4.8), and try to use C# 8's nullable reference types, I see the following: And, I get this warning in my build output: warning CS8632: The annota...

© 2022 - 2024 — McMap. All rights reserved.