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


C# CSharpResolver.GetAllExtensionMethods方法代码示例

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


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

示例1: CreateCompletionData

        IEnumerable<ICompletionData> CreateCompletionData(TextLocation location, ResolveResult resolveResult, AstNode resolvedNode, CSharpResolver state)
        {
            if (resolveResult == null /*|| resolveResult.IsError*/)
                return null;

            if (resolveResult is NamespaceResolveResult) {
                var nr = (NamespaceResolveResult)resolveResult;
                var namespaceContents = new CompletionDataWrapper (this);

                foreach (var cl in nr.Namespace.Types) {
                    namespaceContents.AddType (cl, cl.Name);
                }

                foreach (var ns in nr.Namespace.ChildNamespaces) {
                    namespaceContents.AddNamespace (ns.Name);
                }
                return namespaceContents.Result;
            }

            IType type = resolveResult.Type;
            var typeDef = resolveResult.Type.GetDefinition ();
            var lookup = new MemberLookup (ctx.CurrentTypeDefinition, Compilation.MainAssembly);
            var result = new CompletionDataWrapper (this);
            bool isProtectedAllowed = false;
            bool includeStaticMembers = false;

            if (resolveResult is LocalResolveResult) {
                isProtectedAllowed = currentType != null && typeDef != null ? typeDef.GetAllBaseTypeDefinitions ().Any (bt => bt.Equals (currentType)) : false;
                if (resolvedNode is IdentifierExpression) {
                    var mrr = (LocalResolveResult)resolveResult;
                    includeStaticMembers = mrr.Variable.Name == mrr.Type.Name;
                }
            } else {
                isProtectedAllowed = currentType != null && typeDef != null ? currentType.Resolve (ctx).GetDefinition ().GetAllBaseTypeDefinitions ().Any (bt => bt.Equals (typeDef)) : false;
            }
            if (resolveResult is TypeResolveResult && type.Kind == TypeKind.Enum) {
                foreach (var field in type.GetFields ()) {
                    result.AddMember (field);
                }
                foreach (var m in type.GetMethods ()) {
                    if (m.Name == "TryParse")
                        result.AddMember (m);
                }
                return result.Result;
            }

            if (resolveResult is MemberResolveResult && resolvedNode is IdentifierExpression) {
                var mrr = (MemberResolveResult)resolveResult;
                includeStaticMembers = mrr.Member.Name == mrr.Type.Name;
            }

            //			Console.WriteLine ("type:" + type +"/"+type.GetType ());
            //			Console.WriteLine ("IS PROT ALLOWED:" + isProtectedAllowed);
            //			Console.WriteLine (resolveResult);
            //			Console.WriteLine (currentMember !=  null ? currentMember.IsStatic : "currentMember == null");

            if (resolvedNode.Annotation<ObjectCreateExpression> () == null) { //tags the created expression as part of an object create expression.
                foreach (var member in type.GetMembers ()) {
                    if (!lookup.IsAccessible (member, isProtectedAllowed)) {
                        //					Console.WriteLine ("skip access: " + member.FullName);
                        continue;
                    }
                    if (resolvedNode is BaseReferenceExpression && member.IsAbstract)
                        continue;

                    if (!includeStaticMembers && member.IsStatic && !(resolveResult is TypeResolveResult)) {
                        //					Console.WriteLine ("skip static member: " + member.FullName);
                        continue;
                    }
                    if (!member.IsStatic && (resolveResult is TypeResolveResult)) {
                        //					Console.WriteLine ("skip non static member: " + member.FullName);
                        continue;
                    }
                    //				Console.WriteLine ("add : "+ member.FullName + " --- " + member.IsStatic);
                    result.AddMember (member);
                }
            }

            if (resolveResult is TypeResolveResult || includeStaticMembers) {
                foreach (var nested in type.GetNestedTypes ()) {
                    result.AddType (nested, nested.Name);
                }

            } else {
                foreach (var meths in state.GetAllExtensionMethods (type)) {
                    foreach (var m in meths) {
                        result.AddMember (m);
                    }
                }
            }

            //			IEnumerable<object> objects = resolveResult.CreateResolveResult (dom, resolver != null ? resolver.CallingMember : null);
            //			CompletionDataCollector col = new CompletionDataCollector (this, dom, result, Document.CompilationUnit, resolver != null ? resolver.CallingType : null, location);
            //			col.HideExtensionParameter = !resolveResult.StaticResolve;
            //			col.NamePrefix = expressionResult.Expression;
            //			bool showOnlyTypes = expressionResult.Contexts.Any (ctx => ctx == ExpressionContext.InheritableType || ctx == ExpressionContext.Constraints);
            //			if (objects != null) {
            //				foreach (object obj in objects) {
            //					if (expressionResult.ExpressionContext != null && expressionResult.ExpressionContext.FilterEntry (obj))
            //						continue;
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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