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


C# SemanticModel.GetSpeculativeTypeInfo方法代码示例

本文整理汇总了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;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:6,代码来源:CSharpCodeModelService.cs

示例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;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:52,代码来源:ObjectInitializerContextHandler.cs

示例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;
        }
开发者ID:mpmedia,项目名称:Excess,代码行数:39,代码来源:Compiler.cs

示例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;
            }
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:12,代码来源:CSharpMethodExtractor.Analyzer.cs

示例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;
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:12,代码来源:Rewriter.cs


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