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


C# Compilation.GetSpecialType方法代码示例

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


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

示例1: CreateEqualsMethod

        public static IMethodSymbol CreateEqualsMethod(
            this SyntaxGenerator factory,
            Compilation compilation,
            INamedTypeSymbol containingType,
            IList<ISymbol> symbols,
            CancellationToken cancellationToken)
        {
            var statements = CreateEqualsMethodStatements(factory, compilation, containingType, symbols, cancellationToken);

            return CodeGenerationSymbolFactory.CreateMethodSymbol(
                attributes: null,
                accessibility: Accessibility.Public,
                modifiers: new DeclarationModifiers(isOverride: true),
                returnType: compilation.GetSpecialType(SpecialType.System_Boolean),
                explicitInterfaceSymbol: null,
                name: EqualsName,
                typeParameters: null,
                parameters: new[] { CodeGenerationSymbolFactory.CreateParameterSymbol(compilation.GetSpecialType(SpecialType.System_Object), ObjName) },
                statements: statements);
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:20,代码来源:ICodeDefinitionFactoryExtensions_CreateEqualsMethod.cs

示例2: CreateGetHashCodeMethod

        public static IMethodSymbol CreateGetHashCodeMethod(
            this ISyntaxFactoryService factory,
            Compilation compilation,
            INamedTypeSymbol containingType,
            IList<ISymbol> symbols,
            CancellationToken cancellationToken)
        {
            var statements = CreateGetHashCodeMethodStatements(factory, compilation, containingType, symbols, cancellationToken);

            return CodeGenerationSymbolFactory.CreateMethodSymbol(
                attributes: null,
                accessibility: Accessibility.Public,
                modifiers: new SymbolModifiers(isOverride: true),
                returnType: compilation.GetSpecialType(SpecialType.System_Int32),
                explicitInterfaceSymbol: null,
                name: GetHashCodeName,
                typeParameters: null,
                parameters: null,
                statements: statements);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:20,代码来源:ICodeDefinitionFactoryExtensions_CreateGetHashCodeMethod.cs

示例3: TryGetSymbolForIDisposable

        private static INamedTypeSymbol TryGetSymbolForIDisposable(Compilation compilation)
        {
            // Get symbol for 'System.IDisposable'.
            var idisposable = compilation.GetSpecialType(SpecialType.System_IDisposable);
            if ((idisposable != null) && (idisposable.TypeKind == TypeKind.Interface))
            {
                var idisposableMembers = idisposable.GetMembers().ToArray();

                // Get symbol for 'System.IDisposable.Dispose()'.
                IMethodSymbol disposeMethod = null;
                if ((idisposableMembers.Length == 1) && (idisposableMembers[0].Kind == SymbolKind.Method) &&
                    (idisposableMembers[0].Name == "Dispose"))
                {
                    disposeMethod = idisposableMembers[0] as IMethodSymbol;
                    if ((disposeMethod != null) && (!disposeMethod.IsStatic) && disposeMethod.ReturnsVoid &&
                        (disposeMethod.Arity == 0) && (disposeMethod.Parameters.Length == 0))
                    {
                        return idisposable;
                    }
                }
            }

            return null;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:24,代码来源:AbstractImplementInterfaceService.DisposePatternCodeAction.cs

示例4: Object

 public static INamedTypeSymbol Object(Compilation compilation)
 {
     return compilation.GetSpecialType(SpecialType.System_Object);
 }
开发者ID:vweijsters,项目名称:roslyn-analyzers,代码行数:4,代码来源:WellKnownTypes.cs

示例5: String

 public static INamedTypeSymbol String(Compilation compilation)
 {
     return compilation.GetSpecialType(SpecialType.System_String);
 }
开发者ID:vweijsters,项目名称:roslyn-analyzers,代码行数:4,代码来源:WellKnownTypes.cs

示例6: GetType

 private static ITypeSymbol GetType(Compilation compilation, ISymbol symbol)
 {
     return symbol.TypeSwitch(
         (IFieldSymbol field) => field.Type,
         (IPropertySymbol property) => property.Type,
         (ISymbol _) => compilation.GetSpecialType(SpecialType.System_Object));
 }
开发者ID:RoryVL,项目名称:roslyn,代码行数:7,代码来源:ICodeDefinitionFactoryExtensions_CreateEqualsMethod.cs

示例7: GetExpectedMethodSignature

 private static ExpectedMethodSignature GetExpectedMethodSignature(IMethodSymbol operatorOverloadSymbol, Compilation compilation)
 {
     var containingType = (ITypeSymbol)operatorOverloadSymbol.ContainingType;
     ITypeSymbol returnType = operatorOverloadSymbol.ReturnType;
     string expectedName = OperatorOverloadsHaveNamedAlternatesAnalyzer.GetExpectedAlternateMethodGroup(operatorOverloadSymbol.Name, returnType).AlternateMethod1;
     switch (operatorOverloadSymbol.Name)
     {
         case "op_GreaterThan":
         case "op_GreaterThanOrEqual":
         case "op_LessThan":
         case "op_LessThanOrEqual":
             // e.g., public int CompareTo(MyClass other)
             INamedTypeSymbol intType = compilation.GetSpecialType(SpecialType.System_Int32);
             return new ExpectedMethodSignature(expectedName, intType, ImmutableArray.Create(Tuple.Create("other", containingType)), isStatic: false);
         case "op_Decrement":
         case "op_Increment":
         case "op_UnaryNegation":
         case "op_UnaryPlus":
             // e.g., public static MyClass Decrement(MyClass item)
             return new ExpectedMethodSignature(expectedName, returnType, ImmutableArray.Create(Tuple.Create("item", containingType)), isStatic: true);
         case "op_Implicit":
             // e.g., public int ToInt32()
             return new ExpectedMethodSignature(expectedName, returnType, ImmutableArray.Create<Tuple<string, ITypeSymbol>>(), isStatic: false);
         default:
             // e.g., public static MyClass Add(MyClass left, MyClass right)
             return new ExpectedMethodSignature(expectedName, returnType, ImmutableArray.Create(Tuple.Create("left", containingType), Tuple.Create("right", containingType)), isStatic: true);
     }
 }
开发者ID:duracellko,项目名称:roslyn-analyzers,代码行数:28,代码来源:OperatorOverloadsHaveNamedAlternates.Fixer.cs

示例8: FindSetPropertyMethod

        private static IMethodSymbol FindSetPropertyMethod(this INamedTypeSymbol classSymbol, Compilation compilation)
        {
            // Find SetProperty<T>(ref T, T, string) method.
            var setPropertyMethod = classSymbol
                .GetMembers("SetProperty")
                .OfType<IMethodSymbol>()
                .FirstOrDefault(m => m.Parameters.Length == 3 && m.TypeParameters.Length == 1);

            if (setPropertyMethod != null)
            {
                var parameters = setPropertyMethod.Parameters;
                var typeParameter = setPropertyMethod.TypeParameters[0];
                var stringType = compilation.GetSpecialType(SpecialType.System_String);

                if (setPropertyMethod.ReturnsVoid &&
                    parameters[0].RefKind == RefKind.Ref &&
                    parameters[0].Type.Equals(typeParameter) &&
                    parameters[1].Type.Equals(typeParameter) &&
                    parameters[2].Type.Equals(stringType))
                {
                    return setPropertyMethod;
                }
            }

            return null;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:26,代码来源:CodeGeneration.cs

示例9: CreateAnalyzerWithinCompilation

 public IDiagnosticAnalyzer CreateAnalyzerWithinCompilation(Compilation compilation, AnalyzerOptions options, CancellationToken cancellationToken)
 {
     var disposableType = compilation.GetSpecialType(SpecialType.System_IDisposable);
     return disposableType != null ? GetAnalyzer(disposableType) : null;
 }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:5,代码来源:CA2213DiagnosticAnalyzer.cs

示例10: GetElementType

		ITypeSymbol GetElementType (Compilation compilation, ITypeSymbol type)
		{
			ITypeSymbol tmp = type;
			foreach (var baseType in type.AllInterfaces) {
				if (baseType != null && baseType.Name == "IEnumerable") {
					if (baseType.TypeArguments.Length > 0) {
						return baseType.TypeArguments [0];
					} else if (baseType.ContainingNamespace.ToDisplayString (Ambience.LabelFormat) == "System.Collections") {
						tmp = compilation.GetSpecialType (SpecialType.System_Object);
					}
				}
			}
			return tmp;
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:14,代码来源:ExpansionObject.cs

示例11: OnCompilationStarted

 public ICompilationEndedAnalyzer OnCompilationStarted(Compilation compilation, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
 {
     var disposableType = compilation.GetSpecialType(SpecialType.System_IDisposable);
     return disposableType != null ? GetAnalyzer(disposableType) : null;
 }
开发者ID:pheede,项目名称:roslyn,代码行数:5,代码来源:CA2213DiagnosticAnalyzer.cs

示例12: GetDisposeMethod

 internal static IMethodSymbol GetDisposeMethod(Compilation compilation)
 {
     return (IMethodSymbol)compilation.GetSpecialType(SpecialType.System_IDisposable)
         .GetMembers("Dispose")
         .SingleOrDefault();
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:6,代码来源:DisposeNotImplementingDispose.cs

示例13: GetSpecialTypeLibAttributeConstructorsWorker

        /// <summary>
        /// The TypeLib*Attribute classes that accept TypeLib*Flags with FHidden as an option all have two constructors,
        /// one accepting a TypeLib*Flags and the other a short. This methods gets those two constructor symbols for any
        /// of these attribute classes. It does not require that the either of these types be those shipped by Microsoft,
        /// but it does demand the types found follow the expected pattern. If at any point that pattern appears to be
        /// violated, return an empty enumerable to indicate that no appropriate constructors were found.
        /// </summary>
        private static List<IMethodSymbol> GetSpecialTypeLibAttributeConstructorsWorker(
            Compilation compilation,
            string attributeMetadataName,
            string flagsMetadataName)
        {
            var typeLibAttributeType = compilation.GetTypeByMetadataName(attributeMetadataName);
            var typeLibFlagsType = compilation.GetTypeByMetadataName(flagsMetadataName);
            var shortType = compilation.GetSpecialType(SpecialType.System_Int16);

            if (typeLibAttributeType == null || typeLibFlagsType == null || shortType == null)
            {
                return new List<IMethodSymbol>();
            }

            var candidateConstructors = typeLibAttributeType.Constructors
                                                            .Where(c => c.Parameters.Length == 1 &&
                                                                        (c.Parameters[0].Type == typeLibFlagsType || c.Parameters[0].Type == shortType));

            candidateConstructors = candidateConstructors.Where(c => (!c.IsVararg &&
                                                                      !c.Parameters[0].IsRefOrOut() &&
                                                                      !c.Parameters[0].CustomModifiers.Any()));

            return candidateConstructors.ToList();
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:31,代码来源:EditorBrowsableHelpers.cs

示例14: GenerateSetPropertyMethod

        internal static IMethodSymbol GenerateSetPropertyMethod(Compilation compilation)
        {
            var body = SyntaxFactory.ParseStatement(
                @"if (!System.Collections.Generic.EqualityComparer<T>.Default.Equals(field, value))
{
    field = value;

    var handler = PropertyChanged;
    if (handler != null)
    {
        handler(this, new System.ComponentModel.PropertyChangedEventArgs(name));
    }
}");

            body = body.WithAdditionalAnnotations(Simplifier.Annotation);

            var stringType = compilation.GetSpecialType(SpecialType.System_String);
            var voidType = compilation.GetSpecialType(SpecialType.System_Void);

            var typeParameter = CodeGenerationSymbolFactory.CreateTypeParameterSymbol("T");

            var parameter1 = CodeGenerationSymbolFactory.CreateParameterSymbol(
                attributes: null,
                refKind: RefKind.Ref,
                isParams: false,
                type: typeParameter,
                name: "field");

            var parameter2 = CodeGenerationSymbolFactory.CreateParameterSymbol(typeParameter, "value");
            var parameter3 = CodeGenerationSymbolFactory.CreateParameterSymbol(stringType, "name");

            return CodeGenerationSymbolFactory.CreateMethodSymbol(
                attributes: null,
                accessibility: Microsoft.CodeAnalysis.Accessibility.Private,
                modifiers: new SymbolModifiers(),
                returnType: voidType,
                explicitInterfaceSymbol: null,
                name: "SetProperty",
                typeParameters: new[] { typeParameter },
                parameters: new[] { parameter1, parameter2, parameter3 },
                statements: new[] { body });
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:42,代码来源:CodeGeneration.cs

示例15: UIntPtr

 public static INamedTypeSymbol UIntPtr(Compilation compilation)
 {
     return compilation.GetSpecialType(SpecialType.System_UIntPtr);
 }
开发者ID:vweijsters,项目名称:roslyn-analyzers,代码行数:4,代码来源:WellKnownTypes.cs


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