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


C# ITypeSymbol类代码示例

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


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


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