本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax类的典型用法代码示例。如果您正苦于以下问题:C# TypeSyntax类的具体用法?C# TypeSyntax怎么用?C# TypeSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了TypeSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllReferencedTypes
private static IEnumerable<TypeSyntax> GetAllReferencedTypes(TypeSyntax type, SyntaxNodeAnalysisContext context)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
// The "all referenced types" set will be the current type and any generic type parameters that it has (and any generic type parameters that
// they might have)..
yield return type;
// .. so, if this type doesn't have any type parameters then we're done here..
// If this isn't
var genericTypeIfApplicable = type as GenericNameSyntax;
if (genericTypeIfApplicable == null)
yield break;
// .. alternatively, if the type has the Bridge [IgnoreGeneric] attribute on it then we don't need to worry about the type parameters since
// there won't be references to them at runtime
var typeSymbolInfo = context.SemanticModel.GetSymbolInfo(type);
if ((typeSymbolInfo.Symbol != null) && typeSymbolInfo.Symbol.GetAttributes().Any(attribute => IsBridgeClass(attribute.AttributeClass, "IgnoreGenericAttribute")))
yield break;
foreach (var typeParameter in genericTypeIfApplicable.TypeArgumentList.Arguments)
{
foreach (var typeRelatedToTypeParameter in GetAllReferencedTypes(typeParameter, context))
yield return typeRelatedToTypeParameter;
}
}
示例2: GetTrackerClassName
public static string GetTrackerClassName(TypeSyntax type)
{
// NOTE: it's naive approach because we don't know semantic type information here.
var genericType = type as GenericNameSyntax;
if (genericType == null)
{
if (type.ToString().StartsWith("Trackable"))
{
return $"TrackablePocoTracker<I{type.ToString().Substring(9)}>";
}
}
else if (CodeAnalaysisExtensions.CompareTypeName(genericType.Identifier.ToString(),
"TrackableData.TrackableDictionary"))
{
return $"TrackableDictionaryTracker{genericType.TypeArgumentList}";
}
else if (CodeAnalaysisExtensions.CompareTypeName(genericType.Identifier.ToString(),
"TrackableData.TrackableSet"))
{
return $"TrackableSetTracker{genericType.TypeArgumentList}";
}
else if (CodeAnalaysisExtensions.CompareTypeName(genericType.Identifier.ToString(),
"TrackableData.TrackableList"))
{
return $"TrackableListTracker{genericType.TypeArgumentList}";
}
throw new Exception("Cannot resolve tracker class of " + type);
}
示例3: AddTypeParameters
private void AddTypeParameters(TypeSyntax typeSyntax, MultiDictionary<string, TypeParameterSymbol> map)
{
switch (typeSyntax.Kind())
{
case SyntaxKind.AliasQualifiedName:
AddTypeParameters(((AliasQualifiedNameSyntax)typeSyntax).Name, map);
break;
case SyntaxKind.QualifiedName:
// NOTE: Dev11 does not warn about duplication, it just matches parameter types to the
// *last* type parameter with the same name. That's why we're iterating backwards.
QualifiedNameSyntax qualifiedNameSyntax = (QualifiedNameSyntax)typeSyntax;
AddTypeParameters(qualifiedNameSyntax.Right, map);
AddTypeParameters(qualifiedNameSyntax.Left, map);
break;
case SyntaxKind.GenericName:
AddTypeParameters((GenericNameSyntax)typeSyntax, map);
break;
case SyntaxKind.IdentifierName:
case SyntaxKind.PredefinedType:
break;
default:
Debug.Assert(false, "Unexpected type syntax kind " + typeSyntax.Kind());
break;
}
}
示例4: IsTrackableType
public static bool IsTrackableType(TypeSyntax type)
{
// NOTE: it's naive approach because we don't know semantic type information here.
var parts = type.ToString().Split('.');
var typeName = parts[parts.Length - 1];
return typeName.StartsWith("Trackable");
}
示例5: HandleDeclaration
private static void HandleDeclaration(SyntaxNodeAnalysisContext context, TypeSyntax returnType)
{
var predefinedType = returnType as PredefinedTypeSyntax;
if (predefinedType != null && predefinedType.Keyword.IsKind(SyntaxKind.VoidKeyword))
{
// There is no return value
return;
}
var documentationStructure = context.Node.GetDocumentationCommentTriviaSyntax();
if (documentationStructure == null)
{
return;
}
if (documentationStructure.Content.GetFirstXmlElement(XmlCommentHelper.InheritdocXmlTag) != null)
{
// Don't report if the documentation is inherited.
return;
}
if (documentationStructure.Content.GetFirstXmlElement(XmlCommentHelper.ReturnsXmlTag) == null)
{
context.ReportDiagnostic(Diagnostic.Create(Descriptor, returnType.GetLocation()));
}
}
开发者ID:robinsedlaczek,项目名称:StyleCopAnalyzers,代码行数:28,代码来源:SA1615ElementReturnValueMustBeDocumented.cs
示例6: MethodDeclaration
public static MethodDeclarationSyntax MethodDeclaration(
SyntaxList<AttributeListSyntax> attributeLists,
SyntaxTokenList modifiers,
TypeSyntax returnType,
ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier,
SyntaxToken identifier,
TypeParameterListSyntax typeParameterList,
ParameterListSyntax parameterList,
SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses,
BlockSyntax body,
SyntaxToken semicolonToken)
{
return SyntaxFactory.MethodDeclaration(
attributeLists,
modifiers,
default(SyntaxToken),
returnType,
explicitInterfaceSpecifier,
identifier,
typeParameterList,
parameterList,
constraintClauses,
body,
default(ArrowExpressionClauseSyntax),
semicolonToken);
}
示例7: TryAnalyzeVariableDeclaration
protected override bool TryAnalyzeVariableDeclaration(TypeSyntax typeName, SemanticModel semanticModel, OptionSet optionSet, CancellationToken cancellationToken, out TextSpan issueSpan)
{
issueSpan = default(TextSpan);
// If it is currently not var, explicit typing exists, return.
// this also takes care of cases where var is mapped to a named type via an alias or a class declaration.
if (!typeName.IsTypeInferred(semanticModel))
{
return false;
}
if (typeName.Parent.IsKind(SyntaxKind.VariableDeclaration) &&
typeName.Parent.Parent.IsKind(SyntaxKind.LocalDeclarationStatement, SyntaxKind.ForStatement, SyntaxKind.UsingStatement))
{
// check assignment for variable declarations.
var variable = ((VariableDeclarationSyntax)typeName.Parent).Variables.First();
if (!AssignmentSupportsStylePreference(variable.Identifier, typeName, variable.Initializer, semanticModel, optionSet, cancellationToken))
{
return false;
}
}
issueSpan = typeName.Span;
return true;
}
示例8: BuildDeclaration
public MethodDeclarationSyntax BuildDeclaration(TypeSyntax returnType, string name, IEnumerable<ParameterSyntax> paramsInfo)
{
MethodDeclarationSyntax mDecl = SF.MethodDeclaration (returnType, name);
mDecl = mDecl.AddModifiers (SF.Token (SyntaxKind.PublicKeyword));
mDecl = mDecl.AddParameterListParameters (paramsInfo.ToArray ());
return mDecl;
}
示例9: MakeForeachLocal
public static SourceLocalSymbol MakeForeachLocal(
MethodSymbol containingMethod,
ForEachLoopBinder binder,
TypeSyntax typeSyntax,
SyntaxToken identifierToken,
ExpressionSyntax collection)
{
return new SourceLocalSymbol(containingMethod, binder, typeSyntax, identifierToken, null, collection, LocalDeclarationKind.ForEach);
}
示例10: FurnaceTypeWriter
public FurnaceTypeWriter(string baseClassFullName)
{
GuardBaseClass(baseClassFullName);
var typeIndex = baseClassFullName.LastIndexOf('.') + 1;
_typeName = baseClassFullName.Substring(typeIndex);
_typeNamespace = baseClassFullName.Substring(0, typeIndex - 1);
_baseTypeSyntax = SyntaxFactory.ParseTypeName(baseClassFullName);
}
示例11: PerformAction
internal static Document PerformAction(Document document, SyntaxNode root, TypeSyntax type)
{
var newRoot = root.ReplaceNode((SyntaxNode)
type,
SyntaxFactory.IdentifierName("var")
.WithLeadingTrivia(type.GetLeadingTrivia())
.WithTrailingTrivia(type.GetTrailingTrivia())
);
return document.WithSyntaxRoot(newRoot);
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:10,代码来源:ReplaceExplicitTypeWithVarCodeRefactoringProvider.cs
示例12: CreateAutoProperty
internal static PropertyDeclarationSyntax CreateAutoProperty(TypeSyntax type, string identifier, SyntaxList<AccessorDeclarationSyntax> accessors, SyntaxKind? accessibility)
{
var newProperty = SyntaxFactory.PropertyDeclaration(type, identifier)
.WithAccessorList(SyntaxFactory.AccessorList(accessors));
if (accessibility.HasValue)
newProperty = newProperty.WithModifiers(SyntaxFactory.TokenList(SyntaxFactory.Token(accessibility.Value)));
return newProperty.WithAdditionalAnnotations(Formatter.Annotation);
}
示例13: MakeLocal
public static SourceLocalSymbol MakeLocal(
Symbol containingSymbol,
Binder binder,
TypeSyntax typeSyntax,
SyntaxToken identifierToken,
LocalDeclarationKind declarationKind)
{
Debug.Assert(declarationKind != LocalDeclarationKind.ForEachIterationVariable);
return new SourceLocalSymbol(containingSymbol, binder, typeSyntax, identifierToken, declarationKind);
}
示例14: PerformAction
static Document PerformAction(Document document, SemanticModel model, SyntaxNode root, ITypeSymbol type, TypeSyntax typeSyntax)
{
var newRoot = root.ReplaceNode((SyntaxNode)
typeSyntax,
SyntaxFactory.ParseTypeName(type.ToMinimalDisplayString(model, typeSyntax.SpanStart))
.WithLeadingTrivia(typeSyntax.GetLeadingTrivia())
.WithTrailingTrivia(typeSyntax.GetTrailingTrivia())
);
return document.WithSyntaxRoot(newRoot);
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:10,代码来源:ReplaceVarWithExplicitTypeCodeRefactoringProvider.cs
示例15: QueryUnboundLambdaState
public QueryUnboundLambdaState(UnboundLambda unbound, Binder binder, RangeVariableMap rangeVariableMap, ImmutableArray<RangeVariableSymbol> parameters, ExpressionSyntax body, TypeSyntax castTypeSyntax, TypeSymbol castType)
: this(unbound, binder, rangeVariableMap, parameters, (LambdaSymbol lambdaSymbol, ExecutableCodeBinder lambdaBodyBinder, DiagnosticBag diagnostics) =>
{
BoundExpression expression = lambdaBodyBinder.BindValue(body, diagnostics, BindValueKind.RValue);
Debug.Assert((object)castType != null);
Debug.Assert(castTypeSyntax != null);
// We transform the expression from "expr" to "expr.Cast<castTypeOpt>()".
expression = lambdaBodyBinder.MakeQueryInvocation(body, expression, "Cast", castTypeSyntax, castType, diagnostics);
return lambdaBodyBinder.WrapExpressionLambdaBody(expression, body, diagnostics);
})
{ }