• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ITypeSymbol类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ChangeToImmutableArrayCreateRange

        private static async Task<Document> ChangeToImmutableArrayCreateRange(
            ObjectCreationExpressionSyntax objectCreation,
            InitializerExpressionSyntax initializer,
            INamedTypeSymbol immutableArrayType,
            ITypeSymbol elementType,
            Document document,
            CancellationToken cancellationToken)
        {
            var generator = SyntaxGenerator.GetGenerator(document);

            var arrayElementType = (TypeSyntax)generator.TypeExpression(elementType);
            var arrayType = SyntaxFactory.ArrayType(arrayElementType, 
                SyntaxFactory.SingletonList(
                    SyntaxFactory.ArrayRankSpecifier(
                        SyntaxFactory.SingletonSeparatedList(
                            (ExpressionSyntax)SyntaxFactory.OmittedArraySizeExpression()))));

            var arrayCreationExpression = SyntaxFactory.ArrayCreationExpression(
                type: arrayType,
                initializer: SyntaxFactory.InitializerExpression(
                    kind: SyntaxKind.ArrayInitializerExpression,
                    expressions: initializer.Expressions))
                .WithAdditionalAnnotations(Formatter.Annotation);
            
            var type = generator.TypeExpression(immutableArrayType);
            var memberAccess = generator.MemberAccessExpression(type, "CreateRange");
            var invocation = generator.InvocationExpression(memberAccess, arrayCreationExpression);

            var oldRoot = await document.GetSyntaxRootAsync(cancellationToken);
            var newRoot = oldRoot.ReplaceNode(objectCreation, invocation);

            return document.WithSyntaxRoot(newRoot);
        }
开发者ID:jwendl,项目名称:CoreFxAnalyzers,代码行数:33,代码来源:DoNotUseImmutableArrayCollectionInitializerCodeFix.cs


示例2: IsSingleParameterLinqMethod

 /// <summary>
 /// Is this a method on <see cref="Enumerable" /> which takes only a single parameter?
 /// </summary>
 /// <remarks>
 /// Many of the methods we target, like Last, have overloads that take a filter delegate.  It is 
 /// completely appropriate to use such methods even with <see cref="IReadOnlyList{T}" />.  Only the single parameter
 /// ones are suspect
 /// </remarks>
 private static bool IsSingleParameterLinqMethod(IMethodSymbol methodSymbol, ITypeSymbol enumerableType)
 {
     Debug.Assert(methodSymbol.ReducedFrom == null);
     return
         methodSymbol.ContainingSymbol.Equals(enumerableType) &&
         methodSymbol.Parameters.Length == 1;
 }
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:15,代码来源:DoNotUseEnumerableMethodsOnIndexableCollectionsInsteadUseTheCollectionDirectly.cs


