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


C# ITypeSymbol.Equals方法代码示例

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


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

示例1: 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

示例2: IsPropertyAccessSomeObviousTypeCase

        protected static bool IsPropertyAccessSomeObviousTypeCase(SyntaxNodeAnalysisContext nodeContext, ExpressionSyntax initializerExpression, ITypeSymbol variableType)
        {
            var simpleMemberAccess = initializerExpression as MemberAccessExpressionSyntax;
            if (simpleMemberAccess != null)
            {
                var propertyType = nodeContext.SemanticModel.GetTypeInfo(simpleMemberAccess, nodeContext.CancellationToken).Type;
                return propertyType != null && variableType.Equals(propertyType);
            }

            return false;
        }
开发者ID:yeaicc,项目名称:RefactoringEssentials,代码行数:11,代码来源:SuggestUseVarKeywordEvidentAnalyzer.cs

示例3: CheckCuriouslyRecurringTemplatePattern

 static bool CheckCuriouslyRecurringTemplatePattern(ITypeSymbol containingType, ITypeSymbol type)
 {
     if (containingType.Equals(type))
         return true;
     var nt = containingType as INamedTypeSymbol;
     if (nt == null)
         return false;
     foreach (var typeArg in nt.TypeArguments)
     {
         if (CheckCuriouslyRecurringTemplatePattern(typeArg, type))
             return true;
     }
     return false;
 }
开发者ID:pgrefviau,项目名称:RefactoringEssentials,代码行数:14,代码来源:AccessToStaticMemberViaDerivedTypeAnalyzer.cs

