diff --git a/source/Handlebars/Compiler/Lexer/Converter/BlockAccumulators/BlockAccumulatorContext.cs b/source/Handlebars/Compiler/Lexer/Converter/BlockAccumulators/BlockAccumulatorContext.cs index cd525d6f..c5b21c39 100644 --- a/source/Handlebars/Compiler/Lexer/Converter/BlockAccumulators/BlockAccumulatorContext.cs +++ b/source/Handlebars/Compiler/Lexer/Converter/BlockAccumulators/BlockAccumulatorContext.cs @@ -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; diff --git a/source/Handlebars/Extensions/TypeExtensions.cs b/source/Handlebars/Extensions/TypeExtensions.cs index 351da73b..efe6ded1 100644 --- a/source/Handlebars/Extensions/TypeExtensions.cs +++ b/source/Handlebars/Extensions/TypeExtensions.cs @@ -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) { diff --git a/source/Handlebars/Helpers/IHelperResolver.cs b/source/Handlebars/Helpers/IHelperResolver.cs index 54d79994..3285d3b9 100644 --- a/source/Handlebars/Helpers/IHelperResolver.cs +++ b/source/Handlebars/Helpers/IHelperResolver.cs @@ -16,7 +16,7 @@ public interface IHelperResolver /// /// /// - bool TryResolveHelper(PathInfo name, Type? targetType, [MaybeNullWhen(false)] out IHelperDescriptor helper); + bool TryResolveHelper(PathInfo name, Type? targetType, [NotNullWhen(true)] out IHelperDescriptor? helper); /// /// Resolves @@ -24,6 +24,6 @@ public interface IHelperResolver /// /// /// - bool TryResolveBlockHelper(PathInfo name, [MaybeNullWhen(false)] out IHelperDescriptor helper); + bool TryResolveBlockHelper(PathInfo name, [NotNullWhen(true)] out IHelperDescriptor? helper); } } \ No newline at end of file diff --git a/source/Handlebars/IO/Formatters/CollectionFormatterProvider.cs b/source/Handlebars/IO/Formatters/CollectionFormatterProvider.cs index 81918e96..9849d362 100644 --- a/source/Handlebars/IO/Formatters/CollectionFormatterProvider.cs +++ b/source/Handlebars/IO/Formatters/CollectionFormatterProvider.cs @@ -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)) { diff --git a/source/Handlebars/IO/Formatters/DefaultFormatterProvider.cs b/source/Handlebars/IO/Formatters/DefaultFormatterProvider.cs index 643e2e7f..81c1486a 100644 --- a/source/Handlebars/IO/Formatters/DefaultFormatterProvider.cs +++ b/source/Handlebars/IO/Formatters/DefaultFormatterProvider.cs @@ -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)) { diff --git a/source/Handlebars/IO/Formatters/FormatterProvider.cs b/source/Handlebars/IO/Formatters/FormatterProvider.cs index dd82e747..d70ec838 100644 --- a/source/Handlebars/IO/Formatters/FormatterProvider.cs +++ b/source/Handlebars/IO/Formatters/FormatterProvider.cs @@ -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; diff --git a/source/Handlebars/IO/Formatters/IFormatterProvider.cs b/source/Handlebars/IO/Formatters/IFormatterProvider.cs index bfa016f7..7a0330fe 100644 --- a/source/Handlebars/IO/Formatters/IFormatterProvider.cs +++ b/source/Handlebars/IO/Formatters/IFormatterProvider.cs @@ -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); } } \ No newline at end of file diff --git a/source/Handlebars/IO/Formatters/ReadOnlyCollectionFormatterProvider.cs b/source/Handlebars/IO/Formatters/ReadOnlyCollectionFormatterProvider.cs index 0018d600..6582e5a2 100644 --- a/source/Handlebars/IO/Formatters/ReadOnlyCollectionFormatterProvider.cs +++ b/source/Handlebars/IO/Formatters/ReadOnlyCollectionFormatterProvider.cs @@ -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)) { diff --git a/source/Handlebars/IO/Formatters/UndefinedFormatter.cs b/source/Handlebars/IO/Formatters/UndefinedFormatter.cs index 9d8f7234..be541eed 100644 --- a/source/Handlebars/IO/Formatters/UndefinedFormatter.cs +++ b/source/Handlebars/IO/Formatters/UndefinedFormatter.cs @@ -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)) { diff --git a/source/Handlebars/LayoutViewModel.cs b/source/Handlebars/LayoutViewModel.cs index 4b118ead..812eb119 100644 --- a/source/Handlebars/LayoutViewModel.cs +++ b/source/Handlebars/LayoutViewModel.cs @@ -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) { diff --git a/source/Handlebars/ObjectDescriptors/DictionaryObjectDescriptor.cs b/source/Handlebars/ObjectDescriptors/DictionaryObjectDescriptor.cs index 21d49acf..eb824958 100644 --- a/source/Handlebars/ObjectDescriptors/DictionaryObjectDescriptor.cs +++ b/source/Handlebars/ObjectDescriptors/DictionaryObjectDescriptor.cs @@ -19,7 +19,7 @@ public sealed class DictionaryObjectDescriptor : IObjectDescriptorProvider private static readonly Func 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)) { diff --git a/source/Handlebars/ObjectDescriptors/DynamicObjectDescriptor.cs b/source/Handlebars/ObjectDescriptors/DynamicObjectDescriptor.cs index 0c93ce7e..9ae704f5 100644 --- a/source/Handlebars/ObjectDescriptors/DynamicObjectDescriptor.cs +++ b/source/Handlebars/ObjectDescriptors/DynamicObjectDescriptor.cs @@ -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)) { diff --git a/source/Handlebars/ObjectDescriptors/EnumerableObjectDescriptor.cs b/source/Handlebars/ObjectDescriptors/EnumerableObjectDescriptor.cs index f8829025..14898cfa 100644 --- a/source/Handlebars/ObjectDescriptors/EnumerableObjectDescriptor.cs +++ b/source/Handlebars/ObjectDescriptors/EnumerableObjectDescriptor.cs @@ -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))) { @@ -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) { @@ -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)) { @@ -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)) { diff --git a/source/Handlebars/ObjectDescriptors/GenericDictionaryObjectDescriptorProvider.cs b/source/Handlebars/ObjectDescriptors/GenericDictionaryObjectDescriptorProvider.cs index 5fefe608..b68dc4e7 100644 --- a/source/Handlebars/ObjectDescriptors/GenericDictionaryObjectDescriptorProvider.cs +++ b/source/Handlebars/ObjectDescriptors/GenericDictionaryObjectDescriptorProvider.cs @@ -21,7 +21,7 @@ public sealed class GenericDictionaryObjectDescriptorProvider : IObjectDescripto private readonly LookupSlim, ReferenceEqualityComparer> _typeCache = new LookupSlim, ReferenceEqualityComparer>(new ReferenceEqualityComparer()); - 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) diff --git a/source/Handlebars/ObjectDescriptors/IObjectDescriptorProvider.cs b/source/Handlebars/ObjectDescriptors/IObjectDescriptorProvider.cs index 763e0f53..330859ae 100644 --- a/source/Handlebars/ObjectDescriptors/IObjectDescriptorProvider.cs +++ b/source/Handlebars/ObjectDescriptors/IObjectDescriptorProvider.cs @@ -13,6 +13,6 @@ public interface IObjectDescriptorProvider /// /// /// - bool TryGetDescriptor(Type type, [MaybeNullWhen(false)] out ObjectDescriptor value); + bool TryGetDescriptor(Type type, [NotNullWhen(true)] out ObjectDescriptor? value); } } \ No newline at end of file diff --git a/source/Handlebars/ObjectDescriptors/ObjectAccessor.cs b/source/Handlebars/ObjectDescriptors/ObjectAccessor.cs index 72b69abc..76b66ec0 100644 --- a/source/Handlebars/ObjectDescriptors/ObjectAccessor.cs +++ b/source/Handlebars/ObjectDescriptors/ObjectAccessor.cs @@ -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; } } diff --git a/source/Handlebars/ObjectDescriptors/ObjectDescriptor.cs b/source/Handlebars/ObjectDescriptors/ObjectDescriptor.cs index bf91ae56..c0b4730c 100644 --- a/source/Handlebars/ObjectDescriptors/ObjectDescriptor.cs +++ b/source/Handlebars/ObjectDescriptors/ObjectDescriptor.cs @@ -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); } diff --git a/source/Handlebars/ObjectDescriptors/ObjectDescriptorFactory.cs b/source/Handlebars/ObjectDescriptors/ObjectDescriptorFactory.cs index 9ccd6404..134d2196 100644 --- a/source/Handlebars/ObjectDescriptors/ObjectDescriptorFactory.cs +++ b/source/Handlebars/ObjectDescriptors/ObjectDescriptorFactory.cs @@ -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); diff --git a/source/Handlebars/ObjectDescriptors/ObjectDescriptorProvider.cs b/source/Handlebars/ObjectDescriptors/ObjectDescriptorProvider.cs index 4afa9cea..61bec5c9 100644 --- a/source/Handlebars/ObjectDescriptors/ObjectDescriptorProvider.cs +++ b/source/Handlebars/ObjectDescriptors/ObjectDescriptorProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using HandlebarsDotNet.Collections; @@ -21,7 +22,7 @@ public ObjectDescriptorProvider(IReadOnlyList 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, diff --git a/source/Handlebars/ObjectDescriptors/ReadOnlyGenericDictionaryObjectDescriptorProvider.cs b/source/Handlebars/ObjectDescriptors/ReadOnlyGenericDictionaryObjectDescriptorProvider.cs index d79d76be..7f5a1a9b 100644 --- a/source/Handlebars/ObjectDescriptors/ReadOnlyGenericDictionaryObjectDescriptorProvider.cs +++ b/source/Handlebars/ObjectDescriptors/ReadOnlyGenericDictionaryObjectDescriptorProvider.cs @@ -21,7 +21,7 @@ public sealed class ReadOnlyGenericDictionaryObjectDescriptorProvider : IObjectD private readonly LookupSlim, ReferenceEqualityComparer> _typeCache = new LookupSlim, ReferenceEqualityComparer>(new ReferenceEqualityComparer()); - 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) diff --git a/source/Handlebars/ObjectDescriptors/ReadOnlyStringDictionaryObjectDescriptorProvider.cs b/source/Handlebars/ObjectDescriptors/ReadOnlyStringDictionaryObjectDescriptorProvider.cs index c5444497..010c1d5b 100644 --- a/source/Handlebars/ObjectDescriptors/ReadOnlyStringDictionaryObjectDescriptorProvider.cs +++ b/source/Handlebars/ObjectDescriptors/ReadOnlyStringDictionaryObjectDescriptorProvider.cs @@ -21,7 +21,7 @@ public sealed class ReadOnlyStringDictionaryObjectDescriptorProvider : IObjectDe private readonly LookupSlim, ReferenceEqualityComparer> _typeCache = new LookupSlim, ReferenceEqualityComparer>(new ReferenceEqualityComparer()); - 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) diff --git a/source/Handlebars/ObjectDescriptors/StringDictionaryObjectDescriptorProvider.cs b/source/Handlebars/ObjectDescriptors/StringDictionaryObjectDescriptorProvider.cs index cd1163b9..3ef492e0 100644 --- a/source/Handlebars/ObjectDescriptors/StringDictionaryObjectDescriptorProvider.cs +++ b/source/Handlebars/ObjectDescriptors/StringDictionaryObjectDescriptorProvider.cs @@ -21,7 +21,7 @@ public sealed class StringDictionaryObjectDescriptorProvider : IObjectDescriptor private readonly LookupSlim, ReferenceEqualityComparer> _typeCache = new LookupSlim, ReferenceEqualityComparer>(new ReferenceEqualityComparer()); - 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)