1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.Model
9 using System.ComponentModel;
10 using System.Diagnostics;
13 // We need to provide a type descriptor context that can get to
14 // services in the editing context. This wrapper does that by
15 // first checking the original set of services and then routing
16 // to the given service provider (which is usually an editing context's
19 internal class ModelTypeDescriptorContextWrapper : ITypeDescriptorContext
22 ITypeDescriptorContext context;
23 ModelTreeManager modelTreeManager;
25 internal ModelTypeDescriptorContextWrapper(ITypeDescriptorContext context, ModelTreeManager modelTreeManager)
28 this.context = context;
29 this.modelTreeManager = modelTreeManager;
33 public IContainer Container
35 get { return this.context == null ? null : this.context.Container; }
38 public object Instance
42 object instance = null;
44 if (this.context != null)
46 instance = this.context.Instance;
47 ModelItem item = instance as ModelItem;
50 instance = item.GetCurrentValue();
58 public PropertyDescriptor PropertyDescriptor
62 PropertyDescriptor desc = null;
64 if (this.context != null)
66 desc = this.context.PropertyDescriptor;
69 ModelItem item = this.context.Instance as ModelItem;
72 desc = new WrappedPropertyDescriptor(desc, item);
82 public void OnComponentChanged()
84 if (this.context != null)
86 this.context.OnComponentChanged();
90 public bool OnComponentChanging()
92 return this.context == null ? false : this.context.OnComponentChanging();
95 public object GetService(Type serviceType)
97 object service = null;
99 if (this.context != null)
101 service = this.context.GetService(serviceType);
106 service = this.modelTreeManager.Context.Services.GetService(serviceType);
114 // This property descriptor dynamically converts calls to
115 // the original property descriptor, converting values on
117 class WrappedPropertyDescriptor : PropertyDescriptor
119 private PropertyDescriptor _parent;
120 private ModelItem _item;
122 internal WrappedPropertyDescriptor(PropertyDescriptor parent, ModelItem item)
128 public override Type ComponentType
129 { get { return _parent.ComponentType; } }
130 public override bool IsReadOnly
131 { get { return _parent.IsReadOnly; } }
132 public override Type PropertyType
133 { get { return _parent.PropertyType; } }
135 public override bool CanResetValue(object component)
137 return _parent.CanResetValue(_item);
139 public override object GetValue(object component)
141 return _parent.GetValue(_item);
143 public override void ResetValue(object component)
145 _parent.ResetValue(_item);
147 public override void SetValue(object component, object value)
149 _parent.SetValue(_item, value);
151 public override bool ShouldSerializeValue(object component)
153 return _parent.ShouldSerializeValue(_item);