示例4: IsCorrectTypeForYieldReturn

        private bool IsCorrectTypeForYieldReturn(ITypeSymbol typeArgument, ITypeSymbol returnExpressionType, ITypeSymbol methodReturnType, SemanticModel model)
        {
            var ienumerableSymbol = model.Compilation.GetTypeByMetadataName("System.Collections.IEnumerable");
            var ienumeratorSymbol = model.Compilation.GetTypeByMetadataName("System.Collections.IEnumerator");
            var ienumerableGenericSymbol = model.Compilation.GetTypeByMetadataName("System.Collections.Generic.IEnumerable`1");
            var ienumeratorGenericSymbol = model.Compilation.GetTypeByMetadataName("System.Collections.Generic.IEnumerator`1");

            if (ienumerableGenericSymbol == null ||
                ienumerableSymbol == null ||
                ienumeratorGenericSymbol == null ||
                ienumeratorSymbol == null)
            {
                return false;
            }

            ienumerableGenericSymbol = ienumerableGenericSymbol.Construct(typeArgument);
            ienumeratorGenericSymbol = ienumeratorGenericSymbol.Construct(typeArgument);

            if (!CanConvertTypes(typeArgument, returnExpressionType, model))
            {
                return false;
            }

            if (!(methodReturnType.Equals(ienumerableGenericSymbol) ||
                  methodReturnType.Equals(ienumerableSymbol) ||
                  methodReturnType.Equals(ienumeratorGenericSymbol) ||
                  methodReturnType.Equals(ienumeratorSymbol)))
            {
                return false;
            }

            return true;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:33,代码来源:CSharpAddYieldCodeFixProvider.cs

示例5: CastIfPossible

        /// <summary>
        /// Adds to <paramref name="targetType"/> if it does not contain an anonymous
        /// type and binds to the same type at the given <paramref name="position"/>.
        /// </summary>
        public static ExpressionSyntax CastIfPossible(
            this ExpressionSyntax expression,
            ITypeSymbol targetType,
            int position,
            SemanticModel semanticModel,
            out bool wasCastAdded)
        {
            wasCastAdded = false;

            if (targetType.ContainsAnonymousType())
            {
                return expression;
            }

            if (targetType.Kind == SymbolKind.DynamicType)
            {
                targetType = semanticModel.Compilation.GetSpecialType(SpecialType.System_Object);
            }

            var typeSyntax = targetType.GenerateTypeSyntax();
            var type = semanticModel.GetSpeculativeTypeInfo(
                position,
                typeSyntax,
                SpeculativeBindingOption.BindAsTypeOrNamespace).Type;

            if (!targetType.Equals(type))
            {
                return expression;
            }

            var castExpression = expression.Cast(targetType);

            // Ensure that inserting the cast doesn't change the semantics.
            var specAnalyzer = new SpeculationAnalyzer(expression, castExpression, semanticModel, CancellationToken.None);
            var speculativeSemanticModel = specAnalyzer.SpeculativeSemanticModel;
            if (speculativeSemanticModel == null)
            {
                return expression;
            }

            var speculatedCastExpression = (CastExpressionSyntax)specAnalyzer.ReplacedExpression;
            if (!speculatedCastExpression.IsUnnecessaryCast(speculativeSemanticModel, CancellationToken.None))
            {
                return expression;
            }

            wasCastAdded = true;
            return castExpression;
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:53,代码来源:ExpressionSyntaxExtensions.cs

示例6: IsArrayTypeSomeObviousTypeCase

        static bool IsArrayTypeSomeObviousTypeCase(SyntaxNodeAnalysisContext nodeContext, ExpressionSyntax initializerExpression, ITypeSymbol variableType, LocalDeclarationStatementSyntax localVariable)
        {
            var arrayCreationExpressionSyntax = initializerExpression as ArrayCreationExpressionSyntax;
            if (arrayCreationExpressionSyntax != null)
            {
                if (arrayCreationExpressionSyntax.Type.IsMissing)
                    return false;

                var arrayType = nodeContext.SemanticModel.GetTypeInfo(arrayCreationExpressionSyntax).ConvertedType;
                return arrayType != null && arrayCreationExpressionSyntax.Initializer != null && variableType.Equals(arrayType);
            }

            return false;
        }
开发者ID:pgrefviau,项目名称:RefactoringEssentials,代码行数:14,代码来源:SuggestUseVarKeywordEvidentAnalyzer.cs

示例7: IsObjectCreationSomeObviousTypeCase

        static bool IsObjectCreationSomeObviousTypeCase(SyntaxNodeAnalysisContext nodeContext, ExpressionSyntax initializerExpression, ITypeSymbol variableType)
        {
            var objectCreationExpressionSyntax = initializerExpression as ObjectCreationExpressionSyntax;
            if (objectCreationExpressionSyntax != null)
            {
                var objectType = nodeContext.SemanticModel.GetTypeInfo(objectCreationExpressionSyntax, nodeContext.CancellationToken).ConvertedType;
                return objectType != null && variableType.Equals(objectType);
            }

            return false;
        }
开发者ID:pgrefviau,项目名称:RefactoringEssentials,代码行数:11,代码来源:SuggestUseVarKeywordEvidentAnalyzer.cs

示例8: 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

示例9: ContainsType

		static bool ContainsType (ITypeSymbol testType, ITypeSymbol searchType)
		{
			if (testType == null)
				return false;
			Console.WriteLine (testType +" == " + searchType + " ? " + (testType == searchType) + "/" + testType.Equals (searchType));
			if (testType == searchType)
				return true;
			var namedTypeSymbol = testType as INamedTypeSymbol;
			if (namedTypeSymbol != null) {
				foreach (var arg in namedTypeSymbol.TypeArguments)
					if (ContainsType (arg, searchType))
						return true;
			}
			return false;
		}
开发者ID:pjcollins,项目名称:monodevelop,代码行数:15,代码来源:RoslynSymbolCompletionData.cs

示例10: IsTaskLike

        protected static bool IsTaskLike(
            ITypeSymbol returnType, ITypeSymbol taskType, INamedTypeSymbol taskOfTType)
        {
            if (returnType.Equals(taskType))
            {
                return true;
            }

            if (returnType.OriginalDefinition.Equals(taskOfTType))
            {
                return true;
            }

            if (returnType.IsErrorType() &&
                returnType.Name.Equals("Task"))
            {
                return true;
            }

            return false;
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:21,代码来源:AbstractMakeMethodAsynchronousCodeFixProvider.cs

示例11: DetermineType

		/// <summary>
		///     Classifies the type of the <paramref name="expressionType" />.
		/// </summary>
		private ExpressionType DetermineType(ITypeSymbol expressionType)
		{
			if (expressionType.Equals(_ctlFormulaType))
				return ExpressionType.Ctl;

			if (expressionType.Equals(_ltlFormulaType))
				return ExpressionType.Ltl;

			return ExpressionType.Other;
		}
开发者ID:cubeme,项目名称:safety-sharp,代码行数:13,代码来源:FormulaNormalizer.cs

示例12: IsFormulaType

		/// <summary>
		///   Classifies the type of the <paramref name="expressionType" />.
		/// </summary>
		private bool IsFormulaType(ITypeSymbol expressionType)
		{
			return expressionType.Equals(_formulaType);
		}
开发者ID:isse-augsburg,项目名称:ssharp,代码行数:7,代码来源:FormulaNormalizer.cs

示例13: IsInvocationSomeObviousTypeCase

        protected static bool IsInvocationSomeObviousTypeCase(SyntaxNodeAnalysisContext nodeContext, ExpressionSyntax initializerExpression, ITypeSymbol variableType)
        {
            var invocationExpression = initializerExpression as InvocationExpressionSyntax;
            if (invocationExpression != null)
            {
                var invokedMethod = nodeContext.SemanticModel.GetSymbolInfo(invocationExpression, nodeContext.CancellationToken).Symbol as IMethodSymbol;
                return invokedMethod != null && variableType.Equals(invokedMethod.ReturnType);
            }

            return false;
        }
开发者ID:ceddlyburge,项目名称:RefactoringEssentials,代码行数:11,代码来源:SuggestUseVarKeywordEvidentAnalyzer.cs


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