本文整理汇总了C#中Candidate.AddError方法的典型用法代码示例。如果您正苦于以下问题:C# Candidate.AddError方法的具体用法?C# Candidate.AddError怎么用?C# Candidate.AddError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Candidate
的用法示例。
在下文中一共展示了Candidate.AddError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunTypeInference
void RunTypeInference(Candidate candidate)
{
IMethod method = candidate.Member as IMethod;
if (method == null || method.TypeParameters.Count == 0) {
if (explicitlyGivenTypeArguments != null) {
// method does not expect type arguments, but was given some
candidate.AddError(OverloadResolutionErrors.WrongNumberOfTypeArguments);
}
return;
}
ParameterizedType parameterizedDeclaringType = candidate.Member.DeclaringType as ParameterizedType;
IList<IType> classTypeArguments;
if (parameterizedDeclaringType != null) {
classTypeArguments = parameterizedDeclaringType.TypeArguments;
} else {
classTypeArguments = null;
}
// The method is generic:
if (explicitlyGivenTypeArguments != null) {
if (explicitlyGivenTypeArguments.Length == method.TypeParameters.Count) {
candidate.InferredTypes = explicitlyGivenTypeArguments;
} else {
candidate.AddError(OverloadResolutionErrors.WrongNumberOfTypeArguments);
// wrong number of type arguments given, so truncate the list or pad with UnknownType
candidate.InferredTypes = new IType[method.TypeParameters.Count];
for (int i = 0; i < candidate.InferredTypes.Length; i++) {
if (i < explicitlyGivenTypeArguments.Length)
candidate.InferredTypes[i] = explicitlyGivenTypeArguments[i];
else
candidate.InferredTypes[i] = SpecialType.UnknownType;
}
}
} else {
TypeInference ti = new TypeInference(compilation, conversions);
bool success;
candidate.InferredTypes = ti.InferTypeArguments(candidate.TypeParameters, arguments, candidate.ParameterTypes, out success, classTypeArguments);
if (!success)
candidate.AddError(OverloadResolutionErrors.TypeInferenceFailed);
}
// Now substitute in the formal parameters:
var substitution = new ConstraintValidatingSubstitution(classTypeArguments, candidate.InferredTypes, this);
for (int i = 0; i < candidate.ParameterTypes.Length; i++) {
candidate.ParameterTypes[i] = candidate.ParameterTypes[i].AcceptVisitor(substitution);
}
if (!substitution.ConstraintsValid)
candidate.AddError(OverloadResolutionErrors.ConstructedTypeDoesNotSatisfyConstraint);
}
示例2: CheckApplicability
void CheckApplicability(Candidate candidate)
{
// C# 4.0 spec: §7.5.3.1 Applicable function member
// Test whether parameters were mapped the correct number of arguments:
int[] argumentCountPerParameter = new int[candidate.ParameterTypes.Length];
foreach (int parameterIndex in candidate.ArgumentToParameterMap) {
if (parameterIndex >= 0)
argumentCountPerParameter[parameterIndex]++;
}
for (int i = 0; i < argumentCountPerParameter.Length; i++) {
if (candidate.IsExpandedForm && i == argumentCountPerParameter.Length - 1)
continue; // any number of arguments is fine for the params-array
if (argumentCountPerParameter[i] == 0) {
if (candidate.Parameters[i].IsOptional)
candidate.HasUnmappedOptionalParameters = true;
else
candidate.AddError(OverloadResolutionErrors.MissingArgumentForRequiredParameter);
} else if (argumentCountPerParameter[i] > 1) {
candidate.AddError(OverloadResolutionErrors.MultipleArgumentsForSingleParameter);
}
}
candidate.ArgumentConversions = new Conversion[arguments.Length];
// Test whether argument passing mode matches the parameter passing mode
for (int i = 0; i < arguments.Length; i++) {
int parameterIndex = candidate.ArgumentToParameterMap[i];
if (parameterIndex < 0) continue;
ByReferenceResolveResult brrr = arguments[i] as ByReferenceResolveResult;
if (brrr != null) {
if ((brrr.IsOut && !candidate.Parameters[parameterIndex].IsOut) || (brrr.IsRef && !candidate.Parameters[parameterIndex].IsRef))
candidate.AddError(OverloadResolutionErrors.ParameterPassingModeMismatch);
} else {
if (candidate.Parameters[parameterIndex].IsOut || candidate.Parameters[parameterIndex].IsRef)
candidate.AddError(OverloadResolutionErrors.ParameterPassingModeMismatch);
}
IType parameterType = candidate.ParameterTypes[parameterIndex];
Conversion c = conversions.ImplicitConversion(arguments[i], parameterType);
candidate.ArgumentConversions[i] = c;
if (IsExtensionMethodInvocation && parameterIndex == 0) {
// First parameter to extension method must be an identity, reference or boxing conversion
if (!(c == Conversion.IdentityConversion || c == Conversion.ImplicitReferenceConversion || c == Conversion.BoxingConversion))
candidate.AddError(OverloadResolutionErrors.ArgumentTypeMismatch);
} else {
if (!c.IsValid)
candidate.AddError(OverloadResolutionErrors.ArgumentTypeMismatch);
}
}
}
示例3: MapCorrespondingParameters
void MapCorrespondingParameters(Candidate candidate)
{
// C# 4.0 spec: §7.5.1.1 Corresponding parameters
candidate.ArgumentToParameterMap = new int[arguments.Length];
for (int i = 0; i < arguments.Length; i++) {
candidate.ArgumentToParameterMap[i] = -1;
if (argumentNames[i] == null) {
// positional argument
if (i < candidate.ParameterTypes.Length) {
candidate.ArgumentToParameterMap[i] = i;
} else if (candidate.IsExpandedForm) {
candidate.ArgumentToParameterMap[i] = candidate.ParameterTypes.Length - 1;
} else {
candidate.AddError(OverloadResolutionErrors.TooManyPositionalArguments);
}
} else {
// named argument
for (int j = 0; j < candidate.Parameters.Count; j++) {
if (argumentNames[i] == candidate.Parameters[j].Name) {
candidate.ArgumentToParameterMap[i] = j;
}
}
if (candidate.ArgumentToParameterMap[i] < 0)
candidate.AddError(OverloadResolutionErrors.NoParameterFoundForNamedArgument);
}
}
}
示例4: AddCandidate
public OverloadResolutionErrors AddCandidate(IParameterizedMember member, OverloadResolutionErrors additionalErrors)
{
if (member == null)
throw new ArgumentNullException("member");
Candidate c = new Candidate(member, false);
if (additionalErrors != OverloadResolutionErrors.None)
c.AddError(additionalErrors);
if (CalculateCandidate(c)) {
//candidates.Add(c);
}
if (this.AllowExpandingParams && member.Parameters.Count > 0
&& member.Parameters[member.Parameters.Count - 1].IsParams)
{
Candidate expandedCandidate = new Candidate(member, true);
if (additionalErrors != OverloadResolutionErrors.None)
expandedCandidate.AddError(additionalErrors);
// consider expanded form only if it isn't obviously wrong
if (CalculateCandidate(expandedCandidate)) {
//candidates.Add(expandedCandidate);
if (expandedCandidate.ErrorCount < c.ErrorCount)
return expandedCandidate.Errors;
}
}
return c.Errors;
}
示例5: CheckApplicability
void CheckApplicability(Candidate candidate)
{
// C# 4.0 spec: §7.5.3.1 Applicable function member
// Test whether parameters were mapped the correct number of arguments:
int[] argumentCountPerParameter = new int[candidate.ParameterTypes.Length];
foreach (int parameterIndex in candidate.ArgumentToParameterMap) {
if (parameterIndex >= 0)
argumentCountPerParameter[parameterIndex]++;
}
for (int i = 0; i < argumentCountPerParameter.Length; i++) {
if (candidate.IsExpandedForm && i == argumentCountPerParameter.Length - 1)
continue; // any number of arguments is fine for the params-array
if (argumentCountPerParameter[i] == 0) {
if (candidate.Parameters[i].IsOptional)
candidate.HasUnmappedOptionalParameters = true;
else
candidate.AddError(OverloadResolutionErrors.MissingArgumentForRequiredParameter);
} else if (argumentCountPerParameter[i] > 1) {
candidate.AddError(OverloadResolutionErrors.MultipleArgumentsForSingleParameter);
}
}
// Test whether argument passing mode matches the parameter passing mode
for (int i = 0; i < arguments.Length; i++) {
int parameterIndex = candidate.ArgumentToParameterMap[i];
if (parameterIndex < 0) continue;
ByReferenceResolveResult brrr = arguments[i] as ByReferenceResolveResult;
if (brrr != null) {
if ((brrr.IsOut && !candidate.Parameters[parameterIndex].IsOut) || (brrr.IsRef && !candidate.Parameters[parameterIndex].IsRef))
candidate.AddError(OverloadResolutionErrors.ParameterPassingModeMismatch);
} else {
if (candidate.Parameters[parameterIndex].IsOut || candidate.Parameters[parameterIndex].IsRef)
candidate.AddError(OverloadResolutionErrors.ParameterPassingModeMismatch);
}
if (!conversions.ImplicitConversion(arguments[i], candidate.ParameterTypes[parameterIndex]))
candidate.AddError(OverloadResolutionErrors.ArgumentTypeMismatch);
}
}
示例6: MapCorrespondingParameters
void MapCorrespondingParameters(Candidate candidate)
{
candidate.ArgumentToParameterMap = new int[arguments.Length];
for(int i = 0; i < arguments.Length; ++i){
candidate.ArgumentToParameterMap[i] = -1;
// positional argument
if(i < candidate.ParameterTypes.Length)
candidate.ArgumentToParameterMap[i] = i;
else if(candidate.IsExpandedForm)
candidate.ArgumentToParameterMap[i] = candidate.ParameterTypes.Length - 1;
else
candidate.AddError(OverloadResolutionErrors.TooManyPositionalArguments);
}
}
示例7: CheckApplicability
void CheckApplicability(Candidate candidate)
{
// C# 4.0 spec: §7.5.3.1 Applicable function member
// Test whether parameters were mapped the correct number of arguments:
int[] argument_count_per_parameter = new int[candidate.ParameterTypes.Length];
foreach(int parameter_index in candidate.ArgumentToParameterMap){
if(parameter_index >= 0)
argument_count_per_parameter[parameter_index]++;
}
for(int i = 0; i < argument_count_per_parameter.Length; ++i){
if(candidate.IsExpandedForm && i == argument_count_per_parameter.Length - 1)
continue; // any number of arguments is fine for the params-array
if(argument_count_per_parameter[i] == 0)
candidate.AddError(OverloadResolutionErrors.MissingArgumentForRequiredParameter);
else if(argument_count_per_parameter[i] > 1)
candidate.AddError(OverloadResolutionErrors.MultipleArgumentsForSingleParameter);
}
// Test whether types of arguments match that of parameters
for(int i = 0; i < arguments.Length; ++i){
int parameterIndex = candidate.ArgumentToParameterMap[i];
IType parameter_type = candidate.ParameterTypes[parameterIndex];
if(!MatchType(arguments[i], parameter_type))
candidate.AddError(OverloadResolutionErrors.ArgumentTypeMismatch);
}
}