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


C# TypeSymbol.GetMembers方法代码示例

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


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

示例1: MightContainReferences

 /// <summary>
 /// Might the given type be, or contain, managed references?  This is used to determine which
 /// fields allocated to temporaries should be cleared when the underlying variable goes out of scope, so
 /// that they do not cause unnecessary object retention.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 private bool MightContainReferences(TypeSymbol type)
 {
     if (type.IsReferenceType || type.TypeKind == TypeKind.TypeParameter) return true; // type parameter or reference type
     if (type.TypeKind != TypeKind.Struct) return false; // enums, etc
     if (type.SpecialType == SpecialType.System_TypedReference) return true;
     if (type.SpecialType != SpecialType.None) return false; // int, etc
     CSharpCompilation Compilation = this.CompilationState.ModuleBuilderOpt.Compilation;
     if (type.DeclaringCompilation != Compilation) return true; // perhaps from ref assembly
     if (emptyStructTypeCache.IsEmptyStructType(type)) return false;
     foreach (var f in type.GetMembers())
     {
         if (f.Kind == SymbolKind.Field && !f.IsStatic && MightContainReferences(((FieldSymbol)f).Type)) return true;
     }
     return false;
 }
开发者ID:nagyist,项目名称:roslyn,代码行数:22,代码来源:StateMachineMethodToClassRewriter.cs

