本文整理汇总了C#中CSharpConversions类的典型用法代码示例。如果您正苦于以下问题:C# CSharpConversions类的具体用法?C# CSharpConversions怎么用?C# CSharpConversions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CSharpConversions类属于命名空间,在下文中一共展示了CSharpConversions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TypeInference
internal TypeInference(ICompilation compilation, CSharpConversions conversions)
{
Debug.Assert(compilation != null);
Debug.Assert(conversions != null);
this.compilation = compilation;
this.conversions = conversions;
}
示例2: VisitForeachStatement
public override void VisitForeachStatement(ForeachStatement foreachStatement)
{
base.VisitForeachStatement(foreachStatement);
var rr = ctx.Resolve(foreachStatement) as ForEachResolveResult;
if (rr == null)
return;
if (rr.ElementType.Kind == TypeKind.Unknown)
return;
if (ReflectionHelper.GetTypeCode(rr.ElementType) == TypeCode.Object)
return;
if (conversions == null) {
conversions = CSharpConversions.Get(ctx.Compilation);
}
Conversion c = conversions.ImplicitConversion(rr.ElementType, rr.ElementVariable.Type);
if (c.IsValid)
return;
var csResolver = ctx.GetResolverStateBefore(foreachStatement);
var builder = new TypeSystemAstBuilder(csResolver);
AstType elementType = builder.ConvertType(rr.ElementType);
AstType variableType = foreachStatement.VariableType;
string issueText = ctx.TranslateString("Collection element type '{0}' is not implicitly convertible to '{1}'");
string fixText = ctx.TranslateString("Use type '{0}'");
AddIssue(variableType, string.Format(issueText, elementType.GetText(), variableType.GetText()),
new CodeAction(string.Format(fixText, elementType.GetText()),
script => script.Replace(variableType, elementType)));
}
示例3: CSharpResolver
public CSharpResolver(ICompilation compilation)
{
if (compilation == null)
throw new ArgumentNullException("compilation");
this.compilation = compilation;
this.conversions = CSharpConversions.Get(compilation);
this.context = new CSharpTypeResolveContext(compilation.MainAssembly);
}
示例4: CSharpResolver
public CSharpResolver(ICompilation compilation)
{
if (compilation == null)
throw new ArgumentNullException("compilation");
this.compilation = compilation;
this.conversions = CSharpConversions.Get(compilation);
this.context = new CSharpTypeResolveContext(compilation.MainAssembly);
var pc = compilation.MainAssembly.UnresolvedAssembly as CSharpProjectContent;
if (pc != null) {
this.checkForOverflow = pc.CompilerSettings.CheckForOverflow;
}
}
示例5: SupportsIndexingCriterion
public SupportsIndexingCriterion(IType returnType, IEnumerable<IType> argumentTypes, CSharpConversions conversions, bool isWriteAccess = false)
{
if (returnType == null)
throw new ArgumentNullException("returnType");
if (argumentTypes == null)
throw new ArgumentNullException("argumentTypes");
if (conversions == null)
throw new ArgumentNullException("conversions");
this.returnType = returnType;
this.argumentTypes = argumentTypes.ToList();
this.conversions = conversions;
this.isWriteAccess = isWriteAccess;
}
示例6: OverloadResolution
public OverloadResolution(ICompilation compilation, ResolveResult[] arguments, string[] argumentNames = null, IType[] typeArguments = null, CSharpConversions conversions = null)
{
if (compilation == null)
throw new ArgumentNullException("compilation");
if (arguments == null)
throw new ArgumentNullException("arguments");
if (argumentNames == null)
argumentNames = new string[arguments.Length];
else if (argumentNames.Length != arguments.Length)
throw new ArgumentException("argumentsNames.Length must be equal to arguments.Length");
this.compilation = compilation;
this.arguments = arguments;
this.argumentNames = argumentNames;
// keep explicitlyGivenTypeArguments==null when no type arguments were specified
if (typeArguments != null && typeArguments.Length > 0)
this.explicitlyGivenTypeArguments = typeArguments;
this.conversions = conversions ?? CSharpConversions.Get(compilation);
this.AllowExpandingParams = true;
this.AllowOptionalParameters = true;
}
示例7: IsValid
public override Conversion IsValid(IType[] parameterTypes, IType returnType, CSharpConversions conversions)
{
return conversions.ImplicitConversion(inferredReturnType, returnType);
}
示例8: IsValid
/// <summary>
/// Gets whether the lambda body is valid for the given parameter types and return type.
/// </summary>
/// <returns>
/// Produces a conversion with <see cref="Conversion.IsAnonymousFunctionConversion"/>=<c>true</c> if the lambda is valid;
/// otherwise returns <see cref="Conversion.None"/>.
/// </returns>
public abstract Conversion IsValid(IType[] parameterTypes, IType returnType, CSharpConversions conversions);
示例9: SetUp
public override void SetUp()
{
base.SetUp();
conversions = new CSharpConversions(compilation);
}
示例10: IsEligibleExtensionMethod
static bool IsEligibleExtensionMethod(ICompilation compilation, CSharpConversions conversions, IType targetType, IMethod method, bool useTypeInference, out IType[] outInferredTypes)
{
outInferredTypes = null;
if (targetType == null)
return true;
if (method.Parameters.Count == 0)
return false;
IType thisParameterType = method.Parameters[0].Type;
if (useTypeInference && method.TypeParameters.Count > 0) {
// We need to infer type arguments from targetType:
TypeInference ti = new TypeInference(compilation, conversions);
ResolveResult[] arguments = { new ResolveResult(targetType) };
IType[] parameterTypes = { method.Parameters[0].Type };
bool success;
var inferredTypes = ti.InferTypeArguments(method.TypeParameters, arguments, parameterTypes, out success);
var substitution = new TypeParameterSubstitution(null, inferredTypes);
// Validate that the types that could be inferred (aren't unknown) satisfy the constraints:
bool hasInferredTypes = false;
for (int i = 0; i < inferredTypes.Length; i++) {
if (inferredTypes[i].Kind != TypeKind.Unknown && inferredTypes[i].Kind != TypeKind.UnboundTypeArgument) {
hasInferredTypes = true;
if (!OverloadResolution.ValidateConstraints(method.TypeParameters[i], inferredTypes[i], substitution, conversions))
return false;
} else {
inferredTypes[i] = method.TypeParameters[i]; // do not substitute types that could not be inferred
}
}
if (hasInferredTypes)
outInferredTypes = inferredTypes;
thisParameterType = thisParameterType.AcceptVisitor(substitution);
}
Conversion c = conversions.ImplicitConversion(targetType, thisParameterType);
return c.IsValid && (c.IsIdentityConversion || c.IsReferenceConversion || c.IsBoxingConversion);
}
示例11: ValidateConstraints
internal static bool ValidateConstraints(ITypeParameter typeParameter, IType typeArgument, TypeVisitor substitution, CSharpConversions conversions)
{
switch (typeArgument.Kind) { // void, null, and pointers cannot be used as type arguments
case TypeKind.Void:
case TypeKind.Null:
case TypeKind.Pointer:
return false;
}
if (typeParameter.HasReferenceTypeConstraint) {
if (typeArgument.IsReferenceType != true)
return false;
}
if (typeParameter.HasValueTypeConstraint) {
if (!NullableType.IsNonNullableValueType(typeArgument))
return false;
}
if (typeParameter.HasDefaultConstructorConstraint) {
ITypeDefinition def = typeArgument.GetDefinition();
if (def != null && def.IsAbstract)
return false;
var ctors = typeArgument.GetConstructors(
m => m.Parameters.Count == 0 && m.Accessibility == Accessibility.Public,
GetMemberOptions.IgnoreInheritedMembers | GetMemberOptions.ReturnMemberDefinitions
);
if (!ctors.Any())
return false;
}
foreach (IType constraintType in typeParameter.DirectBaseTypes) {
IType c = constraintType;
if (substitution != null)
c = c.AcceptVisitor(substitution);
if (!conversions.IsConstraintConvertible(typeArgument, c))
return false;
}
return true;
}
示例12: IsValid
public override Conversion IsValid(IType[] parameterTypes, IType returnType, CSharpConversions conversions)
{
Assert.AreEqual(expectedParameterTypes, parameterTypes);
return conversions.ImplicitConversion(inferredReturnType, returnType);
}
示例13: GatherVisitor
public GatherVisitor (BaseRefactoringContext ctx)
: base (ctx)
{
conversions = CSharpConversions.Get(ctx.Compilation);
}
示例14: SetUp
public void SetUp()
{
compilation = new SimpleCompilation(CecilLoaderTests.Mscorlib);
conversions = new CSharpConversions(compilation);
}
示例15: ConstraintValidatingSubstitution
public ConstraintValidatingSubstitution(IList<IType> classTypeArguments, IList<IType> methodTypeArguments, OverloadResolution overloadResolution)
: base(classTypeArguments, methodTypeArguments)
{
this.conversions = overloadResolution.conversions;
}