1 // IndexerValueReference.cs
4 // Lluis Sanchez Gual <lluis@novell.com>
6 // Copyright (c) 2008 Novell, Inc (http://www.novell.com)
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
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
;
42 public IndexerValueReference (EvaluationContext ctx
, TargetStructObject target
, TargetObject index
, TargetPropertyInfo indexerProp
): base (ctx
)
44 this.indexer
= indexerProp
;
49 public static IndexerValueReference
CreateIndexerValueReference (EvaluationContext ctx
, TargetObject target
, TargetObject index
)
51 TargetStructObject sob
= target
as TargetStructObject
;
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
)
59 if (mem
.Member
is TargetPropertyInfo
) {
60 TargetPropertyInfo prop
= (TargetPropertyInfo
) mem
.Member
;
61 if (prop
.CanRead
&& prop
.Getter
.ParameterTypes
.Length
== 1) {
67 if (indexerProp
!= null)
68 return new IndexerValueReference (ctx
, sob
, index
, indexerProp
);
73 public override TargetObject Value
{
75 return ObjectUtil
.GetRealObject (Context
, Server
.Instance
.RuntimeInvoke (Context
, indexer
.Getter
, target
, new TargetObject
[] {index}
));
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
{
88 return indexer
.Getter
.ReturnType
;
90 return indexer
.Setter
.ParameterTypes
[1];
95 public override string Name
{
97 return "[" + Server
.Instance
.Evaluator
.TargetObjectToExpression (Context
, index
) + "]";
102 public override ObjectValueFlags Flags
{
104 if (!indexer
.CanWrite
)
105 return ObjectValueFlags
.ArrayElement
| ObjectValueFlags
.ReadOnly
;
107 return ObjectValueFlags
.ArrayElement
;