|
|
|
@ -443,7 +443,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
@@ -443,7 +443,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
|
|
|
|
|
throw new InvalidOperationException(); |
|
|
|
|
} |
|
|
|
|
OverloadResolution r = new OverloadResolution(context, new[] { expression }); |
|
|
|
|
foreach (var candidate in methodGroup) { |
|
|
|
|
foreach (var candidate in methodGroup.Concat(GetUserDefinedUnaryOperatorCandidates (type, GetOverloadableOperatorName(op)))) { |
|
|
|
|
r.AddCandidate(candidate); |
|
|
|
|
} |
|
|
|
|
UnaryOperatorMethod m = (UnaryOperatorMethod)r.BestCandidate; |
|
|
|
@ -570,6 +570,21 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
@@ -570,6 +570,21 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
|
|
|
|
|
get { return baseMethod.Parameters; } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sealed class UserDefinedUnaryOperatorMethod : UnaryOperatorMethod |
|
|
|
|
{ |
|
|
|
|
public UserDefinedUnaryOperatorMethod (IMethod baseOperator) |
|
|
|
|
{ |
|
|
|
|
foreach (var p in baseOperator.Parameters) |
|
|
|
|
Parameters.Add (p); |
|
|
|
|
ReturnType = baseOperator.ReturnType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override object Invoke(CSharpResolver resolver, object input) |
|
|
|
|
{ |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Unary operator definitions
|
|
|
|
@ -612,13 +627,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
@@ -612,13 +627,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
|
|
|
|
|
); |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
object GetUserUnaryOperatorCandidates() |
|
|
|
|
|
|
|
|
|
#region User defined unary operators
|
|
|
|
|
IEnumerable<OperatorMethod> GetUserDefinedUnaryOperatorCandidates (IType type, string operatorName) |
|
|
|
|
{ |
|
|
|
|
// C# 4.0 spec: §7.3.5 Candidate user-defined operators
|
|
|
|
|
// TODO: implement user-defined operators
|
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
Predicate<IMethod> filter = m => m.IsOperator && m.Name == operatorName; |
|
|
|
|
return type.GetMethods (context, filter).Select (op => new UserDefinedUnaryOperatorMethod (op)); |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ResolveBinaryOperator
|
|
|
|
|
#region ResolveBinaryOperator method
|
|
|
|
@ -825,7 +843,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
@@ -825,7 +843,7 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
|
|
|
|
|
throw new InvalidOperationException(); |
|
|
|
|
} |
|
|
|
|
OverloadResolution r = new OverloadResolution(context, new[] { lhs, rhs }); |
|
|
|
|
foreach (var candidate in methodGroup) { |
|
|
|
|
foreach (var candidate in methodGroup.Concat (GetUserDefinedBinaryOperatorCandidates (lhsType, rhsType, GetOverloadableOperatorName (op)))) { |
|
|
|
|
r.AddCandidate(candidate); |
|
|
|
|
} |
|
|
|
|
BinaryOperatorMethod m = (BinaryOperatorMethod)r.BestCandidate; |
|
|
|
@ -1103,6 +1121,27 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
@@ -1103,6 +1121,27 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
|
|
|
|
|
get { return baseMethod.Parameters; } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sealed class UserDefinedBinaryOperatorMethod : BinaryOperatorMethod |
|
|
|
|
{ |
|
|
|
|
public override bool CanEvaluateAtCompileTime { |
|
|
|
|
get { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public UserDefinedBinaryOperatorMethod (IMethod baseOperator) |
|
|
|
|
{ |
|
|
|
|
foreach (var p in baseOperator.Parameters) |
|
|
|
|
Parameters.Add (p); |
|
|
|
|
ReturnType = baseOperator.ReturnType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override object Invoke(CSharpResolver resolver, object lhs, object rhs) |
|
|
|
|
{ |
|
|
|
|
throw new NotSupportedException("Operator can't be evaluated."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Arithmetic operators
|
|
|
|
@ -1458,11 +1497,14 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
@@ -1458,11 +1497,14 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
|
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
object GetUserBinaryOperatorCandidates() |
|
|
|
|
IEnumerable<OperatorMethod> GetUserDefinedBinaryOperatorCandidates (IType lhsType, IType rhsType, string operatorName) |
|
|
|
|
{ |
|
|
|
|
// C# 4.0 spec: §7.3.5 Candidate user-defined operators
|
|
|
|
|
// TODO: implement user-defined operators
|
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
Predicate<IMethod> filter = m => m.IsOperator && m.Name == operatorName; |
|
|
|
|
var operators = lhsType.GetMethods (context, filter); |
|
|
|
|
if (!lhsType.Equals (rhsType)) |
|
|
|
|
operators = operators.Concat (rhsType.GetMethods (context, filter)); |
|
|
|
|
return operators.Select (op => new UserDefinedBinaryOperatorMethod (op)); |
|
|
|
|
} |
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|