public bool TryProvideParser(IParserDiscovery currentNamespace, out TypeParser <T> parser)
 => Provider.TryProvideParser <T>(currentNamespace, out parser);
 public abstract bool TryProvideParser(IParserDiscovery discovery, out TypeParser parser);
        private bool TryGetGenericParser <T>(Type type, IParserDiscovery parserNamespace, out TypeParser <T> parser)
        {
            parser = null;
            var genericType = type.GetGenericTypeDefinition();

            if (!Parsers.TryGetValue(genericType, out var provider))
            {
                return(false);
            }
            // uh-oh, AOT unfriendly!
            var gProvider = Activator.CreateInstance(((Type)provider).MakeGenericType(type.GetGenericArguments())) as GenericParserProvider;

            Debug.Assert(gProvider != null);
            if (!gProvider.TryProvideParser(parserNamespace, out parser))
            {
                return(false);
            }
            // Cache the parser for this type
            Parsers.TryAdd(type, gProvider.CreateProvider <T>());
            return(true);
        }
        private bool TryGetNonGenericParser <T>(Type type, IParserDiscovery parserNamespace, out TypeParser <T> parser)
        {
            parser = null;
            if (!Parsers.TryGetValue(type, out var regParser))
            {
                return(false);
            }

            switch (regParser)
            {
            case TypeParser <T> sealedParser:
                parser = sealedParser;
                return(true);

            case IParserProvider <T> parserProvider:
                return(parserProvider.TryProvideParser(parserNamespace, out parser));
            }

            Debug.Fail($"{regParser} should be registered for {type.Name}");
            return(false);
        }
 public virtual void ReplaceSealedParser <T>(TypeParser <T> parser) => Parsers[typeof(T)] = parser;
 public virtual bool AddSealedParser <T>(TypeParser <T> parser) => Parsers.TryAdd(typeof(T), parser);
Exemple #7
0
 public static bool TryGetParser <T>(this BinaryPacker packer, out TypeParser <T> parser) => packer.DefaultNamespace.TryGetParser <T>(out parser);