-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IObjectValueSource.SetValue now throws ValueModificationException if …
…modification is failed instead of supressing the exception. This allows to show the error info to user at the call site (e.g. in message box). ValueReference.SetValue() and ArrayElementGroup.SetValue() implementations unified and moved to ValueModificationUtil. (cherry picked from commit 316b7cc)
- Loading branch information
1 parent
e1f7852
commit da12417
Showing
6 changed files
with
231 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Mono.Debugging/Mono.Debugging.Evaluation/ValueModificationException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace Mono.Debugging.Evaluation | ||
{ | ||
public class ValueModificationException : Exception | ||
{ | ||
public ValueModificationException () | ||
{ | ||
} | ||
|
||
public ValueModificationException (string message) : base (message) | ||
{ | ||
} | ||
|
||
public ValueModificationException (string message, Exception innerException) : base (message, innerException) | ||
{ | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Mono.Debugging/Mono.Debugging.Evaluation/ValueModificationUtil.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using Mono.Debugging.Backend; | ||
|
||
namespace Mono.Debugging.Evaluation | ||
{ | ||
public static class ValueModificationUtil | ||
{ | ||
internal static ValueReference EvaluateRightHandValue (EvaluationContext context, string value, object expectedType) | ||
{ | ||
context.Options.AllowMethodEvaluation = true; | ||
context.Options.AllowTargetInvoke = true; | ||
try { | ||
return context.Evaluator.Evaluate (context, value, expectedType); | ||
} catch (Exception e) { | ||
throw new ValueModificationException(string.Format ("Cannot evaluate '{0}': {1}", value, e.Message), e); | ||
} | ||
} | ||
|
||
internal static object ConvertRightHandValue (EvaluationContext context, object value, object expectedType) | ||
{ | ||
try { | ||
return context.Adapter.Convert (context, value, expectedType); | ||
} catch (Exception e) { | ||
throw new ValueModificationException(string.Format ("Conversion error: {0}", e.Message), e); | ||
} | ||
} | ||
|
||
internal static EvaluationResult ModifyValue (EvaluationContext context, string value, object expectedType, Action<object> valueSetter) | ||
{ | ||
var rightHandValue = EvaluateRightHandValue (context, value, expectedType); | ||
|
||
object val; | ||
try { | ||
val = rightHandValue.Value; | ||
} catch (Exception e) { | ||
throw new ValueModificationException(string.Format ("Cannot get real object of {0}", value), e); | ||
} | ||
var convertedValue = ConvertRightHandValue (context, val, expectedType); | ||
try { | ||
valueSetter (convertedValue); | ||
} catch (Exception e) { | ||
throw new ValueModificationException(string.Format ("Error while assigning new value to object: {0}", e.Message), e); | ||
} | ||
// don't wrap with try-catch it, this call normally should not throw exceptions produced by wrong user input. | ||
// If exception was occured this means something has gone wrong in we have to report it in log | ||
return context.Evaluator.TargetObjectToExpression (context, convertedValue); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.