Beispiel #1
0
        public override bool TryAddBinder(LanguageSyntaxNode node, object usage, ref Binder binder)
        {
            var key = new BinderCacheKey(node, usage);

            if (!_binderCache.TryAdd(key, binder))
            {
                if (_binderCache.TryGetValue(key, out Binder oldBinder))
                {
                    binder = oldBinder;
                }
                return(false);
            }
            return(true);
        }
        internal InMethodBinder GetRecordConstructorInMethodBinder(SynthesizedRecordConstructor constructor)
        {
            RecordDeclarationSyntax typeDecl = constructor.GetSyntax();

            var extraInfo = NodeUsage.ConstructorBodyOrInitializer;
            var key       = BinderFactoryVisitor.CreateBinderCacheKey(typeDecl, extraInfo);

            if (!_binderCache.TryGetValue(key, out Binder resultBinder))
            {
                // Ctors cannot be generic
                Debug.Assert(constructor.Arity == 0, "Generic Ctor, What to do?");
                resultBinder = new InMethodBinder(constructor, GetInRecordBodyBinder(typeDecl));

                _binderCache.TryAdd(key, resultBinder);
            }

            return((InMethodBinder)resultBinder);
        }
Beispiel #3
0
        internal string NormalizeDebugDocumentPath(string path, string basePath)
        {
            if (_resolverOpt == null)
            {
                return(path);
            }

            var    key = ValueTuple.Create(path, basePath);
            string normalizedPath;

            if (!_normalizedPathsCache.TryGetValue(key, out normalizedPath))
            {
                normalizedPath = _resolverOpt.NormalizePath(path, basePath) ?? path;
                _normalizedPathsCache.TryAdd(key, normalizedPath);
            }

            return(normalizedPath);
        }
        internal string NormalizeDebugDocumentPath(string path, string basePath)
        {
            var resolver = _compilation.Options.SourceReferenceResolver;

            if (resolver == null)
            {
                return(path);
            }

            var    key = ValueTuple.Create(path, basePath);
            string normalizedPath;

            if (!_normalizedPathsCache.TryGetValue(key, out normalizedPath))
            {
                normalizedPath = resolver.NormalizePath(path, basePath) ?? path;
                _normalizedPathsCache.TryAdd(key, normalizedPath);
            }

            return(normalizedPath);
        }
Beispiel #5
0
 private static void AddToCache(object instance, object param, MethodInfo methodInfo)
 {
     ConcurrentCache<Type, MethodInfo> instanceCache;
     
     if (methodCache.TryGetValue(instance.GetType(), out instanceCache))
     {
         instanceCache.TryAdd(param.GetType(), methodInfo);
     }
     else
     {
         instanceCache = new ConcurrentCache<Type, MethodInfo>();
         instanceCache.TryAdd(param.GetType(), methodInfo);
         methodCache.TryAdd(instance.GetType(), instanceCache);
     }
 }