Browse Source

Moved code to the Value class:

- Value.GetFieldValue
 - Value.GetPropertyValue
 - Value.SetPropertyValue
 - Value.InvokeMethod
 - Value.AsyncInvokeMethod

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2769 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 18 years ago
parent
commit
9a645660c7
  1. 44
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/FieldInfo.cs
  2. 24
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/MethodInfo.cs
  3. 62
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/PropertyInfo.cs
  4. 170
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/Value.Object.cs

44
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/FieldInfo.cs

@ -68,49 +68,5 @@ namespace Debugger @@ -68,49 +68,5 @@ namespace Debugger
{
this.fieldProps = fieldProps;
}
/// <summary>
/// Given an object of correct type, get the value of this field
/// </summary>
public Value GetValue(Value objectInstance) {
return new Value(
this.Process,
this.Name,
new Ast.FieldReferenceExpression(
new Ast.IdentifierExpression("parent"), // TODO
this
),
new IExpirable[] {objectInstance},
new IMutable[] {objectInstance},
delegate { return GetCorValue(objectInstance); }
);
}
ICorDebugValue GetCorValue(Value objectInstance)
{
if (!DeclaringType.IsInstanceOfType(objectInstance)) {
throw new CannotGetValueException("Object is not of type " + DeclaringType.FullName);
}
// Current frame is used to resolve context specific static values (eg. ThreadStatic)
ICorDebugFrame curFrame = null;
if (this.Process.IsPaused &&
this.Process.SelectedThread != null &&
this.Process.SelectedThread.LastFunction != null &&
this.Process.SelectedThread.LastFunction.CorILFrame != null) {
curFrame = this.Process.SelectedThread.LastFunction.CorILFrame.CastTo<ICorDebugFrame>();
}
try {
if (this.IsStatic) {
return DeclaringType.CorType.GetStaticFieldValue(MetadataToken, curFrame);
} else {
return objectInstance.CorObjectValue.GetFieldValue(DeclaringType.CorType.Class, MetadataToken);
}
} catch {
throw new CannotGetValueException("Can not get value of field");
}
}
}
}

24
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/MethodInfo.cs

@ -99,29 +99,5 @@ namespace Debugger @@ -99,29 +99,5 @@ namespace Debugger
}
throw new DebuggerException("Not found");
}
/// <summary>
/// Synchronously invoke the method of an a given object
/// </summary>
public Value Invoke(Value objectInstance, Value[] arguments)
{
return Eval.InvokeMethod(
this,
this.IsStatic ? null : objectInstance,
arguments ?? new Value[0]
);
}
/// <summary>
/// Asynchronously invoke the method of an a given object
/// </summary>
public Eval AsyncInvoke(Value objectInstance, Value[] arguments)
{
return Eval.AsyncInvokeMethod(
this,
this.IsStatic ? null : objectInstance,
arguments ?? new Value[0]
);
}
}
}

62
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Types/PropertyInfo.cs

@ -68,63 +68,17 @@ namespace Debugger @@ -68,63 +68,17 @@ namespace Debugger
}
/// <summary> Get the get accessor of the property </summary>
public MethodInfo GetGetMethod()
{
return getMethod;
public MethodInfo GetMethod {
get {
return getMethod;
}
}
/// <summary> Get the set accessor of the property </summary>
public MethodInfo GetSetMethod()
{
return setMethod;
}
/// <summary> Get the value of the property using the get accessor </summary>
public Value GetValue(Value objectInstance)
{
return GetValue(objectInstance, null);
}
/// <summary> Get the value of indexer property </summary>
public Value GetValue(Value objectInstance, Value[] parameters)
{
if (getMethod == null) throw new CannotGetValueException("Property does not have a get method");
parameters = parameters ?? new Value[0];
List<Value> dependencies = new List<Value>();
dependencies.Add(objectInstance);
dependencies.AddRange(parameters);
return new Value(
this.Process,
this.Name,
new Ast.PropertyReferenceExpression(
new Ast.IdentifierExpression("parent"), // TODO
this
),
dependencies.ToArray(),
dependencies.ToArray(),
delegate { return getMethod.Invoke(objectInstance, parameters).RawCorValue; }
);
}
/// <summary> Set the value of the property using the set accessor </summary>
public Value SetValue(Value objectInstance, Value newValue)
{
return SetValue(objectInstance, newValue, null);
}
/// <summary> Set the value of indexer property </summary>
public Value SetValue(Value objectInstance, Value newValue, Value[] parameters)
{
if (setMethod == null) throw new CannotGetValueException("Property does not have a set method");
parameters = parameters ?? new Value[0];
Value[] allParams = new Value[1 + parameters.Length];
allParams[0] = newValue;
parameters.CopyTo(allParams, 1);
return setMethod.Invoke(objectInstance, allParams);
public MethodInfo SetMethod {
get {
return setMethod;
}
}
}
}

