本文整理汇总了C#中CSharpConversions.ImplicitConversion方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpConversions.ImplicitConversion方法的具体用法?C# CSharpConversions.ImplicitConversion怎么用?C# CSharpConversions.ImplicitConversion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSharpConversions
的用法示例。
在下文中一共展示了CSharpConversions.ImplicitConversion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsValid
public override Conversion IsValid(IType[] parameterTypes, IType returnType, CSharpConversions conversions)
{
return conversions.ImplicitConversion(inferredReturnType, returnType);
}
示例2: IsValid
public override Conversion IsValid(IType[] parameterTypes, IType returnType, CSharpConversions conversions)
{
Assert.AreEqual(expectedParameterTypes, parameterTypes);
return conversions.ImplicitConversion(inferredReturnType, returnType);
}
示例3: 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);
}