Skip to content

Commit

Permalink
update Nullable Reference Types VS 16.2
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Aug 5, 2019
1 parent 99a38a2 commit 92b213e
Show file tree
Hide file tree
Showing 34 changed files with 216 additions and 116 deletions.
2 changes: 1 addition & 1 deletion Signum.Engine/BulkInserter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static int BulkInsertQueryIds<T, K>(this IEnumerable<T> entities,
int? timeout = null,
string? message = null)
where T : Entity
where K : object
where K : notnull
{
using (HeavyProfiler.Log(nameof(BulkInsertQueryIds), () => typeof(T).TypeName()))
using (Transaction tr = new Transaction())
Expand Down
6 changes: 3 additions & 3 deletions Signum.Engine/DynamicQuery/ExpressionContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public ExtensionDictionaryInfo<T, KVP, K, V> RegisterDictionary<T, KVP, K, V>(
Expression<Func<KVP, V>> valueSelector,
ResetLazy<HashSet<K>>? allKeys = null)
where T : Entity
where K : object
where K : notnull
{
var mei = new ExtensionDictionaryInfo<T, KVP, K, V>(collectionSelector, keySelector, valueSelector,
allKeys ?? GetAllKeysLazy<T, KVP, K>(collectionSelector, keySelector));
Expand All @@ -126,7 +126,7 @@ public ExtensionDictionaryInfo<M, KVP, K, V> RegisterDictionaryInEmbedded<T, M,
ResetLazy<HashSet<K>>? allKeys = null)
where T : Entity
where M : ModifiableEntity
where K : object
where K : notnull
{
var mei = new ExtensionDictionaryInfo<M, KVP, K, V>(collectionSelector, keySelector, valueSelector,
allKeys ?? GetAllKeysLazy<T, KVP, K>(CombineSelectors(embeddedSelector, collectionSelector), keySelector));
Expand Down Expand Up @@ -173,7 +173,7 @@ public interface IExtensionDictionaryInfo
}

public class ExtensionDictionaryInfo<T, KVP, K, V> : IExtensionDictionaryInfo
where K : object
where K : notnull
{
public ResetLazy<HashSet<K>> AllKeys;

Expand Down
6 changes: 3 additions & 3 deletions Signum.Engine/Engine/Synchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void Synchronize<K, N, O>(
Action<K, N>? createNew,
Action<K, O>? removeOld,
Action<K, N, O>? merge)
where K : object
where K : notnull
{
HashSet<K> keys = new HashSet<K>();
keys.UnionWith(oldDictionary.Keys);
Expand Down Expand Up @@ -48,7 +48,7 @@ public static void SynchronizeProgressForeach<K, N, O>(
Action<K, N, O>? merge,
bool showProgress = true,
bool transactional = true)
where K : object
where K : notnull
{
HashSet<K> keys = new HashSet<K>();
keys.UnionWith(oldDictionary.Keys);
Expand Down Expand Up @@ -120,7 +120,7 @@ public static void SynchronizeReplacing<N, O>(
Func<K, N, O, SqlPreCommand?>? mergeBoth)
where O : class
where N : class
where K : object
where K : notnull
{
return newDictionary.OuterJoinDictionaryCC(oldDictionary, (key, newVal, oldVal) =>
{
Expand Down
3 changes: 3 additions & 0 deletions Signum.Engine/Linq/ExpressionVisitor/DbExpressionNominator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
Expand Down Expand Up @@ -61,6 +62,7 @@ static internal HashSet<Expression> Nominate(Expression? expression, out Express
return n.candidates;
}

[return: NotNullIfNotNull("expression")]
static internal Expression? FullNominate(Expression? expression)
{
DbExpressionNominator n = new DbExpressionNominator { isFullNominate = true };
Expand All @@ -69,6 +71,7 @@ static internal HashSet<Expression> Nominate(Expression? expression, out Express
return result;
}

[return: NotNullIfNotNull("expression")]
static internal Expression? FullNominateNotNullable(Expression? expression)
{
DbExpressionNominator n = new DbExpressionNominator { isFullNominate = true, isNotNullRoot = expression };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected internal virtual Expression VisitTypeEntity(TypeEntityExpression typeF

[DebuggerStepThrough]
protected static ReadOnlyDictionary<K, V> Visit<K, V>(ReadOnlyDictionary<K, V> dictionary, Func<V, V> newValue)
where K : object
where K : notnull
where V : class
{
Dictionary<K, V>? alternate = null;
Expand Down
4 changes: 2 additions & 2 deletions Signum.Engine/Linq/ExpressionVisitor/QueryBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ private ProjectionExpression GetTableValuedFunctionProjection(MethodCallExpressi

var functionName = mce.Method.GetCustomAttribute<SqlMethodAttribute>().Name ?? mce.Method.Name;

var argumens = mce.Arguments.Select(DbExpressionNominator.FullNominate).ToList();
var argumens = mce.Arguments.Select(a => DbExpressionNominator.FullNominate(a)!).ToList();

SqlTableValuedFunctionExpression tableExpression = new SqlTableValuedFunctionExpression(functionName, table, tableAlias, argumens);

Expand Down Expand Up @@ -2425,7 +2425,7 @@ public void FillColumnAssigments(List<ColumnAssignment> assignments, ParameterEx

private Exception InvalidBody()
{
throw new InvalidOperationException("The only allowed expressions on UnsafeInsert are: object initializers, calling method 'SetMixin', or or calling 'Administrator.SetReadonly'");
throw new InvalidOperationException("The only allowed expressions on UnsafeInsert are: notnull initializers, calling method 'SetMixin', or or calling 'Administrator.SetReadonly'");
}

private ColumnAssignment[] AdaptAssign(Expression colExpression, Expression exp)
Expand Down
5 changes: 3 additions & 2 deletions Signum.Engine/Schema/SchemaBuilder/SchemaBuilderSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Concurrent;
using Signum.Utilities.ExpressionTrees;
using System.Runtime.CompilerServices;
using Signum.Utilities.Reflection;

namespace Signum.Engine.Maps
{
Expand Down Expand Up @@ -224,8 +225,8 @@ private IsNullable GetIsNullablePrivate(PropertyRoute propertyRoute)
if (propertyRoute.Type.IsValueType)
return propertyRoute.Type.IsNullable() ? IsNullable.Yes : IsNullable.No;

var nullable = FieldAttribute<NullableAttribute>(propertyRoute);
if (nullable != null && nullable.IsNullableMain == true)
var nullable = propertyRoute.FieldInfo?.IsNullable();
if (nullable == true)
return IsNullable.Yes;

return IsNullable.No;
Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine/Signum.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>preview</LangVersion>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NullableContextOptions>enable</NullableContextOptions>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Platforms>x64;x86;AnyCPU</Platforms>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Signum.Entities.DynamicQuery
{
[Serializable]
public class ExtensionDictionaryToken<T, K, V> : QueryToken
where K : object
where K : notnull
{
QueryToken parent;
public override QueryToken? Parent => parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override int GetHashCode(T obj)
}

public class ClassStructuralEqualityComparer<T> : EqualityComparer<T>, ICompletableComparer
where T: object
where T: notnull
{
public Dictionary<string, PropertyComparer<T>> Properties;

Expand Down
8 changes: 6 additions & 2 deletions Signum.Entities/Signum.Entities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>preview</LangVersion>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NullableContextOptions>enable</NullableContextOptions>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Platforms>x64;x86;AnyCPU</Platforms>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Signum.Analyzer" Version="2.0.0" />
<PackageReference Include="Signum.MSBuildTask" Version="1.0.3" />
Expand Down
4 changes: 2 additions & 2 deletions Signum.Entities/TimeZoneManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Signum.Utilities;

namespace Signum.Entities
Expand Down Expand Up @@ -29,7 +29,7 @@ public static void IncrementOverridenNow(TimeSpan ts)
if (OverrideNowVariable.Value == null)
throw new InvalidOperationException("OverridenNow is not set");

OverrideNowVariable.Value += ts;
OverrideNowVariable.Value = OverrideNowVariable.Value!.Value + ts;
}


Expand Down
4 changes: 2 additions & 2 deletions Signum.Entities/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ internal PropertyValidator(PropertyInfo pi)

this.Validators = pi.GetCustomAttributes(typeof(ValidatorAttribute), false).OfType<ValidatorAttribute>().OrderBy(va => va.Order).ThenBy(va => va.GetType().Name).ToList();

var nullable = pi.GetCustomAttribute<NullableAttribute>();
if (nullable != null && nullable.IsNullableMain == false && !this.Validators.Any(v => v is NotNullValidatorAttribute))
var nullable = pi.IsNullable();
if (nullable == false && !this.Validators.Any(v => v is NotNullValidatorAttribute))
this.Validators.Add(new NotNullValidatorAttribute());

this.GetValue = ReflectionTools.CreateGetter<T>(pi)!;
Expand Down
12 changes: 0 additions & 12 deletions Signum.MSBuildTask/Properties/PublishProfiles/FolderProfile.pubxml

This file was deleted.

2 changes: 1 addition & 1 deletion Signum.MSBuildTask/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profiles": {
"Signum.Test": {
"commandName": "Project",
"commandName": "Signum.Test",
"commandLineArgs": "\"obj\\Debug\\netcoreapp2.2\\Signum.Test.dll\" \"D:\\Signum\\Southwind\\Framework\\Signum.Test\\obj\\SignumReferences.txt\"",
"workingDirectory": "D:\\Signum\\Southwind\\Framework\\Signum.Test\\"
}
Expand Down
6 changes: 1 addition & 5 deletions Signum.MSBuildTask/Signum.MSBuildTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<LangVersion>latest</LangVersion>
<Platforms>x64</Platforms>
<Platforms>x64;AnyCPU</Platforms>
<NuSpecFile>Signum.MSBuildTask.nuspec</NuSpecFile>
<Version>1.0.3</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mono.Cecil" Version="0.10.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions Signum.React/Signum.React.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TypeScriptToolsVersion>3.5</TypeScriptToolsVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>preview</LangVersion>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NullableContextOptions>enable</NullableContextOptions>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<OutputType>Library</OutputType>
<StartupObject></StartupObject>
Expand Down
17 changes: 15 additions & 2 deletions Signum.TSGenerator/EntityDeclarationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,13 @@ private static string EntityInTypeScript(TypeDefinition type, Options options)

var properties = GetProperties(type);

var defaultNullableCustomAttribute = type.NullableContextAttribute();


foreach (var prop in properties)
{
string context = $"By type {type.Name} and property {prop.Name}";
var propertyType = TypeScriptNameInternal(prop.PropertyType, type, options, context) + (prop.GetTypescriptNull() ? " | null" : "");
var propertyType = TypeScriptNameInternal(prop.PropertyType, type, options, context) + (prop.GetTypescriptNull(defaultNullableCustomAttribute) ? " | null" : "");

var undefined = prop.GetTypescriptUndefined() ? "?" : "";

Expand All @@ -348,6 +351,13 @@ private static string EntityInTypeScript(TypeDefinition type, Options options)
return sb.ToString();
}

static CustomAttribute NullableContextAttribute(this TypeDefinition type)
{
return type.CustomAttributes.SingleOrDefault(a => a.AttributeType.Name == "NullableContextAttribute") ?? type.DeclaringType?.NullableContextAttribute();
}



static bool IsModifiableEntity(TypeDefinition t)
{
if (t.IsValueType || t.IsInterface)
Expand Down Expand Up @@ -465,7 +475,7 @@ public static bool GetTypescriptUndefined(this PropertyDefinition p)
return (bool?)inTSAttr?.Properties.SingleOrDefault(a => a.Name == "Undefined").Argument.Value;
}

public static bool GetTypescriptNull(this PropertyDefinition p)
public static bool GetTypescriptNull(this PropertyDefinition p, CustomAttribute defaultCustomAttribute)
{
var inTSAttr = p.CustomAttributes.SingleOrDefault(a => a.AttributeType.FullName == Cache.InTypeScriptAttribute.FullName);

Expand All @@ -479,6 +489,9 @@ public static bool GetTypescriptNull(this PropertyDefinition p)
{
var nullableAttr = p.CustomAttributes.SingleOrDefault(a => a.AttributeType.Name == "NullableAttribute");

if (nullableAttr == null)
nullableAttr = defaultCustomAttribute;

if (nullableAttr == null)
return false;

Expand Down
2 changes: 1 addition & 1 deletion Signum.TSGenerator/Signum.TSGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<LangVersion>latest</LangVersion>
<Platforms>x64</Platforms>
<Platforms>x64;AnyCPU</Platforms>
<Version>2.0.2</Version>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions Signum.Test/Signum.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>preview</LangVersion>
<UserSecretsId>SignumTest</UserSecretsId>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<NullableContextOptions>enable</NullableContextOptions>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Platforms>x64;x86;AnyCPU</Platforms>
</PropertyGroup>
Expand All @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Signum.Analyzer" Version="2.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
Expand Down
2 changes: 1 addition & 1 deletion Signum.Utilities/ConsoleSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Signum.Utilities
{
public class ConsoleSwitch<K, V> : IEnumerable<KeyValuePair<string, WithDescription<V>>>
where K : object
where K : notnull
where V : class
{
readonly Dictionary<string, WithDescription<V>> dictionary = new Dictionary<string, WithDescription<V>>(StringComparer.InvariantCultureIgnoreCase);
Expand Down
4 changes: 2 additions & 2 deletions Signum.Utilities/DataStructures/DirectedEdgedGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Signum.Utilities.DataStructures
{
public class DirectedEdgedGraph<T, E> : IEnumerable<T>
where T: object
where T: notnull
{
Dictionary<T, Dictionary<T, E>> adjacency;
public IEqualityComparer<T> Comparer { get; private set; }
Expand Down Expand Up @@ -609,7 +609,7 @@ public override string ToString()
public static class DirectedEdgedGraphExtensions
{
public static E GetOrCreate<T, E>(this DirectedEdgedGraph<T, E> graph, T from, T to)
where T : object
where T : notnull
where E : new()
{
var dic = graph.TryRelatedTo(from);
Expand Down
2 changes: 1 addition & 1 deletion Signum.Utilities/DataStructures/DirectedGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Signum.Utilities.DataStructures
{
public class DirectedGraph<T> : IEnumerable<T>
where T : object
where T : notnull
{
readonly Dictionary<T, HashSet<T>> adjacency;
public IEqualityComparer<T> Comparer { get; private set; }
Expand Down
4 changes: 2 additions & 2 deletions Signum.Utilities/DataStructures/ImmutableStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ internal ImmutableStack() { }

public static class ImmutableStackExtensions
{
public static ImmutableStack<T> Reverse<T>(this ImmutableStack<T> stack) where T : object
public static ImmutableStack<T> Reverse<T>(this ImmutableStack<T> stack) where T : notnull
{
return Reverse(stack, ImmutableStack<T>.Empty);
}

public static ImmutableStack<T> Reverse<T>(this ImmutableStack<T> stack, ImmutableStack<T> initial) where T : object
public static ImmutableStack<T> Reverse<T>(this ImmutableStack<T> stack, ImmutableStack<T> initial) where T : notnull
{
ImmutableStack<T> r = initial;
for (ImmutableStack<T> f = stack; !f.IsEmpty; f = f.Pop())
Expand Down
2 changes: 1 addition & 1 deletion Signum.Utilities/ExpressionTrees/ExpressionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public override int GetHashCode()
{
return cachedStaticGetters.GetOrAdd((type: mi.DeclaringType, name: mi.Name), _ =>
{
return Expression.Lambda<Func<object?>>(Expression.Convert(Expression.MakeMemberAccess(null, mi), typeof(object?))).Compile();
return Expression.Lambda<Func<object?>>(Expression.Convert(Expression.MakeMemberAccess(null, mi), typeof(object))).Compile();
});
}

Expand Down
Loading

2 comments on commit 92b213e

@olmobrutall
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to Null Reference Type changes in VS 16.2

Looks like .Net / Roslyn team are working hard in polishing Null Reference Types for .Net Core 3.0, in the latest update of VS the nullability analysis has two main changes.

With this commits (until 9e4eb08) the framework, extensions ans southwind are updated to this changes.

Enjoy!

@MehdyKarimpour
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Please sign in to comment.