本文整理汇总了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);
}
示例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);
}
示例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);
}
示例5: String
public static INamedTypeSymbol String(Compilation compilation)
{
return compilation.GetSpecialType(SpecialType.System_String);
}
示例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));
}
示例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);
}
}
示例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;
}
示例9: CreateAnalyzerWithinCompilation
public IDiagnosticAnalyzer CreateAnalyzerWithinCompilation(Compilation compilation, AnalyzerOptions options, CancellationToken cancellationToken)
{
var disposableType = compilation.GetSpecialType(SpecialType.System_IDisposable);
return disposableType != null ? GetAnalyzer(disposableType) : null;
}
示例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;
}
示例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;
}
示例12: GetDisposeMethod
internal static IMethodSymbol GetDisposeMethod(Compilation compilation)
{
return (IMethodSymbol)compilation.GetSpecialType(SpecialType.System_IDisposable)
.GetMembers("Dispose")
.SingleOrDefault();
}
示例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();
}
示例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 });
}
示例15: UIntPtr
public static INamedTypeSymbol UIntPtr(Compilation compilation)
{
return compilation.GetSpecialType(SpecialType.System_UIntPtr);
}