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


C# ITypeSymbol.GetTypeArguments方法代码示例

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


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

示例1: CanConvertTypes

        private bool CanConvertTypes(ITypeSymbol typeArgument, ITypeSymbol returnExpressionType, SemanticModel model)
        {
            // return false if there is no conversion for the top level type
            if (!model.Compilation.ClassifyConversion(typeArgument, returnExpressionType).Exists)
            {
                return false;
            }

            // Classify conversion does not consider type parameters on its own so we will have to recurse through them
            var leftArguments = typeArgument.GetTypeArguments();
            var rightArguments = returnExpressionType.GetTypeArguments();

            // If we have a mismatch in the number of type arguments we can immediately return as there is no way the types are convertible
            if ((leftArguments != null && rightArguments != null) &&
                leftArguments.Length != rightArguments.Length)
            {
                return false;
            }

            // If there are no more type arguments we assume they are convertible since the outer generic types are convertible
            if (leftArguments == null || !leftArguments.Any())
            {
                return true;
            }

            // Check if all the type arguments are convertible
            for (int i = 0; i < leftArguments.Length; i++)
            {
                if (!CanConvertTypes(leftArguments[i], rightArguments[i], model))
                {
                    return false;
                }
            }

            // Type argument comparisons have all succeeded, return true
            return true;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:37,代码来源:CSharpAddYieldCodeFixProvider.cs

示例2: IsContainerTypeEqualToReturnType

        /// <remarks>
        /// If there are type arguments on either side of assignment, we match type names instead of type equality 
        /// to account for inferred generic type arguments.
        /// e.g: Tuple.Create(0, true) returns Tuple&lt;X,y&gt; which isn't the same as type Tuple.
        /// otherwise, we match for type equivalence
        /// </remarks>
        private static bool IsContainerTypeEqualToReturnType(IMethodSymbol methodSymbol, 
            ITypeSymbol typeInDeclaration, 
            ITypeSymbol containingType)
        {
            var returnType = methodSymbol.ReturnType;

            if (typeInDeclaration?.GetTypeArguments().Length > 0 ||
                containingType.GetTypeArguments().Length > 0)
            {
                return containingType.Name.Equals(returnType.Name);
            }
            else
            {
                return containingType.Equals(returnType);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:22,代码来源:TypeStyleHelper.cs

示例3: DoesTypeReferenceTypeParameter

        private bool DoesTypeReferenceTypeParameter(ITypeSymbol type, ITypeParameterSymbol typeParameter, HashSet<ITypeSymbol> checkedTypes)
        {
            if (!checkedTypes.Add(type))
            {
                return false;
            }

            if (type == typeParameter ||
                type.GetTypeArguments().Any(t => DoesTypeReferenceTypeParameter(t, typeParameter, checkedTypes)))
            {
                return true;
            }

            if (type.ContainingType != null &&
                type.Kind != SymbolKind.TypeParameter &&
                DoesTypeReferenceTypeParameter(type.ContainingType, typeParameter, checkedTypes))
            {
                return true;
            }

            return false;
        }
开发者ID:GloryChou,项目名称:roslyn,代码行数:22,代码来源:AbstractExtractInterfaceService.cs

示例4: GetPreselectedSymbolsWorker2

		static Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker2 (CSharpSyntaxContext context, ITypeSymbol type, CancellationToken cancellationToken)
		{
			// Unwrap an array type fully.  We only want to offer the underlying element type in the
			// list of completion items.
			bool isArray = false;
			while (type is IArrayTypeSymbol) {
				isArray = true;
				type = ((IArrayTypeSymbol)type).ElementType;
			}

			if (type == null) {
				return Task.FromResult (Enumerable.Empty<ISymbol> ());
			}

			// Unwrap nullable
			if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) {
				type = type.GetTypeArguments ().FirstOrDefault ();
			}

			if (type.SpecialType == SpecialType.System_Void) {
				return Task.FromResult (Enumerable.Empty<ISymbol> ());
			}

			if (type.ContainsAnonymousType ()) {
				return Task.FromResult (Enumerable.Empty<ISymbol> ());
			}

			if (!type.CanBeReferencedByName) {
				return Task.FromResult (Enumerable.Empty<ISymbol> ());
			}

			// Normally the user can't say things like "new IList".  Except for "IList[] x = new |".
			// In this case we do want to allow them to preselect certain types in the completion
			// list even if they can't new them directly.
			if (!isArray) {
				if (type.TypeKind == TypeKind.Interface ||
				    type.TypeKind == TypeKind.Pointer ||
				    type.TypeKind == TypeKind.Dynamic ||
				    type.IsAbstract) {
					return Task.FromResult (Enumerable.Empty<ISymbol> ());
				}

				if (type.TypeKind == TypeKind.TypeParameter &&
				    !((ITypeParameterSymbol)type).HasConstructorConstraint) {
					return Task.FromResult (Enumerable.Empty<ISymbol> ());
				}
			}

//			if (!type.IsEditorBrowsable(options.GetOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language), context.SemanticModel.Compilation))
//			{
//				return SpecializedTasks.EmptyEnumerable<ISymbol>();
//			}
//
			return Task.FromResult (SpecializedCollections.SingletonEnumerable ((ISymbol)type));
		}
开发者ID:powerumc,项目名称:monodevelop_korean,代码行数:55,代码来源:ObjectCreationContextHandler.cs


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