* Makefile.am:
[monodevelop.git] / extras / MonoDevelop.Debugger.Mdb / Mono.Debugging.Server.Mdb / IndexerValueReference.cs
blobe944752e12f99f31510a7c43ca08250ebc08c0b3
1 // IndexerValueReference.cs
2 //
3 // Author:
4 // Lluis Sanchez Gual <lluis@novell.com>
5 //
6 // Copyright (c) 2008 Novell, Inc (http://www.novell.com)
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 // THE SOFTWARE.
28 using System;
29 using Mono.Debugger;
30 using Mono.Debugger.Languages;
31 using Mono.Debugging.Client;
32 using System.Collections.Generic;
34 namespace DebuggerServer
36 public class IndexerValueReference: ValueReference
38 TargetPropertyInfo indexer;
39 TargetStructObject target;
40 TargetObject index;
42 public IndexerValueReference (EvaluationContext ctx, TargetStructObject target, TargetObject index, TargetPropertyInfo indexerProp): base (ctx)
44 this.indexer = indexerProp;
45 this.target = target;
46 this.index = index;
49 public static IndexerValueReference CreateIndexerValueReference (EvaluationContext ctx, TargetObject target, TargetObject index)
51 TargetStructObject sob = target as TargetStructObject;
52 if (sob == null)
53 return null;
55 TargetPropertyInfo indexerProp = null;
56 foreach (MemberReference mem in ObjectUtil.GetTypeMembers (ctx, target.Type, false, false, true, true, ReqMemberAccess.All)) {
57 if (mem.Member.IsStatic)
58 continue;
59 if (mem.Member is TargetPropertyInfo) {
60 TargetPropertyInfo prop = (TargetPropertyInfo) mem.Member;
61 if (prop.CanRead && prop.Getter.ParameterTypes.Length == 1) {
62 indexerProp = prop;
63 break;
67 if (indexerProp != null)
68 return new IndexerValueReference (ctx, sob, index, indexerProp);
69 else
70 return null;
73 public override TargetObject Value {
74 get {
75 return ObjectUtil.GetRealObject (Context, Server.Instance.RuntimeInvoke (Context, indexer.Getter, target, new TargetObject [] {index}));
77 set {
78 TargetObject cindex = TargetObjectConvert.Cast (Context, index, indexer.Setter.ParameterTypes [0]);
79 TargetObject cvalue = TargetObjectConvert.Cast (Context, value, indexer.Setter.ParameterTypes [1]);
80 Server.Instance.RuntimeInvoke (Context, indexer.Setter, target, new TargetObject [] {cindex, cvalue});
85 public override Mono.Debugger.Languages.TargetType Type {
86 get {
87 if (indexer.CanRead)
88 return indexer.Getter.ReturnType;
89 else
90 return indexer.Setter.ParameterTypes [1];
95 public override string Name {
96 get {
97 return "[" + Server.Instance.Evaluator.TargetObjectToExpression (Context, index) + "]";
102 public override ObjectValueFlags Flags {
103 get {
104 if (!indexer.CanWrite)
105 return ObjectValueFlags.ArrayElement | ObjectValueFlags.ReadOnly;
106 else
107 return ObjectValueFlags.ArrayElement;