本文整理汇总了C#中Microsoft.CodeAnalysis.SemanticModel.GetSpeculativeTypeInfo方法的典型用法代码示例。如果您正苦于以下问题:C# SemanticModel.GetSpeculativeTypeInfo方法的具体用法?C# SemanticModel.GetSpeculativeTypeInfo怎么用?C# SemanticModel.GetSpeculativeTypeInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.SemanticModel
的用法示例。
在下文中一共展示了SemanticModel.GetSpeculativeTypeInfo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTypeSymbolFromPartialName
protected override ITypeSymbol GetTypeSymbolFromPartialName(string partialName, SemanticModel semanticModel, int position)
{
var parsedTypeName = SyntaxFactory.ParseTypeName(partialName);
return semanticModel.GetSpeculativeTypeInfo(position, parsedTypeName, SpeculativeBindingOption.BindAsTypeOrNamespace).Type;
}
示例2: GetInitializedType
static Tuple<ITypeSymbol, Location> GetInitializedType (Document document, SemanticModel semanticModel, int position, CancellationToken cancellationToken)
{
var tree = semanticModel.SyntaxTree;
if (tree.IsInNonUserCode (position, cancellationToken)) {
return null;
}
var token = tree.FindTokenOnLeftOfPosition (position, cancellationToken);
token = token.GetPreviousTokenIfTouchingWord (position);
if (token.Kind () != SyntaxKind.CommaToken && token.Kind () != SyntaxKind.OpenBraceToken) {
return null;
}
if (token.Parent == null || token.Parent.Parent == null) {
return null;
}
// If we got a comma, we can syntactically find out if we're in an ObjectInitializerExpression
if (token.Kind () == SyntaxKind.CommaToken &&
token.Parent.Kind () != SyntaxKind.ObjectInitializerExpression) {
return null;
}
// new Foo { bar = $$
if (token.Parent.Parent.IsKind (SyntaxKind.ObjectCreationExpression)) {
var objectCreation = token.Parent.Parent as ObjectCreationExpressionSyntax;
if (objectCreation == null) {
return null;
}
var ctor = semanticModel.GetSymbolInfo (objectCreation, cancellationToken).Symbol;
var type = ctor != null ? ctor.ContainingType : null;
if (type == null) {
type = semanticModel.GetSpeculativeTypeInfo (objectCreation.SpanStart, objectCreation.Type, SpeculativeBindingOption.BindAsTypeOrNamespace).Type as INamedTypeSymbol;
}
return Tuple.Create<ITypeSymbol, Location> (type, token.GetLocation ());
}
// Nested: new Foo { bar = { $$
if (token.Parent.Parent.IsKind (SyntaxKind.SimpleAssignmentExpression)) {
// Use the type inferrer to get the type being initialzied.
var typeInferenceService = TypeGuessing.typeInferenceService;
var parentInitializer = token.GetAncestor<InitializerExpressionSyntax> ();
var expectedType = typeInferenceService.InferType (semanticModel, parentInitializer, objectAsDefault: false, cancellationToken: cancellationToken);
return Tuple.Create (expectedType, token.GetLocation ());
}
return null;
}
示例3: linkArray
private SyntaxNode linkArray(ExcessContext ctx, SyntaxNode linkNode, SyntaxNode newNode, SemanticModel model)
{
ArrayCreationExpressionSyntax ace = newNode as ArrayCreationExpressionSyntax;
ArgumentSyntax arg = null;
bool asParam = newNode is ArgumentSyntax;
if (asParam)
{
arg = (ArgumentSyntax)newNode;
ace = (ArrayCreationExpressionSyntax)arg.Expression;
}
ITypeSymbol arrayType = null;
foreach (var expr in ace.Initializer.Expressions)
{
ITypeSymbol type = model.GetSpeculativeTypeInfo(expr.SpanStart, expr, SpeculativeBindingOption.BindAsExpression).Type;
if (arrayType == null)
arrayType = type;
else if (type != arrayType)
{
if (isSuperClass(type, arrayType))
arrayType = type; //downcast
else if (!isSuperClass(arrayType, type))
{
//td: error
return newNode; //unable to refine
}
}
}
if (arrayType == null)
return newNode;
ace = ace.WithType(SyntaxFactory.ArrayType(SyntaxFactory.IdentifierName(arrayType.Name + "[]")));
if (asParam)
return arg.WithExpression(ace);
return ace;
}
示例4: GetRangeVariableType
protected override ITypeSymbol GetRangeVariableType(SemanticModel model, IRangeVariableSymbol symbol)
{
var info = model.GetSpeculativeTypeInfo(this.SelectionResult.FinalSpan.Start, SyntaxFactory.ParseName(symbol.Name), SpeculativeBindingOption.BindAsExpression);
if (info.Type.IsErrorType())
{
return null;
}
return info.Type == null || info.Type.SpecialType == Microsoft.CodeAnalysis.SpecialType.System_Object
? info.Type
: info.ConvertedType;
}
示例5: GetMethods
private IEnumerable<IMethodSymbol> GetMethods(SemanticModel semanticModel, ITypeSymbol symbol, string name, MethodDeclarationSyntax method, MethodDeclarationSyntax originalMethod)
{
var parameters = method.ParameterList.Parameters;
var retval = this
.GetAllMembers(symbol)
.Where(c => c.Name == name)
.OfType<IMethodSymbol>()
.Where(c => c.Parameters.Select(d => this.GetParameterTypeComparisonKey(d.Type)).SequenceEqual(parameters.Select(d => this.GetParameterTypeComparisonKey(semanticModel.GetSpeculativeTypeInfo(originalMethod.ParameterList.SpanStart, d.Type, SpeculativeBindingOption.BindAsExpression).Type, method, d.Type))));
return retval;
}