示例2: DelegateConstructor

        private MethodSymbol DelegateConstructor(CSharpSyntaxNode syntax, TypeSymbol delegateType)
        {
            foreach (var possibleCtor in delegateType.GetMembers(WellKnownMemberNames.InstanceConstructorName))
            {
                var m = possibleCtor as MethodSymbol;
                if ((object)m == null) continue;
                var parameters = m.Parameters;
                if (parameters.Length != 2) continue;
                if (parameters[0].Type.SpecialType != SpecialType.System_Object) continue;
                var p1t = parameters[1].Type.SpecialType;
                if (p1t == SpecialType.System_IntPtr || p1t == SpecialType.System_UIntPtr)
                {
                    return m;
                }
            }

            // The delegate '{0}' does not have a valid constructor
            diagnostics.Add(ErrorCode.ERR_BadDelegateConstructor, syntax.Location, delegateType);
            return null;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:20,代码来源:EmitConversion.cs

示例3: FindMethod

        private MethodSymbol FindMethod(TypeSymbol receiver, string name, ImmutableArray<TypeSymbol> typeArgs, ImmutableArray<BoundExpression> args)
        {
            MethodSymbol found = null;
            bool ambiguous = false;
            ImmutableArray<Symbol> candidates = receiver.GetMembers(name);
            foreach (var candidate in candidates)
            {
                var method = candidate as MethodSymbol;
                if ((object)method == null || method.Arity != typeArgs.Length || method.ParameterCount != args.Length) continue;
                if (method.Arity != 0) method = method.Construct(typeArgs);
                var parameters = method.Parameters;
                bool exact = true;

                for (int i = 0; i < args.Length; i++)
                {
                    HashSet<DiagnosticInfo> useSiteDiagnostics = null;
                    if (parameters[i].RefKind != RefKind.None ||
                        !((object)args[i].Type == null && parameters[i].Type.IsReferenceType ||
                        Compilation.Conversions.ClassifyConversion(args[i].Type, parameters[i].Type, ref useSiteDiagnostics).IsImplicit))
                    {
                        Debug.Assert(useSiteDiagnostics.IsNullOrEmpty());
                        goto nextCandidate;
                    }

                    Debug.Assert(useSiteDiagnostics.IsNullOrEmpty());
                    exact = exact && args[i].Type == parameters[i].Type;
                }

                if (exact) return method;
                if ((object)found != null)
                {
                    ambiguous = true;
                }
                found = method;

                nextCandidate: ;
            }

            if (ambiguous) ReportLibraryProblem(ErrorCode.ERR_LibraryMethodNotUnique, receiver, name, typeArgs, args);
            else if ((object)found == null) ReportLibraryProblem(ErrorCode.ERR_LibraryMethodNotFound, receiver, name, typeArgs, args);
            return found;
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:42,代码来源:SyntheticBoundNodeFactory.cs

示例4: GetRequiredMethod

 private static MethodSymbol GetRequiredMethod(TypeSymbol type, string methodName, DiagnosticBag diagnostics)
 {
     var method = type.GetMembers(methodName).SingleOrDefault() as MethodSymbol;
     if ((object)method == null)
     {
         diagnostics.Add(ErrorCode.ERR_MissingPredefinedMember, NoLocation.Singleton, type, methodName);
     }
     return method;
 }
开发者ID:RoryVL,项目名称:roslyn,代码行数:9,代码来源:SynthesizedEntryPointSymbol.cs

示例5: FindMethodBySignature

        private static MethodSymbol FindMethodBySignature(TypeSymbol targetTypeSymbol, string targetMemberName, SignatureHeader targetMemberSignatureHeader, int targetMemberTypeParamCount, ParamInfo<TypeSymbol>[] targetParamInfo)
        {
            foreach (Symbol member in targetTypeSymbol.GetMembers(targetMemberName))
            {
                var method = member as MethodSymbol;
                if ((object)method != null &&
                    ((byte)method.CallingConvention == targetMemberSignatureHeader.RawValue) &&
                    (targetMemberTypeParamCount == method.Arity) &&
                    MethodSymbolMatchesParamInfo(method, targetParamInfo))
                {
                    // Behavior in the face of multiple matching signatures is
                    // implementation defined - we'll just pick the first one.
                    return method;
                }
            }

            return null;
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:18,代码来源:MemberRefMetadataDecoder.cs

示例6: FindFieldBySignature

        private static FieldSymbol FindFieldBySignature(TypeSymbol targetTypeSymbol, string targetMemberName, ImmutableArray<ModifierInfo<TypeSymbol>> customModifiers, TypeSymbol type)
        {
            foreach (Symbol member in targetTypeSymbol.GetMembers(targetMemberName))
            {
                var field = member as FieldSymbol;
                if ((object)field != null &&
                    field.Type == type &&
                    CustomModifiersMatch(field.CustomModifiers, customModifiers))
                {
                    // Behavior in the face of multiple matching signatures is
                    // implementation defined - we'll just pick the first one.
                    return field;
                }
            }

            return null;
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:17,代码来源:MemberRefMetadataDecoder.cs

示例7: MemberLookupWithoutInheritance

        // Does a member lookup in a single type, without considering inheritance.
        private LookupResult MemberLookupWithoutInheritance(TypeSymbol type, string name, int arity, bool invoked)
        {
            LookupResult result = new LookupResult();

            IEnumerable<Symbol> members = type.GetMembers(name);
            foreach (Symbol member in members) {
                LookupResult resultOfThisMember;
                // Do we need to exclude override members, or is that done later by overload resolution. It seems like
                // not excluding them here can't lead to problems, because we will always find the overridden method as well.

                SymbolKind memberKind = member.Kind;
                DiagnosticInfo diagInfo;
                if (WrongArity(member, arity, out diagInfo))
                    resultOfThisMember = LookupResult.WrongArity(member, diagInfo);
                else if (invoked && !IsInvocable(member))
                    resultOfThisMember = LookupResult.Bad(member, new CSDiagnosticInfo(ErrorCode.ERR_NonInvocableMemberCalled, member.GetFullName()));
                else if (!IsMemberAccessible(member))
                    resultOfThisMember = LookupResult.Inaccessible(member);
                else
                    resultOfThisMember = LookupResult.Good(member);

                result = MergeLookupsInSameScope(result, resultOfThisMember);
            }

            return result;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:27,代码来源:MemberAccess.cs

示例8: AreEquivalent

        internal static bool AreEquivalent(TypeSymbol a, TypeSymbol b, Compilation comp)
        {
            var aMembers = a.GetMembers().OfType<PropertySymbol>().ToList();
            var bMembers = b.GetMembers().OfType<PropertySymbol>().ToList();

            if (aMembers.Count != bMembers.Count) return false;

            for (var i = 0; i < aMembers.Count; i++)
            {
                var aMember = aMembers[i];
                var bMember = bMembers[i];

                if (aMember.Name != bMember.Name) return false;
                if (aMember.DeclaredAccessibility != bMember.DeclaredAccessibility) return false;

                var aType = aMember.Type;
                var bType = bMember.Type;

                var aName = aType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
                var bName = bType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);

                if (aName == bName) continue;

                var conv = comp.ClassifyConversion(aType, bType);

                if (!conv.IsIdentity) return false;
            }

            return true;
        }
开发者ID:kevin-montrose,项目名称:further-type-inferencing,代码行数:30,代码来源:Visitors.cs


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