示例3: GetContainingTypeName

		private static IEnumerable<string> GetContainingTypeName(ITypeSymbol symbol)
		{
			for (var typeSymbol = symbol; typeSymbol != null; typeSymbol = typeSymbol.ContainingSymbol as ITypeSymbol)
			{
				yield return typeSymbol.Name;
			}
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:7,代码来源:TypeExtensions.cs


示例4: ResolveTypeName

		private static string ResolveTypeName(ITypeSymbol symbol)
		{
			INamedTypeSymbol symbol3;
			var builder = new StringBuilder();
			var flag = false;
			var symbol2 = symbol as IArrayTypeSymbol;
			if (symbol2 != null)
			{
				flag = true;
				symbol = symbol2.ElementType;
			}

			builder.Append(symbol.Name);
			if (((symbol3 = symbol as INamedTypeSymbol) != null) && symbol3.TypeArguments.Any())
			{
				IEnumerable<string> values = (from x in symbol3.TypeArguments.AsEnumerable() select ResolveTypeName(x)).ToArray<string>();
				builder.AppendFormat("<{0}>", string.Join(", ", values));
			}

			if (flag)
			{
				builder.Append("[]");
			}

			return builder.ToString();
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:26,代码来源:MemberNameResolver.cs


示例5: CreatePartialCompletionData

		public CreatePartialCompletionData (ICompletionDataKeyHandler keyHandler, RoslynCodeCompletionFactory factory, int declarationBegin, ITypeSymbol currentType, ISymbol member, bool afterKeyword) : base (keyHandler, factory, member)
		{
			this.afterKeyword = afterKeyword;
			this.currentType = currentType;
			this.declarationBegin = declarationBegin;
			this.GenerateBody = true;
		}
开发者ID:swarkcn,项目名称:monodevelop,代码行数:7,代码来源:CreatePartialCompletionData.cs


示例6: TypeHasWeakIdentity

 private bool TypeHasWeakIdentity(ITypeSymbol type, SemanticModel model)
 {
     switch (type.TypeKind)
     {
         case TypeKind.ArrayType:
             var arrayType = type as IArrayTypeSymbol;
             return arrayType != null && arrayType.ElementType.IsPrimitiveType();
         case TypeKind.Class:
         case TypeKind.TypeParameter:
             Compilation compilation = model.Compilation;
             INamedTypeSymbol marshalByRefObjectTypeSymbol = compilation.GetTypeByMetadataName("System.MarshalByRefObject");
             INamedTypeSymbol executionEngineExceptionTypeSymbol = compilation.GetTypeByMetadataName("System.ExecutionEngineException");
             INamedTypeSymbol outOfMemoryExceptionTypeSymbol = compilation.GetTypeByMetadataName("System.OutOfMemoryException");
             INamedTypeSymbol stackOverflowExceptionTypeSymbol = compilation.GetTypeByMetadataName("System.StackOverflowException");
             INamedTypeSymbol memberInfoTypeSymbol = compilation.GetTypeByMetadataName("System.Reflection.MemberInfo");
             INamedTypeSymbol parameterInfoTypeSymbol = compilation.GetTypeByMetadataName("System.Reflection.ParameterInfo");
             INamedTypeSymbol threadTypeSymbol = compilation.GetTypeByMetadataName("System.Threading.Thread");
             return
                 type.SpecialType == SpecialType.System_String ||
                 type.Equals(executionEngineExceptionTypeSymbol) ||
                 type.Equals(outOfMemoryExceptionTypeSymbol) ||
                 type.Equals(stackOverflowExceptionTypeSymbol) ||
                 type.Inherits(marshalByRefObjectTypeSymbol) ||
                 type.Inherits(memberInfoTypeSymbol) ||
                 type.Inherits(parameterInfoTypeSymbol) ||
                 type.Inherits(threadTypeSymbol);
         
         // What about struct types?
         default:
             return false;
     }
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:32,代码来源:CA2002DiagnosticAnalyzer.cs


示例7: Property

 public Property(string name, ITypeSymbol type, bool hasGetter, bool hasSetter)
 {
     Name = name;
     Type = type;
     HasSetter = hasSetter;
     HasGetter = hasGetter;
 }
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:7,代码来源:Property.cs


示例8: GetType

        internal static string GetType(ITypeSymbol typeSymbol, IEnumerable<string> knownClassNames)
        {
            string typeName;

            var success = GetKnownTypeName(typeSymbol, out typeName);
            if (success) { return typeName; }

            if (IsCollection(typeSymbol))
            {
                return GetCollectionTypeName(typeSymbol, knownClassNames);
            }

            if (typeSymbol.Name == "Task")
            {
                var namedTypeSymbol = typeSymbol as INamedTypeSymbol;

                var typeArgument = namedTypeSymbol?.TypeArguments.FirstOrDefault();
                if (typeArgument != null)
                {
                    return GetType(typeArgument, knownClassNames);
                }

                return Constants.VoidType;
            }

            if (typeSymbol.Name.Equals("void", StringComparison.OrdinalIgnoreCase))
            {
                return Constants.VoidType;
            }

            return knownClassNames.Contains(typeSymbol.Name) ? typeSymbol.Name : Constants.AnyType;
        }
开发者ID:lukeautry,项目名称:DotNetWebSDK,代码行数:32,代码来源:TypeResolver.cs


示例9: CodeTypeRef

 private CodeTypeRef(CodeModelState state, object parent, ProjectId projectId, ITypeSymbol typeSymbol)
     : base(state)
 {
     _parentHandle = new ParentHandle<object>(parent);
     _projectId = projectId;
     _symbolId = typeSymbol.GetSymbolKey();
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:7,代码来源:CodeTypeRef.cs


示例10: IndexerProperty

 public IndexerProperty(
     ITypeSymbol type, 
     bool hasGetter, 
     bool hasSetter):
     base("Item",type,hasGetter, hasSetter)
 {
 }
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:7,代码来源:IndexerProperty.cs


示例11: FilterTypeSymbol

		protected void FilterTypeSymbol(ITypeSymbol symbol)
		{
			switch (symbol.TypeKind)
			{
				case TypeKind.Class:
				case TypeKind.Delegate:
				case TypeKind.Enum:
				case TypeKind.Interface:
					{
						var qualifiedName = symbol.GetQualifiedName().ToString();
						if (!_types.ContainsKey(qualifiedName))
						{
							_types.Add(qualifiedName, symbol);
						}

						break;
					}

				case TypeKind.Dynamic:
				case TypeKind.Error:
				case TypeKind.TypeParameter:
					break;

				default:
					return;
			}
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:27,代码来源:ClassCouplingAnalyzerBase.cs


示例12: Collect

            public static IEnumerable<ITypeParameterSymbol> Collect(ITypeSymbol typeSymbol)
            {
                var collector = new TypeParameterCollector();
                typeSymbol.Accept(collector);

                return collector._typeParameters;
            }
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:MethodExtractor.TypeParameterCollector.cs


示例13: DeriveAdditionKind

        public static BinaryOperationKind DeriveAdditionKind(ITypeSymbol type)
        {
            switch (type.SpecialType)
            {
                case SpecialType.System_Int32:
                case SpecialType.System_Int64:
                case SpecialType.System_Int16:
                case SpecialType.System_SByte:
                    return BinaryOperationKind.IntegerAdd;
                case SpecialType.System_UInt32:
                case SpecialType.System_UInt64:
                case SpecialType.System_UInt16:
                case SpecialType.System_Byte:
                case SpecialType.System_Char:
                case SpecialType.System_Boolean:
                    return BinaryOperationKind.UnsignedAdd;
                case SpecialType.System_Single:
                case SpecialType.System_Double:
                    return BinaryOperationKind.FloatingAdd;
                case SpecialType.System_Object:
                    return BinaryOperationKind.ObjectAdd;
            }

            if (type.TypeKind == TypeKind.Enum)
            {
                return Semantics.BinaryOperationKind.EnumAdd;
            }

            return Semantics.BinaryOperationKind.None;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:30,代码来源:Expression.cs


示例14: GenerateBackingField

 private static MemberDeclarationSyntax GenerateBackingField(ITypeSymbol typeSymbol, string backingFieldName, Workspace workspace)
 {
     var generator = SyntaxGenerator.GetGenerator(workspace, LanguageNames.CSharp);
     SyntaxNode type = generator.TypeExpression(typeSymbol);
     FieldDeclarationSyntax fieldDecl = ParseMember($"private _field_Type_ {backingFieldName};") as FieldDeclarationSyntax;
     return fieldDecl.ReplaceNode(fieldDecl.Declaration.Type, type.WithAdditionalAnnotations(Simplifier.SpecialTypeAnnotation)); 
 }
开发者ID:CNinnovation,项目名称:TechConference2016,代码行数:7,代码来源:CodeGeneration.cs


示例15: CreatePropertySymbol

 internal static IPropertySymbol CreatePropertySymbol(
     INamedTypeSymbol containingType,
     IList<AttributeData> attributes,
     Accessibility accessibility,
     DeclarationModifiers modifiers,
     ITypeSymbol type,
     IPropertySymbol explicitInterfaceSymbol,
     string name,
     IList<IParameterSymbol> parameters,
     IMethodSymbol getMethod,
     IMethodSymbol setMethod,
     bool isIndexer = false,
     SyntaxNode initializer = null)
 {
     var result = new CodeGenerationPropertySymbol(
         containingType,
         attributes,
         accessibility,
         modifiers,
         type,
         explicitInterfaceSymbol,
         name,
         isIndexer,
         parameters,
         getMethod,
         setMethod);
     CodeGenerationPropertyInfo.Attach(result, modifiers.IsNew, modifiers.IsUnsafe, initializer);
     return result;
 }
开发者ID:RoryVL,项目名称:roslyn,代码行数:29,代码来源:CodeGenerationSymbolFactory.cs


示例16: IsRequiredCastForReferenceEqualityComparison

        private static bool IsRequiredCastForReferenceEqualityComparison(ITypeSymbol outerType, CastExpressionSyntax castExpression, SemanticModel semanticModel, out ExpressionSyntax other)
        {
            if (outerType.SpecialType == SpecialType.System_Object)
            {
                var expression = castExpression.WalkUpParentheses();
                var parentNode = expression.Parent;
                if (parentNode.IsKind(SyntaxKind.EqualsExpression) || parentNode.IsKind(SyntaxKind.NotEqualsExpression))
                {
                    // Reference comparison.
                    var binaryExpression = (BinaryExpressionSyntax)parentNode;
                    other = binaryExpression.Left == expression ?
                        binaryExpression.Right :
                        binaryExpression.Left;

                    // Explicit cast not required if we are comparing with type parameter with a class constraint.
                    var otherType = semanticModel.GetTypeInfo(other).Type;
                    if (otherType != null && otherType.TypeKind != TypeKind.TypeParameter)
                    {
                        return !other.WalkDownParentheses().IsKind(SyntaxKind.CastExpression);
                    }
                }
            }

            other = null;
            return false;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:26,代码来源:CastExpressionSyntaxExtensions.cs


示例17: IsAssignableTo

 protected override bool IsAssignableTo(Compilation compilation, ITypeSymbol fromSymbol, ITypeSymbol toSymbol)
 {
     return
         fromSymbol != null &&
         toSymbol != null &&
         ((CSharpCompilation)compilation).ClassifyConversion(fromSymbol, toSymbol).IsImplicit;
 }
开发者ID:bkoelman,项目名称:roslyn-analyzers,代码行数:7,代码来源:CSharpUseGenericEventHandlerInstances.cs


示例18: GetExtensionMethods

		public List<IMethodSymbol> GetExtensionMethods(string name, ITypeSymbol type)
		{
			List<IMethodSymbol> methods;

			if (type == null)
			{
				throw new ArgumentNullException(nameof(type));
			}

			if (!extensionMethodsByName.TryGetValue(name, out methods))
			{
				return new List<IMethodSymbol>();
			}

			var retval = new List<KeyValuePair<IMethodSymbol, int>>();

			foreach (var method in methods)
			{
				var depth = method.Parameters[0].Type?.IsAssignableFrom(type, 0);

				if (depth > -1)
				{
					retval.Add(new KeyValuePair<IMethodSymbol, int>(method, depth.Value));
				}
			}

			return retval.OrderBy(c => c.Key.ContainingAssembly.Equals(this.compilation.Assembly) ? 0 : c.Value + 1).Select(c => c.Key).ToList();
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:28,代码来源:CompilationLookup.cs


示例19: TryGetAllEnumMembers

        private static bool TryGetAllEnumMembers(
            ITypeSymbol enumType,
            Dictionary<long, ISymbol> enumValues)
        {
            foreach (var member in enumType.GetMembers())
            {
                // skip `.ctor` and `__value`
                var fieldSymbol = member as IFieldSymbol;
                if (fieldSymbol == null || fieldSymbol.Type.SpecialType != SpecialType.None)
                {
                    continue;
                }

                if (fieldSymbol.ConstantValue == null)
                {
                    // We have an enum that has problems with it (i.e. non-const members).  We won't
                    // be able to determine properly if the switch is complete.  Assume it is so we
                    // don't offer to do anything.
                    return false;
                }

                // Multiple enum members may have the same value.  Only consider the first one
                // we run int.
                var enumValue = IntegerUtilities.ToInt64(fieldSymbol.ConstantValue);
                if (!enumValues.ContainsKey(enumValue))
                {
                    enumValues.Add(enumValue, fieldSymbol);
                }
            }

            return true;
        }
开发者ID:xyh413,项目名称:roslyn,代码行数:32,代码来源:PopulateSwitchHelpers.cs


示例20: IsDerivedTypeRecursive

        private static bool IsDerivedTypeRecursive(ITypeSymbol derivedType, ITypeSymbol type)
        {
            if (derivedType == type) return true;
            if (derivedType.BaseType == null) return false;

            return IsDerivedTypeRecursive(derivedType.BaseType, type);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:7,代码来源:MyRoslynExtensions.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ITypeSystem类代码示例发布时间:2022-05-24
下一篇:
C# ITypeResolver类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap