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


C# SemanticModel.GetEnclosingNamedTypeOrAssembly方法代码示例

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


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

示例1: GetAttributeNamedParameters

 private IEnumerable<ISymbol> GetAttributeNamedParameters(
     SemanticModel semanticModel,
     int position,
     AttributeSyntax attribute,
     CancellationToken cancellationToken)
 {
     var within = semanticModel.GetEnclosingNamedTypeOrAssembly(position, cancellationToken);
     var attributeType = semanticModel.GetTypeInfo(attribute, cancellationToken).Type as INamedTypeSymbol;
     return attributeType.GetAttributeNamedParameters(semanticModel.Compilation, within);
 }
开发者ID:noahstein,项目名称:roslyn,代码行数:10,代码来源:AttributeNamedParameterCompletionProvider.cs

示例2: GetParameterLists

        private IEnumerable<ImmutableArray<IParameterSymbol>> GetParameterLists(
            SemanticModel semanticModel,
            int position,
            AttributeSyntax attribute,
            CancellationToken cancellationToken)
        {
            var within = semanticModel.GetEnclosingNamedTypeOrAssembly(position, cancellationToken);
            var attributeType = semanticModel.GetTypeInfo(attribute, cancellationToken).Type as INamedTypeSymbol;
            if (within != null && attributeType != null)
            {
                return attributeType.InstanceConstructors.Where(c => c.IsAccessibleWithin(within))
                                                         .Select(c => c.Parameters);
            }

            return SpecializedCollections.EmptyEnumerable<ImmutableArray<IParameterSymbol>>();
        }
开发者ID:noahstein,项目名称:roslyn,代码行数:16,代码来源:AttributeNamedParameterCompletionProvider.cs

示例3: HandleElementAccessExpression

		ParameterHintingResult HandleElementAccessExpression(SemanticModel semanticModel, ElementAccessExpressionSyntax node, CancellationToken cancellationToken)
		{
			var within = semanticModel.GetEnclosingNamedTypeOrAssembly(node.SpanStart, cancellationToken);

			var targetTypeInfo = semanticModel.GetTypeInfo (node.Expression);
			ITypeSymbol type = targetTypeInfo.Type;
			if (type == null)
				return ParameterHintingResult.Empty;

			var result = new ParameterHintingResult(node.SpanStart);
			if (type.TypeKind == TypeKind.Array) {
				result.AddData (factory.CreateArrayDataProvider ((IArrayTypeSymbol)type));
				return result;
			}

			var addedProperties = new List<IPropertySymbol> ();
			for (;type != null; type = type.BaseType) {
				foreach (var indexer in type.GetMembers ().OfType<IPropertySymbol> ().Where (p => p.IsIndexer)) {
					if (addedProperties.Any (added => SignatureComparer.HaveSameSignature (indexer, added, true)))
						continue;

					if (indexer.IsAccessibleWithin (within)) {
						addedProperties.Add (indexer); 
						result.AddData (factory.CreateIndexerParameterDataProvider (indexer, node));
					}
				}
			}
			return result;
		}
开发者ID:pjcollins,项目名称:monodevelop,代码行数:29,代码来源:ParameterHintingEngine.cs

示例4: HandleObjectCreationExpression

		ParameterHintingResult HandleObjectCreationExpression (SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken)
		{
			// var info = semanticModel.GetSymbolInfo(node, cancellationToken);
			var result = new ParameterHintingResult(node.SpanStart);
			var within = semanticModel.GetEnclosingNamedTypeOrAssembly(node.SpanStart, cancellationToken);

			var targetTypeInfo = semanticModel.GetTypeInfo (node);
			if (targetTypeInfo.Type != null) {
				foreach (IMethodSymbol c in targetTypeInfo.Type.GetMembers().OfType<IMethodSymbol>().Where(m => m.MethodKind == MethodKind.Constructor)) {
					if (c.IsAccessibleWithin (within)) {
						result.AddData(factory.CreateConstructorProvider(c));
					}
				}
			}
			return result;
		}
开发者ID:pjcollins,项目名称:monodevelop,代码行数:16,代码来源:ParameterHintingEngine.cs

示例5: HandleInvocationExpression

		ParameterHintingResult HandleInvocationExpression(SemanticModel semanticModel, InvocationExpressionSyntax node, CancellationToken cancellationToken)
		{
			var info = semanticModel.GetSymbolInfo (node, cancellationToken);
			var result = new ParameterHintingResult(node.SpanStart);

			var targetTypeInfo = semanticModel.GetTypeInfo (node.Expression);
			if (targetTypeInfo.Type != null && targetTypeInfo.Type.TypeKind == TypeKind.Delegate) {
				result.AddData (factory.CreateMethodDataProvider (targetTypeInfo.Type.GetDelegateInvokeMethod ()));
				return result;
			}

			var within = semanticModel.GetEnclosingNamedTypeOrAssembly(node.SpanStart, cancellationToken);
			ITypeSymbol type;
			string name = null;
			bool staticLookup = false;
			var ma = node.Expression as MemberAccessExpressionSyntax;
			var mb = node.Expression as MemberBindingExpressionSyntax;
			if (mb != null) {
				info = semanticModel.GetSymbolInfo (mb, cancellationToken);
				type = (info.Symbol ?? info.CandidateSymbols.FirstOrDefault ())?.ContainingType;
				name = mb.Name.Identifier.ValueText;
			} else if (ma != null) {
				staticLookup = semanticModel.GetSymbolInfo (ma.Expression).Symbol is ITypeSymbol;
				type = semanticModel.GetTypeInfo (ma.Expression).Type;
				name = info.Symbol?.Name ?? ma.Name.Identifier.ValueText;
			} else {
				type = within as ITypeSymbol;
				name = info.Symbol?.Name ?? node.Expression.ToString ();
				var sym = semanticModel.GetEnclosingSymbol (node.SpanStart, cancellationToken); 
				staticLookup = sym.IsStatic;
			}
			var addedMethods = new List<IMethodSymbol> ();
			var filterMethod = new HashSet<IMethodSymbol> ();
			for (;type != null; type = type.BaseType) {
				foreach (var method in type.GetMembers ().OfType<IMethodSymbol> ().Concat (GetExtensionMethods(semanticModel, type, node, cancellationToken)).Where (m => m.Name == name)) {
					if (staticLookup && !method.IsStatic)
						continue;
					if (method.OverriddenMethod != null)
						filterMethod.Add (method.OverriddenMethod);
					if (filterMethod.Contains (method))
						continue;
					if (addedMethods.Any (added => SignatureComparer.HaveSameSignature (method, added, true)))
						continue;
					if (method.IsAccessibleWithin (within)) {
						if (info.Symbol != null) {
							var smethod = (IMethodSymbol)info.Symbol;
							if (smethod != null && smethod.OriginalDefinition == method) {
								continue;
							}
						}
						addedMethods.Add (method); 
						result.AddData (factory.CreateMethodDataProvider (method));
					}
				}
			}
			if (info.Symbol != null && !addedMethods.Contains (info.Symbol)) {
				if (!staticLookup || info.Symbol.IsStatic)
					result.AddData (factory.CreateMethodDataProvider ((IMethodSymbol)info.Symbol));
			}
			return result;
		}
开发者ID:pjcollins,项目名称:monodevelop,代码行数:61,代码来源:ParameterHintingEngine.cs


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