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


C# SyntaxTokenList.Any方法代码示例

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


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

示例1: AdjustAccessibility

		static void AdjustAccessibility (SyntaxTokenList modifiers, ref Accessibility acc, ref bool isStatic, ref bool result)
		{
			isStatic = modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.StaticKeyword);
			if (modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) &&
				modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword)) {
				acc = Accessibility.ProtectedOrInternal;
				result = true;
				return;
			}

			foreach (var mod in modifiers) {
				if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PublicKeyword) {
					acc = Accessibility.Public;
					result = true;
					return;
				}
				if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword) {
					acc = Accessibility.Private;
					result = true;
					return;
				}
				if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) {
					acc = Accessibility.Protected;
					result = true;
					return;
				}
				if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword) {
					acc = Accessibility.Internal;
					result = true;
					return;
				}
			}
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:33,代码来源:AstStockIcons.cs

示例2: ProcessAttribute

        protected void ProcessAttribute(SyntaxNodeAnalysisContext context, SyntaxTokenList textTokens)
        {
            if (!textTokens.Any())
            {
                return;
            }

            var token = textTokens.First();

            if (token.Span.Length >= 2)
            {
                var text = token.Text;

                if (text[1] == ':')
                {
                    var location = Location.Create(token.SyntaxTree, textTokens.Span);
                    context.ReportDiagnostic(Diagnostic.Create(Rule, location, text.Substring(0, 2)));
                }
            }
        }
开发者ID:maggiemsft,项目名称:roslyn-analyzers,代码行数:20,代码来源:DoNotUseVerbatimCrefsAnalyzer.cs