170
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/Value.Object.cs

@ -9,6 +9,8 @@ using System; @@ -9,6 +9,8 @@ using System;
using System.Collections.Generic;
using Debugger.Wrappers.CorDebug;
using Ast = ICSharpCode.NRefactory.Ast;
namespace Debugger
{
// This part of the class provides support for classes and structures
@ -31,6 +33,166 @@ namespace Debugger @@ -31,6 +33,166 @@ namespace Debugger
}
}
/// <summary>
/// Get the value of given field.
/// Field may be static
/// </summary>
public Value GetFieldValue(FieldInfo fieldInfo)
{
return Value.GetFieldValue(this, fieldInfo);
}
/// <summary>
/// Get the value of given field.
/// objectInstance must not be null.
/// Field may be static
/// </summary>
public static Value GetFieldValue(Value objectInstance, FieldInfo fieldInfo)
{
return new Value(
objectInstance.Process,
fieldInfo.Name,
new Ast.FieldReferenceExpression(
new Ast.IdentifierExpression("parent"), // TODO
fieldInfo
),
new IExpirable[] {objectInstance},
new IMutable[] {objectInstance},
delegate { return GetFieldCorValue(objectInstance, fieldInfo); }
);
}
static ICorDebugValue GetFieldCorValue(Value objectInstance, FieldInfo fieldInfo)
{
if (!fieldInfo.DeclaringType.IsInstanceOfType(objectInstance)) {
throw new CannotGetValueException("Object is not of type " + fieldInfo.DeclaringType.FullName);
}
// Current frame is used to resolve context specific static values (eg. ThreadStatic)
ICorDebugFrame curFrame = null;
if (objectInstance.Process.IsPaused &&
objectInstance.Process.SelectedThread != null &&
objectInstance.Process.SelectedThread.LastFunction != null &&
objectInstance.Process.SelectedThread.LastFunction.CorILFrame != null) {
curFrame = objectInstance.Process.SelectedThread.LastFunction.CorILFrame.CastTo<ICorDebugFrame>();
}
try {
if (fieldInfo.IsStatic) {
return fieldInfo.DeclaringType.CorType.GetStaticFieldValue(fieldInfo.MetadataToken, curFrame);
} else {
return objectInstance.CorObjectValue.GetFieldValue(fieldInfo.DeclaringType.CorType.Class, fieldInfo.MetadataToken);
}
} catch {
throw new CannotGetValueException("Can not get value of field");
}
}
/// <summary> Get the value of the property using the get accessor </summary>
public Value GetPropertyValue(PropertyInfo propertyInfo)
{
return GetPropertyValue(this, propertyInfo, null);
}
/// <summary> Get the value of the property using the get accessor </summary>
public Value GetPropertyValue(PropertyInfo propertyInfo, Value[] arguments)
{
return GetPropertyValue(this, propertyInfo, arguments);
}
/// <summary> Get the value of the property using the get accessor </summary>
public static Value GetPropertyValue(Value objectInstance, PropertyInfo propertyInfo)
{
return GetPropertyValue(objectInstance, propertyInfo, null);
}
/// <summary> Get the value of the property using the get accessor </summary>
public static Value GetPropertyValue(Value objectInstance, PropertyInfo propertyInfo, Value[] arguments)
{
if (propertyInfo.GetMethod == null) throw new CannotGetValueException("Property does not have a get method");
arguments = arguments ?? new Value[0];
List<Value> dependencies = new List<Value>();
dependencies.Add(objectInstance);
dependencies.AddRange(arguments);
return new Value(
objectInstance.Process,
propertyInfo.Name,
new Ast.PropertyReferenceExpression(
new Ast.IdentifierExpression("parent"), // TODO
propertyInfo
),
dependencies.ToArray(),
dependencies.ToArray(),
delegate { return Value.InvokeMethod(objectInstance, propertyInfo.GetMethod, arguments).RawCorValue; }
);
}
/// <summary> Set the value of the property using the set accessor </summary>
public Value SetPropertyValue(PropertyInfo propertyInfo, Value newValue)
{
return SetPropertyValue(this, propertyInfo, null, newValue);
}
/// <summary> Set the value of the property using the set accessor </summary>
public Value SetPropertyValue(PropertyInfo propertyInfo, Value[] arguments, Value newValue)
{
return SetPropertyValue(this, propertyInfo, arguments, newValue);
}
/// <summary> Set the value of the property using the set accessor </summary>
public static Value SetPropertyValue(Value objectInstance, PropertyInfo propertyInfo, Value newValue)
{
return SetPropertyValue(objectInstance, propertyInfo, null, newValue);
}
/// <summary> Set the value of the property using the set accessor </summary>
public static Value SetPropertyValue(Value objectInstance, PropertyInfo propertyInfo, Value[] arguments, Value newValue)
{
if (propertyInfo.SetMethod == null) throw new CannotGetValueException("Property does not have a set method");
arguments = arguments ?? new Value[0];
Value[] allParams = new Value[1 + arguments.Length];
allParams[0] = newValue;
arguments.CopyTo(allParams, 1);
return Value.InvokeMethod(objectInstance, propertyInfo.SetMethod, allParams);
}
/// <summary> Synchronously invoke the method </summary>
public Value InvokeMethod(MethodInfo methodInfo, params Value[] arguments)
{
return InvokeMethod(this, methodInfo, arguments);
}
/// <summary> Synchronously invoke the method </summary>
public static Value InvokeMethod(Value objectInstance, MethodInfo methodInfo, params Value[] arguments)
{
return Eval.InvokeMethod(
methodInfo,
methodInfo.IsStatic ? null : objectInstance,
arguments ?? new Value[0]
);
}
/// <summary> Asynchronously invoke the method </summary>
public Eval AsyncInvokeMethod(MethodInfo methodInfo, params Value[] arguments)
{
return AsyncInvokeMethod(this, methodInfo, arguments);
}
/// <summary> Asynchronously invoke the method </summary>
public static Eval AsyncInvokeMethod(Value objectInstance, MethodInfo methodInfo, params Value[] arguments)
{
return Eval.AsyncInvokeMethod(
methodInfo,
methodInfo.IsStatic ? null : objectInstance,
arguments ?? new Value[0]
);
}
/// <summary>
/// Get a field or property of an object with a given name.
/// </summary>
@ -40,10 +202,10 @@ namespace Debugger @@ -40,10 +202,10 @@ namespace Debugger
while (currentType != null) {
foreach(MemberInfo memberInfo in currentType.GetMember(name, BindingFlags.All)) {
if (memberInfo is FieldInfo) {
return ((FieldInfo)memberInfo).GetValue(this);
return this.GetFieldValue((FieldInfo)memberInfo);
}
if (memberInfo is PropertyInfo) {
return ((PropertyInfo)memberInfo).GetValue(this);
return this.GetPropertyValue((PropertyInfo)memberInfo);
}
}
currentType = currentType.BaseType;
@ -78,10 +240,10 @@ namespace Debugger @@ -78,10 +240,10 @@ namespace Debugger
DebugType currentType = type ?? this.Type;
while (currentType != null) {
foreach(FieldInfo field in currentType.GetFields(bindingFlags)) {
yield return field.GetValue(this);
yield return this.GetFieldValue(field);
}
foreach(PropertyInfo property in currentType.GetProperties(bindingFlags)) {
yield return property.GetValue(this);
yield return this.GetPropertyValue(property);
}
if (type == null) {
currentType = currentType.BaseType;

Loading…
Cancel
Save