本文整理汇总了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;
}
}
}
示例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)));
}
}
}
示例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();
}
}
示例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;
}
示例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);
}
//.........这里部分代码省略.........
示例6: IsConst
public static bool IsConst(SyntaxTokenList modifiers, EqualsValueClauseSyntax initializerOpt, TypeSyntax type)
{
var t = TypeProcessor.ConvertType(type);
return modifiers.Any(SyntaxKind.ConstKeyword);
}
示例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;
}
示例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;
}
示例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;
}
示例10: IsConst
static bool IsConst (SyntaxTokenList modifiers)
{
return modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ConstKeyword);
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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;
}