示例3: WriteRegion

        private const string _set = "";//"set";

        static void WriteRegion(bool get, string body, ITypeSymbol iface, OutputWriter writer, string typeString, string name, SyntaxTokenList modifiers, string parameters, bool isindexer, bool hasGetter)
        {
            //no inline in D
//            if (get)
                writer.Write((get ? (typeString) : (hasGetter ? typeString : "void")) + " ");
//            else
//                writer.Write("void ");

            if (!isindexer)
            {
               
                writer.Write( (get?(_get+name):(_set+(name))) +
                             (get
                                 ? "(" + (iface != null ? (TypeProcessor.ConvertType(iface) + " __ig=null") : "") + ")"
                                 : "(" + typeString + " value " +
                                   (iface != null ? ("," + TypeProcessor.ConvertType(iface) + " __ig=null") : "") + ")") +
                             " ");
            }
            else
            {
                writer.Write((name) +
                            (get
                                ? "(" + parameters + ")"
                                : "(" + typeString + " value, " +
                                  parameters + ")") +
                            "");
            }


            if (modifiers.Any(SyntaxKind.AbstractKeyword) || body == null)
                writer.Write(";\r\n");
            else
            {
                writer.WriteLine();
                writer.OpenBrace();
                writer.WriteLine(body);
                writer.CloseBrace();
                writer.WriteLine();
            }
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:42,代码来源:WriteProperty.cs

示例4: GetFirstLocalOrFieldBreakpointSpan

        internal static void GetFirstLocalOrFieldBreakpointSpan(SyntaxTokenList modifiers, VariableDeclaratorSyntax declaratorSyntax, out SyntaxNode node, out TextSpan? part)
        {
            var declarationSyntax = (VariableDeclarationSyntax)declaratorSyntax.Parent;

            int start = modifiers.Any() ? modifiers[0].SpanStart : declarationSyntax.SpanStart;

            int end;
            if (declarationSyntax.Variables.Count == 1)
            {
                // [|int x = 1;|]
                // [|public static int x = 1;|]
                end = declarationSyntax.Parent.Span.End;
            }
            else
            {
                // [|int x = 1|], y = 2;
                // [|public static int x = 1|], y = 2;
                end = declaratorSyntax.Span.End;
            }

            part = TextSpan.FromBounds(start, end);
            node = declarationSyntax.Parent;
        }
开发者ID:riversky,项目名称:roslyn,代码行数:23,代码来源:LocalRewriter_SequencePoints.cs

示例5: Go

        public static void Go(OutputWriter writer, MemberDeclarationSyntax field, SyntaxTokenList modifiers, string name,
            TypeSyntax type, EqualsValueClauseSyntax initializerOpt = null, bool isThreadStatic =false)
        {
            writer.WriteIndent();

            var typeinfo = TypeProcessor.GetTypeInfo(type);

//            var isPtr = typeinfo.Type != null && (typeinfo.Type.IsValueType || typeinfo.Type.TypeKind==TypeKind.TypeParameter) ? "" : "";

            var typeStringNoPtr = TypeProcessor.ConvertType(type);

            var typeString = typeStringNoPtr + " ";

            var isConst = IsConst(modifiers, initializerOpt, type);

            var isStatic = isConst;
            //Handle Auto Properties

            // if (modifiers.Any(SyntaxKind.PrivateKeyword)) // Reflection cannot work with this, cant get address or set value
            //   writer.Write("private ");

            if (modifiers.Any(SyntaxKind.PublicKeyword) || modifiers.Any(SyntaxKind.InternalKeyword) ||
                modifiers.Any(SyntaxKind.ProtectedKeyword) || modifiers.Any(SyntaxKind.AbstractKeyword))
                writer.Write("public ");


            if (isThreadStatic)
            {
                writer.Write("static ");
            }

            if (modifiers.Any(SyntaxKind.StaticKeyword) || modifiers.Any(SyntaxKind.ConstKeyword))
            {
                isStatic = true;
                writer.Write("__gshared ");
            }

          

            if (isConst && typeinfo.Type.IsPrimitive())
            {
              
                writer.Write("const "); //const has interesting semantics in Dlang 
            }

            var @event = field is EventFieldDeclarationSyntax;
            ITypeSymbol iface;
            ISymbol[] proxies;

            bool isInterface =false;
           // var ename = MemberUtilities.GetMethodName(field, ref isInterface, out iface, out proxies);
            if (@event)
            {
                typeString = ("__Event!(" + typeString + ")");

                if (field.Parent is InterfaceDeclarationSyntax)
                {
                    
                    //writer.Write(typeString);
                    writer.WriteLine(typeString + " " + name + "(" + TypeProcessor.ConvertType(field.Parent) +" __ij)" + "@property;");
                    return;
                }
            }

            writer.Write(typeString);


//                if (isStatic)
//                    writer.Write(typeString);

            writer.Write(name);
            if (isStatic)
            {
//                var fieldInfo = TypeProcessor.GetDeclaredSymbol(field.Parent);
//                if (fieldInfo != null)
//                    writer.Write((!string.IsNullOrEmpty(fieldInfo.ContainingNamespace.FullName())?(fieldInfo.ContainingNamespace.FullName()+".") :"") + fieldInfo.Name+"."+name);
//				writer.Write(name);
            }

            if (!isStatic || isConst)
            {
                if (initializerOpt != null)
                {
					writer.Write(String.Format(" = cast({0})", typeString));

                    if (CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.CollectionInitializerExpression ||
                        CSharpExtensions.CSharpKind(initializerOpt.Value) == SyntaxKind.ArrayInitializerExpression)
                    {
//                        writer.Write("gc::gc_ptr< " + typeStringNoPtr + " >(");
                        writer.Write(" new " + typeString + " (");
                        var intializer = initializerOpt.Value as InitializerExpressionSyntax;
                        intializer.WriteArrayInitializer(writer, type);

                        writer.Write(")");
                    }

                    else
                        Core.Write(writer, initializerOpt.Value);
                }

//.........这里部分代码省略.........
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:101,代码来源:WriteField.cs

示例6: IsConst

        public static bool IsConst(SyntaxTokenList modifiers, EqualsValueClauseSyntax initializerOpt, TypeSyntax type)
        {
            var t = TypeProcessor.ConvertType(type);

            return modifiers.Any(SyntaxKind.ConstKeyword);
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:6,代码来源:WriteField.cs

示例7: GetModifierFlags

        private static ModifierFlags GetModifierFlags(SyntaxTokenList syntax)
        {
            ModifierFlags flags = 0;
            if (syntax.Any(SyntaxKind.ConstKeyword))
            {
                flags |= ModifierFlags.Const;
            }
            else
            {
                if (syntax.Any(SyntaxKind.StaticKeyword))
                {
                    flags |= ModifierFlags.Static;
                }

                if (syntax.Any(SyntaxKind.ReadOnlyKeyword))
                {
                    flags |= ModifierFlags.Readonly;
                }
            }

            return flags == 0 ? ModifierFlags.None : flags;
        }
开发者ID:robinsedlaczek,项目名称:StyleCopAnalyzers,代码行数:22,代码来源:MemberOrderHelper.cs

示例8: ClassifyModifiedMemberInsert

            private bool ClassifyModifiedMemberInsert(SyntaxTokenList modifiers)
            {
                if (modifiers.Any(SyntaxKind.ExternKeyword))
                {
                    ReportError(RudeEditKind.InsertExtern);
                    return false;
                }

                if (modifiers.Any(SyntaxKind.VirtualKeyword) || modifiers.Any(SyntaxKind.AbstractKeyword) || modifiers.Any(SyntaxKind.OverrideKeyword))
                {
                    ReportError(RudeEditKind.InsertVirtual);
                    return false;
                }

                return true;
            }
开发者ID:GeertVL,项目名称:roslyn,代码行数:16,代码来源:CSharpEditAndContinueAnalyzer.cs

示例9: CheckModifiers

 bool CheckModifiers(SyntaxTokenList modifiers)
 {
     var isUnsafe = modifiers.Any(m => m.IsKind(SyntaxKind.UnsafeKeyword));
     if (unsafeStateStack.Count > 0)
     {
         var curState = unsafeStateStack.Peek();
         unsafeStateStack.Push(new UnsafeState(curState.InUnsafeContext));
     }
     else {
         unsafeStateStack.Push(new UnsafeState(isUnsafe));
     }
     return isUnsafe;
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:13,代码来源:RedundantUnsafeContextAnalyzer.cs

示例10: IsConst

		static bool IsConst (SyntaxTokenList modifiers)
		{
			return modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ConstKeyword);
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:4,代码来源:AstStockIcons.cs

示例11: WriteAutoFieldName

        private static string WriteAutoFieldName(OutputWriter writer, string name, SyntaxTokenList modifiers, bool isInterface,
            bool hasGetter, bool getterHasBody, bool hasSetter, bool setterHasBody, string typeString, out string isOverride, bool isIndexer=false)
        {
//Auto Property
            var fieldName = "__prop_" + name;

            isOverride = (modifiers.Any(SyntaxKind.NewKeyword) ||
                          modifiers.Any(SyntaxKind.OverrideKeyword)) && !isInterface
                ? " override "
                : "";

            var isStatic = modifiers.Any(SyntaxKind.StaticKeyword);

            if (!isInterface &&!isIndexer) // Auto property
            {
                if ((hasGetter && !getterHasBody) &&
                    (hasSetter && !setterHasBody) && (!modifiers.Any(SyntaxKind.AbstractKeyword)))
                {
                   
                    writer.WriteLine("private " + (isStatic?"static " :"") + typeString + " " + fieldName + ";");

                }
            }
            return fieldName;
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:25,代码来源:WriteProperty.cs

示例12: WriteGetter

        private static void WriteGetter(OutputWriter writer, bool isProxy, bool hasGetter, string acccessmodifiers, string typeString, string name, ITypeSymbol iface, bool getterHasBody, SyntaxTokenList modifiers, bool isInterface, string fieldName, string getterbody, string parameters, bool isindexer)
        {
            if (isindexer)
                name = "opIndex";

            var args =_get;
            if (hasGetter && isProxy)
            {
                if (!isindexer)
                {
					writer.WriteLine (string.Format ("{0}{1} {4}{2}({3}) {{ return __Value.{2};}}", acccessmodifiers, typeString, name, (iface != null ? (TypeProcessor.ConvertType (iface) + " __ig=null") : ""), args));
                }
                else
                {
					writer.WriteLine (string.Format ("{0}{1} {2}({3})  {{ return __Value.{2};}}", acccessmodifiers, typeString, name, parameters));
                }
            }
            else if (hasGetter && !getterHasBody) //Getter
            {
                if (modifiers.Any(SyntaxKind.AbstractKeyword) || isInterface)
                {
                    if (!isindexer)
                    {
						writer.WriteLine (string.Format ("{0}{1} {4}{2}({3});", acccessmodifiers, typeString, name, (iface != null ? (TypeProcessor.ConvertType (iface) + " __ig=null") : ""), args));
                    }
                    else
                    {
						writer.WriteLine (string.Format ("{0}{1} {2}({3});", acccessmodifiers, typeString, name, parameters));
                    }
                }

                else
                {
                    if (!isindexer)
                    {
						writer.WriteLine (string.Format ("{0}{1} {5}{2}({3}) {{ return {4};}}", acccessmodifiers, typeString, name, (iface != null ? (TypeProcessor.ConvertType (iface) + " __ig=null") : ""), fieldName, args));
                    }
                    else
                    {
						writer.WriteLine (string.Format ("{0}{1} {2}({3})  {{ return {4};}}", acccessmodifiers, typeString, name, parameters, fieldName));
                    }
                }
            }
            else if (hasGetter)
            {
                writer.WriteIndent();
                writer.Write(acccessmodifiers);
                WriteRegion(true, getterbody, iface, writer, typeString, name, modifiers,parameters,isindexer,hasGetter);
            }
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:50,代码来源:WriteProperty.cs

示例13: WriteSetter

        private static void WriteSetter(OutputWriter writer, bool isProxy, bool hasSetter, string acccessmodifiers, string name, string typeString, ITypeSymbol iface, string isOverride, bool setterHasBody, SyntaxTokenList modifiers, bool isInterface, string fieldName, string setterbody, string parameters, bool isindexer,bool hasGetter)
        {

            if (isindexer)
                name = "opIndexAssign";

            var args = _set;
            if (hasSetter && isProxy)
            {
                if (!isindexer)
                {
					writer.WriteLine (string.Format ("{0} {2} {5}{1}({2} value{3}{4}){4} {{  __Value.{1} = value; return value;}}", acccessmodifiers, name, hasGetter ? typeString : "void", (iface != null ? ("," + TypeProcessor.ConvertType (iface) + " __ig=null") : ""), isOverride, args));
                }
                else
                {
					writer.WriteLine (string.Format ("{0} {2} {1}({2} value,{3}{4}) {4} {{  __Value.{1} = value;return value;}}", acccessmodifiers, name, typeString, parameters, isOverride));
                }
            }
            else if (hasSetter && !setterHasBody) //Setter
            {
                if (modifiers.Any(SyntaxKind.AbstractKeyword) || isInterface)
                {
                    if (!isindexer)
                    {
						writer.WriteLine (string.Format ("{0} {2} {5}{1}({2} value{3}{4});", acccessmodifiers, name, hasGetter ? typeString : "void", (iface != null ? ("," + TypeProcessor.ConvertType (iface) + " __ig=null") : ""), isOverride, args));
                    }
                    else
                    {
						writer.WriteLine (string.Format ("{0} {2} {1}({2} value,{3}{4});", acccessmodifiers, name, typeString, parameters, isOverride));
                    }
                }
                else
                {
                    if (!isindexer)
                    {
                        var returnValue = hasGetter ? writer.WriteIndentToString() + "return value;" :"";
                        writer.WriteLine (string.Format("{0} {2} {6}{1}({2} value{3}){4} {{{5} = value;{7}}}", acccessmodifiers, name, hasGetter?typeString :"void", (iface != null ? ("," + TypeProcessor.ConvertType (iface) + " __ig=null") : ""), isOverride, fieldName, args,returnValue));
                    }
                    else
                    {
                        var returnValue = hasGetter ? writer.WriteIndentToString() + "return value;" : "";

                        writer.WriteLine (string.Format("{0} {2} {1}({2} value,{3}){4} {{{5} = value;{6}}}" , acccessmodifiers, name, typeString, parameters, isOverride, fieldName, returnValue));
                    }
                }
            }
            else if (hasSetter)
            {
                writer.WriteIndent();
                writer.Write(acccessmodifiers);

                WriteRegion(false, setterbody, iface, writer, typeString, name, modifiers,parameters,isindexer,hasGetter);
            }
        }
开发者ID:mortezabarzkar,项目名称:SharpNative,代码行数:54,代码来源:WriteProperty.cs

示例14: NeedsComment

        private bool NeedsComment(SyntaxTokenList modifiers, SyntaxKind defaultModifier)
        {
            if (!(modifiers.Any(SyntaxKind.PublicKeyword)
                || modifiers.Any(SyntaxKind.ProtectedKeyword)
                || modifiers.Any(SyntaxKind.InternalKeyword)
                || defaultModifier == SyntaxKind.PublicKeyword
                || defaultModifier == SyntaxKind.ProtectedKeyword
                || defaultModifier == SyntaxKind.InternalKeyword))
            {
                return false;
            }

            // Also ignore partial classes because they get reported as SA1601
            return !modifiers.Any(SyntaxKind.PartialKeyword);
        }
开发者ID:iaingalloway,项目名称:StyleCopAnalyzers,代码行数:15,代码来源:SA1600ElementsMustBeDocumented.cs

示例15: GetAccessModifier

		private AccessModifierKind GetAccessModifier(SyntaxTokenList tokenList)
		{
			if (tokenList.Any(SyntaxKind.PublicKeyword))
			{
				return AccessModifierKind.Public;
			}

			if (tokenList.Any(SyntaxKind.PrivateKeyword))
			{
				return AccessModifierKind.Private;
			}

			return AccessModifierKind.Internal;
		}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:14,代码来源:TypeMetricsCalculator.cs


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