예제 #1
0
        private ImmutableArray <Symbol> GetMembersWorker(string name)
        {
            var originalMembers = OriginalDefinition.GetMembers(name);

            if (originalMembers.IsDefaultOrEmpty)
            {
                return(originalMembers);
            }

            var builder = ArrayBuilder <Symbol> .GetInstance(originalMembers.Length);

            foreach (var t in originalMembers)
            {
                builder.Add(t.SymbolAsMember(this));
            }

            var substitutedMembers = builder.ToImmutableAndFree();

            // cache of size 8 seems reasonable here.
            // considering that substituted methods have about 10 reference fields,
            // reusing just one may make the cache profitable.
            var cache = _lazyMembersByNameCache ??
                        (_lazyMembersByNameCache = new ConcurrentCache <string, ImmutableArray <Symbol> >(8));

            cache.TryAdd(name, substitutedMembers);
            return(substitutedMembers);
        }
예제 #2
0
        public sealed override ImmutableArray <Symbol> GetMembers()
        {
            var builder = ArrayBuilder <Symbol> .GetInstance();

            if (_unbound)
            {
                // Preserve order of members.
                foreach (var t in OriginalDefinition.GetMembers())
                {
                    if (t.Kind == SymbolKind.NamedType)
                    {
                        builder.Add(((NamedTypeSymbol)t).AsMember(this));
                    }
                }
            }
            else
            {
                foreach (var t in OriginalDefinition.GetMembers())
                {
                    builder.Add(t.SymbolAsMember(this));
                }
            }

            return(builder.ToImmutableAndFree());
        }