Skip to content

Commit

Permalink
Updates for #65, nullable ref types.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdorman committed Jan 30, 2021
1 parent d3bac0b commit 6e48d7f
Show file tree
Hide file tree
Showing 46 changed files with 1,125 additions and 455 deletions.
4 changes: 4 additions & 0 deletions common.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ projects from the command-line or the IDE. -->
<ItemGroup>
<None Include="$(SolutionDir)\Cadru.licenseheader" Link="Cadru.licenseheader" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Validation" Version="2.5.5-beta" PrivateAssets="all" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>
<Description>Provides additional ASP.NET Core TagHelpers.</Description>
<PackageTags>$(CommonPackageTags) aspnetcore taghelper rendering</PackageTags>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions src/Cadru.AspNetCore.Mvc/Extensions/StateManagementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ namespace Cadru.AspNetCore.Mvc.Extensions
/// </summary>
public static class StateManagementExtensions
{
private static string GetTypeName<T>()
{
var type = typeof(T);
return $"{type.Namespace}.{type.Name}";
}

/// <summary>
/// Gets the value associated with the specified key.
/// </summary>
Expand All @@ -57,7 +63,7 @@ public static class StateManagementExtensions
[return: MaybeNull]
public static T Get<T>(this ITempDataDictionary storageProvider)
{
storageProvider.TryGetValue<T>(typeof(T).FullName, out var value);
storageProvider.TryGetValue<T>(GetTypeName<T>(), out var value);
return value;
}

Expand Down Expand Up @@ -99,7 +105,7 @@ public static T Get<T>(this ITempDataDictionary storageProvider, string key)
[return: MaybeNull]
public static T Get<T>(this ISession storageProvider)
{
storageProvider.TryGetValue<T>(typeof(T).FullName, out var value);
storageProvider.TryGetValue<T>(GetTypeName<T>(), out var value);
return value;
}

Expand Down Expand Up @@ -141,7 +147,7 @@ public static T Get<T>(this ISession storageProvider, string key)
[return: MaybeNull]
public static T Get<T>(this ViewDataDictionary storageProvider)
{
storageProvider.TryGetValue<T>(typeof(T).FullName, out var value);
storageProvider.TryGetValue<T>(GetTypeName<T>(), out var value);
return value;
}

Expand Down Expand Up @@ -184,7 +190,7 @@ public static T Get<T>(this ViewDataDictionary storageProvider, string key)
[return: MaybeNull]
public static T Peek<T>(this ITempDataDictionary storageProvider)
{
storageProvider.TryPeekValue<T>(typeof(T).FullName, out var value);
storageProvider.TryPeekValue<T>(GetTypeName<T>(), out var value);
return value;
}

Expand Down Expand Up @@ -228,7 +234,7 @@ public static T Peek<T>(this ITempDataDictionary storageProvider, string key)
[return: MaybeNull]
public static T Peek<T>(this ISession storageProvider)
{
return storageProvider.Get<T>(typeof(T).FullName);
return storageProvider.Get<T>(GetTypeName<T>());
}

/// <summary>
Expand Down Expand Up @@ -321,7 +327,7 @@ public static T Peek<T>(this ViewDataDictionary storageProvider, string key)
/// </remarks>
public static void Put<T>(this ITempDataDictionary storageProvider, T value)
{
storageProvider.Put(typeof(T).FullName, value);
storageProvider.Put(GetTypeName<T>(), value);
}

/// <summary>
Expand Down Expand Up @@ -355,7 +361,7 @@ public static void Put<T>(this ITempDataDictionary storageProvider, string key,
/// </remarks>
public static void Put<T>(this ISession storageProvider, T value)
{
storageProvider.Put(typeof(T).FullName, value);
storageProvider.Put(GetTypeName<T>(), value);
}

/// <summary>
Expand Down Expand Up @@ -389,7 +395,7 @@ public static void Put<T>(this ISession storageProvider, string key, T value)
/// </remarks>
public static void Put<T>(this ViewDataDictionary storageProvider, T value)
{
storageProvider.Put(typeof(T).FullName, value);
storageProvider.Put(GetTypeName<T>(), value);
}

/// <summary>
Expand Down Expand Up @@ -423,7 +429,6 @@ public static void Put<T>(this ViewDataDictionary storageProvider, string key, T
/// <paramref name="storageProvider"/> contains an element with the
/// specified key; otherwise, <see langword="false"></see>.
/// </returns>
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<Pending>")]
public static bool TryGetValue<T>(this ITempDataDictionary storageProvider, string key, [MaybeNull] out T value)
{
var valid = false;
Expand Down Expand Up @@ -461,7 +466,6 @@ public static bool TryGetValue<T>(this ITempDataDictionary storageProvider, stri
/// <paramref name="storageProvider"/> contains an element with the
/// specified key; otherwise, <see langword="false"></see>.
/// </returns>
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<Pending>")]
public static bool TryGetValue<T>(this ISession storageProvider, string key, [MaybeNull] out T value)
{
var valid = false;
Expand Down Expand Up @@ -500,7 +504,6 @@ public static bool TryGetValue<T>(this ISession storageProvider, string key, [Ma
/// <paramref name="storageProvider"/> contains an element with the
/// specified key; otherwise, <see langword="false"></see>.
/// </returns>
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<Pending>")]
public static bool TryGetValue<T>(this ViewDataDictionary storageProvider, string key, [MaybeNull] out T value)
{
var valid = false;
Expand Down Expand Up @@ -539,7 +542,6 @@ public static bool TryGetValue<T>(this ViewDataDictionary storageProvider, strin
/// <paramref name="storageProvider"/> contains an element with the
/// specified key; otherwise, <see langword="false"></see>.
/// </returns>
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<Pending>")]
public static bool TryPeekValue<T>(this ITempDataDictionary storageProvider, string key, [MaybeNull] out T value)
{
var valid = false;
Expand Down
2 changes: 2 additions & 0 deletions src/Cadru.Build.Tasks/Cadru.Build.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>
<Description>Provides additional MSBuild tasks.</Description>
<PackageTags>$(CommonPackageTags) collections logical natural string comparison date comparison comparer</PackageTags>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="RoslynWriteThisAssemblyCodeFile.cs" />
Expand Down
14 changes: 11 additions & 3 deletions src/Cadru.Caching/CacheKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@ public CacheKey(string prefix, IEnumerable<object>? data)

foreach (var element in e)
{
tempBuilder.Add(element.ToString());
var key = element.ToString();
if (!String.IsNullOrWhiteSpace(key))
{
tempBuilder.Add(key);
}
}

keyBuilder.Add(String.Join("-", tempBuilder));
}
else
{
keyBuilder.Add(d.ToString());
var key = d.ToString();
if (!String.IsNullOrWhiteSpace(key))
{
keyBuilder.Add(key);
}
}
}
}
Expand All @@ -119,7 +127,7 @@ public CacheKey(string prefix, IEnumerable<object>? data)
private int Hash { get; }

/// <inheritdoc/>
public override bool Equals(object obj) => (obj is CacheKey key) ? this.Key == key.Key : this == obj;
public override bool Equals(object? obj) => (obj is CacheKey key) ? this.Key == key.Key : this == obj;

/// <inheritdoc/>
public override int GetHashCode() => this.Hash;
Expand Down
Loading

0 comments on commit 6e48d7f

Please sign in to comment.