mardi 14 juillet 2020

Converting null literal or possible null value to non-nullable type

Is it possible to resolve this warning:

Converting null literal or possible null value to non-nullable type.

without suppression for this C# code

 List<PropertyInfo> sourceProperties = sourceObject.GetType().GetProperties().ToList<PropertyInfo>();
            List<PropertyInfo> destinationProperties = destinationObject.GetType().GetProperties().ToList<PropertyInfo>();

            foreach (PropertyInfo sourceProperty in sourceProperties)
            {
                if (!Equals(destinationProperties, null))
                {
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
                    PropertyInfo destinationProperty = destinationProperties.Find(item => item.Name == sourceProperty.Name);
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.

                   
                }
            }

that uses Reflection.

enter image description here

I am using Visual Studio 2019 and .NET Core 3.1.





Aucun commentaire:

Enregistrer un commentaire