当前位置: 首页>>代码示例>>C#>>正文


C# NamespaceOrTypeSymbol.GetMembers方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.NamespaceOrTypeSymbol.GetMembers方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceOrTypeSymbol.GetMembers方法的具体用法?C# NamespaceOrTypeSymbol.GetMembers怎么用?C# NamespaceOrTypeSymbol.GetMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.CSharp.Symbols.NamespaceOrTypeSymbol的用法示例。


在下文中一共展示了NamespaceOrTypeSymbol.GetMembers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDeclaredMember

        /// <summary>
        /// Finds the member in the containing symbol which is inside the given declaration span.
        /// </summary>
        private Symbol GetDeclaredMember(NamespaceOrTypeSymbol container, TextSpan declarationSpan, string name = null)
        {
            if ((object)container == null)
            {
                return null;
            }

            // look for any member with same declaration location
            var collection = name != null ? container.GetMembers(name) : container.GetMembersUnordered();

            Symbol zeroWidthMatch = null;
            foreach (var symbol in collection)
            {
                var namedType = symbol as ImplicitNamedTypeSymbol;
                if ((object)namedType != null && namedType.IsImplicitClass)
                {
                    // look inside wrapper around illegally placed members in namespaces
                    var result = GetDeclaredMember(namedType, declarationSpan, name);
                    if ((object)result != null)
                    {
                        return result;
                    }
                }

                foreach (var loc in symbol.Locations)
                {
                    if (loc.IsInSource && loc.SourceTree == this.SyntaxTree && declarationSpan.Contains(loc.SourceSpan))
                    {
                        if (loc.SourceSpan.IsEmpty && loc.SourceSpan.End == declarationSpan.Start)
                        {
                            // exclude decls created via syntax recovery
                            zeroWidthMatch = symbol;
                        }
                        else
                        {
                            return symbol;
                        }
                    }
                }

                // Handle the case of the implementation of a partial method.
                var partial = symbol.Kind == SymbolKind.Method
                    ? ((MethodSymbol)symbol).PartialImplementationPart
                    : null;
                if ((object)partial != null)
                {
                    var loc = partial.Locations[0];
                    if (loc.IsInSource && loc.SourceTree == this.SyntaxTree && declarationSpan.Contains(loc.SourceSpan))
                    {
                        return partial;
                    }
                }
            }

            // If we didn't find anything better than the symbol that matched because of syntax error recovery, then return that.
            // Otherwise, if there's a name, try again without a name.
            // Otherwise, give up.
            return zeroWidthMatch ??
                (name != null ? GetDeclaredMember(container, declarationSpan) : null);
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:63,代码来源:SyntaxTreeSemanticModel.cs

示例2: GetSourceMemberSymbols

        private static void GetSourceMemberSymbols(NamespaceOrTypeSymbol symbol, List<ISymbol> list, LocalSymbolDumper localDumper)
        {
            foreach (var memberSymbol in symbol.GetMembers())
            {
                list.Add(memberSymbol);

                switch (memberSymbol.Kind)
                {
                    case SymbolKind.NamedType:
                    case SymbolKind.Namespace:
                        GetSourceMemberSymbols((NamespaceOrTypeSymbol)memberSymbol, list, localDumper);
                        break;
                    case SymbolKind.Method:
                        var method = (MethodSymbol)memberSymbol;
                        foreach (var parameter in method.Parameters)
                        {
                            list.Add(parameter);
                        }

                        if (localDumper != null)
                        {
                            localDumper.GetLocalSymbols(method, list);
                        }

                        break;
                    case SymbolKind.Field:
                        if (localDumper != null)
                        {
                            localDumper.GetLocalSymbols((FieldSymbol)memberSymbol, list);
                        }

                        break;
                }
            }
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:35,代码来源:SymbolKeyTestBase.cs

示例3: AppendMembers

        private void AppendMembers(StringBuilder result, NamespaceOrTypeSymbol container, string indent)
        {
            string memberIndent;
            if (container is NamedTypeSymbol)
            {
                memberIndent = indent + "  ";

                result.Append(indent);
                result.AppendLine("{");

                AppendCustomAttributes(result, container, indent, inBlock: true);

                if (container.GetAttributes().Length > 0)
                {
                    result.AppendLine();
                }
            }
            else
            {
                memberIndent = indent;
            }


            foreach (var member in container.GetMembers().OrderBy(m => m.Name, System.StringComparer.InvariantCulture))
            {
                switch (member.Kind)
                {
                    case SymbolKind.NamedType:
                        var namedType = (PENamedTypeSymbol)member;
                        result.Append(memberIndent);
                        result.Append(".class ");
                        MetadataSignatureHelper.AppendTypeAttributes(result, namedType.Flags);
                        result.Append(" ");
                        result.Append(member);

                        if (namedType.BaseType != null)
                        {
                            result.AppendLine();
                            result.Append(memberIndent);
                            result.Append("       extends ");
                            result.Append(namedType.BaseType);
                        }

                        if (namedType.Interfaces.Length > 0)
                        {
                            result.AppendLine();
                            result.Append(memberIndent);
                            result.Append("       implements ");
                            result.Append(string.Join(", ", namedType.Interfaces));
                        }

                        result.AppendLine();

                        AppendMembers(result, namedType, memberIndent);
                        break;

                    case SymbolKind.Namespace:
                        var ns = member as PENamespaceSymbol;
                        if ((object)ns != null)
                        {
                            AppendMembers(result, ns, indent);
                        }
                        break;

                    case SymbolKind.Method:
                        var method = member as PEMethodSymbol;
                        if ((object)method != null && method.AssociatedSymbol == null)
                        {
                            result.Append(memberIndent);
                            result.Append(".method ");
                            AppendMethod(result, method, memberIndent);

                            AppendCustomAttributes(result, member, memberIndent, inBlock: false);
                        }
                        break;

                    case SymbolKind.Field:
                        var field = (PEFieldSymbol)member;
                        result.Append(memberIndent);
                        result.Append(".field ");

                        MetadataSignatureHelper.AppendFieldAttributes(result, field.Flags);
                        result.Append(" ");

                        result.Append(field.Type);
                        result.Append(" ");
                        result.Append(member.Name);
                        result.AppendLine();

                        AppendCustomAttributes(result, member, memberIndent, inBlock: false);
                        break;

                    case SymbolKind.Property:
                        var property = (PEPropertySymbol)member;
                        string propertyName;

                        result.Append(memberIndent);
                        result.Append(".property ");

                        PropertyAttributes propertyAttrs;
//.........这里部分代码省略.........
开发者ID:GloryChou,项目名称:roslyn,代码行数:101,代码来源:WinMdDumpTest.cs

示例4: CheckMemberDistinctness

        private void CheckMemberDistinctness(NamespaceOrTypeSymbol symbol)
        {
            System.Diagnostics.Debug.Assert(IsAccessibleOutsideAssembly(symbol));
            System.Diagnostics.Debug.Assert(IsTrue(GetDeclaredOrInheritedCompliance(symbol)));

            MultiDictionary<string, Symbol> seenByName = new MultiDictionary<string, Symbol>(CaseInsensitiveComparison.Comparer);

            // For types, we also need to consider collisions with inherited members.
            if (symbol.Kind != SymbolKind.Namespace)
            {
                NamedTypeSymbol type = (NamedTypeSymbol)symbol;

                // NOTE: As in dev11 we're using Interfaces, rather than AllInterfaces.
                // This seems like a bug, but it's easier to reproduce it than to deal
                // with all the potential breaks.
                // NOTE: It's not clear why dev11 is looking in interfaces at all. Maybe
                // it was only supposed to happen for interface types?
                foreach (NamedTypeSymbol @interface in type.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics) // NOTE: would be handrolled in a standalone component.
                {
                    if (!IsAccessibleOutsideAssembly(@interface)) continue;

                    foreach (Symbol member in @interface.GetMembersUnordered())
                    {
                        // NOTE: As in dev11 we filter out overriding methods and properties (but not events).
                        // NOTE: As in dev11, we ignore the CLS compliance of the interface and its members.
                        if (IsAccessibleIfContainerIsAccessible(member) &&
                            (!member.IsOverride || !(member.Kind == SymbolKind.Method || member.Kind == SymbolKind.Property)))
                        {
                            seenByName.Add(member.Name, member);
                        }
                    }
                }

                NamedTypeSymbol baseType = type.BaseTypeNoUseSiteDiagnostics;
                while ((object)baseType != null)
                {
                    foreach (Symbol member in baseType.GetMembersUnordered())
                    {
                        // NOTE: As in dev11 we filter out overriding methods and properties (but not events).
                        // NOTE: Unlike for interface members, we check CLS compliance of base type members.
                        if (IsAccessibleOutsideAssembly(member) &&
                            IsTrue(GetDeclaredOrInheritedCompliance(member)) &&
                            (!member.IsOverride || !(member.Kind == SymbolKind.Method || member.Kind == SymbolKind.Property)))
                        {
                            seenByName.Add(member.Name, member);
                        }
                    }

                    baseType = baseType.BaseTypeNoUseSiteDiagnostics;
                }
            }

            // NOTE: visit the members in order so that the same one is always reported as a conflict.
            foreach (Symbol member in symbol.GetMembers())
            {
                // Filter out uninteresting members:
                if (DoNotVisit(member) ||
                    !IsAccessibleIfContainerIsAccessible(member) || // We already know that the container is accessible.
                    !IsTrue(GetDeclaredOrInheritedCompliance(member)) ||
                    member.IsOverride)
                {
                    continue;
                }

                var name = member.Name;
                var sameNameSymbols = seenByName[name];
                if (sameNameSymbols.Count > 0)
                {
                    CheckSymbolDistinctness(member, name, sameNameSymbols);
                }

                seenByName.Add(name, member);
            }
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:74,代码来源:ClsComplianceChecker.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Symbols.NamespaceOrTypeSymbol.GetMembers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。