Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static bool IsPartialBlock (Expression item)
};
}

private static bool IsDetachedClosingElement(Expression item, Expression? parentItem, [MaybeNullWhen(false)] out string closingElement)
private static bool IsDetachedClosingElement(Expression item, Expression? parentItem, [NotNullWhen(true)] out string? closingElement)
{
closingElement = null;

Expand Down
2 changes: 1 addition & 1 deletion source/Handlebars/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace HandlebarsDotNet
{
internal static class TypeExtensions
{
public static bool IsAssignableToGenericType(this Type givenType, Type genericType, [MaybeNullWhen(false)] out Type resolvedType)
public static bool IsAssignableToGenericType(this Type givenType, Type genericType, [NotNullWhen(true)] out Type? resolvedType)
{
while (true)
{
Expand Down
4 changes: 2 additions & 2 deletions source/Handlebars/Helpers/IHelperResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public interface IHelperResolver
/// <param name="targetType"></param>
/// <param name="helper"></param>
/// <returns></returns>
bool TryResolveHelper(PathInfo name, Type? targetType, [MaybeNullWhen(false)] out IHelperDescriptor<HelperOptions> helper);
bool TryResolveHelper(PathInfo name, Type? targetType, [NotNullWhen(true)] out IHelperDescriptor<HelperOptions>? helper);

/// <summary>
/// Resolves <see cref="HandlebarsBlockHelper"/>
/// </summary>
/// <param name="name"></param>
/// <param name="helper"></param>
/// <returns></returns>
bool TryResolveBlockHelper(PathInfo name, [MaybeNullWhen(false)] out IHelperDescriptor<BlockHelperOptions> helper);
bool TryResolveBlockHelper(PathInfo name, [NotNullWhen(true)] out IHelperDescriptor<BlockHelperOptions>? helper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CollectionFormatterProvider : IFormatterProvider
private static readonly Type CollectionFormatterType = typeof(CollectionFormatter<,>);
private static readonly Type CollectionType = typeof(ICollection<>);

public bool TryCreateFormatter(Type type, [MaybeNullWhen(false)] out IFormatter formatter)
public bool TryCreateFormatter(Type type, [NotNullWhen(true)] out IFormatter? formatter)
{
if (!type.GetTypeInfo().IsClass || !type.IsAssignableToGenericType(CollectionType, out var genericType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DefaultFormatterProvider : IFormatterProvider

private static readonly DefaultObjectFormatter DefaultObjectFormatter = new DefaultObjectFormatter();

public bool TryCreateFormatter(Type type, [MaybeNullWhen(false)] out IFormatter formatter)
public bool TryCreateFormatter(Type type, [NotNullWhen(true)] out IFormatter? formatter)
{
if (!Formatters.TryGetValue(type, out formatter))
{
Expand Down
2 changes: 1 addition & 1 deletion source/Handlebars/IO/Formatters/FormatterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public FormatterProvider Append(FormatterProvider provider)
return this;
}

public bool TryCreateFormatter(Type type, [MaybeNullWhen(false)] out IFormatter formatter)
public bool TryCreateFormatter(Type type, [NotNullWhen(true)] out IFormatter? formatter)
{
formatter = _formatters.GetOrAdd(type, ValueFactory, _formatterProviders).Value;
return formatter != null;
Expand Down
2 changes: 1 addition & 1 deletion source/Handlebars/IO/Formatters/IFormatterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace HandlebarsDotNet.IO
{
public interface IFormatterProvider
{
bool TryCreateFormatter(Type type, [MaybeNullWhen(false)] out IFormatter formatter);
bool TryCreateFormatter(Type type, [NotNullWhen(true)] out IFormatter? formatter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ReadOnlyCollectionFormatterProvider : IFormatterProvider
private static readonly Type CollectionFormatterType = typeof(ReadOnlyCollectionFormatter<,>);
private static readonly Type CollectionType = typeof(IReadOnlyCollection<>);

public bool TryCreateFormatter(Type type, [MaybeNullWhen(false)] out IFormatter formatter)
public bool TryCreateFormatter(Type type, [NotNullWhen(true)] out IFormatter? formatter)
{
if (!type.GetTypeInfo().IsClass || !type.IsAssignableToGenericType(CollectionType, out var genericType))
{
Expand Down
2 changes: 1 addition & 1 deletion source/Handlebars/IO/Formatters/UndefinedFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class UndefinedFormatter : IFormatter, IFormatterProvider

public string? FormatString { get; set; }

public bool TryCreateFormatter(Type type, [MaybeNullWhen(false)] out IFormatter formatter)
public bool TryCreateFormatter(Type type, [NotNullWhen(true)] out IFormatter? formatter)
{
if (type != typeof(UndefinedBindingResult))
{
Expand Down
2 changes: 1 addition & 1 deletion source/Handlebars/LayoutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public DescriptorProvider()
);
}

public bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
if (type != Type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class DictionaryObjectDescriptor : IObjectDescriptorProvider

private static readonly Func<ObjectDescriptor, object, IEnumerable> GetProperties = (descriptor, arg) => ((IDictionary) arg).Keys;

public bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
if (!Type.IsAssignableFrom(type))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public DynamicObjectDescriptor(ObjectDescriptorProvider objectDescriptorProvider
_objectDescriptorProvider = objectDescriptorProvider;
}

public bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
if (!Type.IsAssignableFrom(type))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public EnumerableObjectDescriptor(ObjectDescriptorProvider descriptorProvider)
_descriptorProvider = descriptorProvider;
}

public bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
if (!(type != StringType && Type.IsAssignableFrom(type)))
{
Expand Down Expand Up @@ -86,7 +86,7 @@ public bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescrip
|| TryCreateDescriptor(type, typeof(IEnumerable), parameters, NonGenericEnumerableObjectDescriptorFactoryMethodInfo, out value);
}

private static bool TryCreateArrayDescriptor(Type type, object[] parameters, [MaybeNullWhen(false)] out ObjectDescriptor value)
private static bool TryCreateArrayDescriptor(Type type, object[] parameters, [NotNullWhen(true)] out ObjectDescriptor? value)
{
if (!type.IsArray)
{
Expand All @@ -109,7 +109,7 @@ private static bool TryCreateArrayDescriptor(Type type, object[] parameters, [Ma
return true;
}

private static bool TryCreateDescriptorFromOpenGeneric(Type type, Type openGenericType, object[] parameters, MethodInfo method, [MaybeNullWhen(false)] out ObjectDescriptor descriptor)
private static bool TryCreateDescriptorFromOpenGeneric(Type type, Type openGenericType, object[] parameters, MethodInfo method, [NotNullWhen(true)] out ObjectDescriptor? descriptor)
{
if (type.IsAssignableToGenericType(openGenericType, out var genericType))
{
Expand All @@ -124,7 +124,7 @@ private static bool TryCreateDescriptorFromOpenGeneric(Type type, Type openGener
return false;
}

private static bool TryCreateDescriptor(Type type, Type targetType, object[] parameters, MethodInfo method, [MaybeNullWhen(false)] out ObjectDescriptor descriptor)
private static bool TryCreateDescriptor(Type type, Type targetType, object[] parameters, MethodInfo method, [NotNullWhen(true)] out ObjectDescriptor? descriptor)
{
if (targetType.IsAssignableFrom(type))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class GenericDictionaryObjectDescriptorProvider : IObjectDescripto

private readonly LookupSlim<Type, DeferredValue<Type, Type?>, ReferenceEqualityComparer<Type>> _typeCache = new LookupSlim<Type, DeferredValue<Type, Type?>, ReferenceEqualityComparer<Type>>(new ReferenceEqualityComparer<Type>());

public bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
var interfaceType = _typeCache.GetOrAdd(type, InterfaceTypeValueFactory).Value;
if (interfaceType == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public interface IObjectDescriptorProvider
/// </summary>
/// <param name="type"></param>
/// <param name="value"></param>
bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value);
bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value);
}
}
7 changes: 4 additions & 3 deletions source/Handlebars/ObjectDescriptors/ObjectAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ public ObjectAccessor(object? data, ObjectDescriptor descriptor)
public ObjectAccessor(object? data)
{
_data = data;
if (data == null || !ObjectDescriptorFactory.Current!.TryGetDescriptor(data.GetType(), out _descriptor))
if (data == null || !ObjectDescriptorFactory.Current!.TryGetDescriptor(data.GetType(), out var descriptor))
{
_descriptor = ObjectDescriptor.Empty!;
_descriptor = ObjectDescriptor.Empty;
_memberAccessor = null;
}
else
{
_memberAccessor = _descriptor.MemberAccessor;
_descriptor = descriptor;
_memberAccessor = _descriptor.MemberAccessor;
}
}

Expand Down
8 changes: 4 additions & 4 deletions source/Handlebars/ObjectDescriptors/ObjectDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ public static ObjectDescriptor Create(Type? from)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreate(object? from, out ObjectDescriptor descriptor)
public static bool TryCreate(object? from, [NotNullWhen(true)] out ObjectDescriptor? descriptor)
{
return TryCreate(from?.GetType(), out descriptor);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryCreate(Type? @from, out ObjectDescriptor descriptor)
public static bool TryCreate(Type? @from, [NotNullWhen(true)] out ObjectDescriptor? descriptor)
{
if (from == null)
{
descriptor = Empty;
return false;
}

return ObjectDescriptorFactory.Current!.TryGetDescriptor(from, out descriptor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ObjectDescriptorFactory Append(ObjectDescriptorFactory factory)
return this;
}

public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
value = _descriptorsCache.GetOrAdd(type, ValueFactory, _providers).Value;
return !ReferenceEquals(value, ObjectDescriptor.Empty);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using HandlebarsDotNet.Collections;
Expand All @@ -21,7 +22,7 @@ public ObjectDescriptorProvider(IReadOnlyList<IMemberAliasProvider> aliasProvide
_reflectionMemberAccessor = new ReflectionMemberAccessor(aliasProviders);
}

public bool TryGetDescriptor(Type type, out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
value = new ObjectDescriptor(
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class ReadOnlyGenericDictionaryObjectDescriptorProvider : IObjectD

private readonly LookupSlim<Type, DeferredValue<Type, Type?>, ReferenceEqualityComparer<Type>> _typeCache = new LookupSlim<Type, DeferredValue<Type, Type?>, ReferenceEqualityComparer<Type>>(new ReferenceEqualityComparer<Type>());

public bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
var interfaceType = _typeCache.GetOrAdd(type, InterfaceTypeValueFactory).Value;
if (interfaceType == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class ReadOnlyStringDictionaryObjectDescriptorProvider : IObjectDe

private readonly LookupSlim<Type, DeferredValue<Type, Type?>, ReferenceEqualityComparer<Type>> _typeCache = new LookupSlim<Type, DeferredValue<Type, Type?>, ReferenceEqualityComparer<Type>>(new ReferenceEqualityComparer<Type>());

public bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
var interfaceType = _typeCache.GetOrAdd(type, InterfaceTypeValueFactory).Value;
if (interfaceType == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class StringDictionaryObjectDescriptorProvider : IObjectDescriptor

private readonly LookupSlim<Type, DeferredValue<Type, Type?>, ReferenceEqualityComparer<Type>> _typeCache = new LookupSlim<Type, DeferredValue<Type, Type?>, ReferenceEqualityComparer<Type>>(new ReferenceEqualityComparer<Type>());

public bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value)
public bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value)
{
var interfaceType = _typeCache.GetOrAdd(type, InterfaceTypeValueFactory).Value;
if (interfaceType == null)
Expand Down
Loading