Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BasePropertyDescriptor.cs « Common « System.Workflow.Activities « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: edf00c3bb3669620aeed98f6109c77dd9b181850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
// Copyright (c) 1999-2002 Microsoft Corporation. All rights reserved. 
//  
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 
// THE ENTIRE RISK OF USE OR RESULTS IN CONNECTION WITH THE USE OF THIS CODE 
// AND INFORMATION REMAINS WITH THE USER. 
//  
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Collections.Generic;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Security;
using System.Security.Permissions;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Design;

/*********************************************************************
 * NOTE: A copy of this file exists at: WF\Common\Shared
 * The two files must be kept in [....].  Any change made here must also
 * be made to WF\Common\Shared\BasePropertyDescriptor.cs
*********************************************************************/

namespace System.Workflow.Activities.Common
{
    #region Class PropertyDescriptorUtils
    internal static class PropertyDescriptorUtils
    {
        internal static ISite GetSite(IServiceProvider serviceProvider, object component)
        {
            ISite site = null;

            if (component != null)
            {
                if ((component is IComponent) && ((IComponent)component).Site != null)
                    site = ((IComponent)component).Site;

                if (site == null && component.GetType().IsArray && (component as object[]).Length > 0 && (component as object[])[0] is IComponent)
                    site = ((IComponent)(component as object[])[0]).Site;

                if (site == null && serviceProvider != null)
                {
                    IReferenceService referenceService = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
                    if (referenceService != null)
                    {
                        IComponent baseComponent = referenceService.GetComponent(component);
                        if (baseComponent != null)
                            site = baseComponent.Site;
                    }
                }
            }

            if (site == null)
                site = serviceProvider as ISite;

            return site;
        }

        internal static IComponent GetComponent(ITypeDescriptorContext context)
        {
            ISite site = (context != null) ? GetSite(context, context.Instance) : null;
            return (site != null) ? site.Component : null;
        }

        internal static Type GetBaseType(PropertyDescriptor property, object owner, IServiceProvider serviceProvider)
        {
            Type baseType = null;

            Type ownerType = owner.GetType();
            if (owner != null)
            {
                IDynamicPropertyTypeProvider basetypeProvider = owner as IDynamicPropertyTypeProvider;
                if (basetypeProvider != null)
                    baseType = basetypeProvider.GetPropertyType(serviceProvider, property.Name);
            }

            if (baseType == null)
                baseType = property.PropertyType;

            return baseType;
        }

        internal static void SetPropertyValue(IServiceProvider serviceProvider, PropertyDescriptor propertyDescriptor, object component, object value)
        {
            ComponentChangeDispatcher componentChange = new ComponentChangeDispatcher(serviceProvider, component, propertyDescriptor);
            try
            {
                propertyDescriptor.SetValue(component, value);
            }
            catch (Exception t)
            {
                // If there was a problem setting the controls property then we get:
                // ArgumentException (from properties set method)
                // ==> Becomes inner exception of TargetInvocationException
                // ==> caught here
                // Propagate the original exception up
                if (t is TargetInvocationException && t.InnerException != null)
                    throw t.InnerException;
                else
                    throw t;
            }
            finally
            {
                componentChange.Dispose();
            }
        }
    }
    #endregion

    #region Class ComponentChangeDispatcher
    internal sealed class ComponentChangeDispatcher : IDisposable
    {
        private IServiceProvider serviceProvider;
        private object component;
        private PropertyDescriptor property;
        private object oldValue;
        private object newValue;

        public ComponentChangeDispatcher(IServiceProvider serviceProvider, object component, PropertyDescriptor propertyDescriptor)
        {
            this.serviceProvider = serviceProvider;
            this.component = component;
            this.property = propertyDescriptor;

            IComponentChangeService changeService = serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
            if (changeService != null)
            {
                try
                {
                    newValue = oldValue = propertyDescriptor.GetValue(component);
                    propertyDescriptor.AddValueChanged(component, new EventHandler(OnValueChanged));
                    changeService.OnComponentChanging(component, propertyDescriptor);
                }
                catch (CheckoutException coEx)
                {
                    if (coEx == CheckoutException.Canceled)
                        return;
                    throw coEx;
                }
            }
        }

        public void Dispose()
        {
            IComponentChangeService changeService = this.serviceProvider.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
            if (changeService != null)
                changeService.OnComponentChanged(this.component, this.property, this.oldValue, this.newValue);
        }

        private void OnValueChanged(object sender, EventArgs e)
        {
            this.newValue = this.property.GetValue(this.component);
            this.property.RemoveValueChanged(this.component, new EventHandler(OnValueChanged));
        }
    }
    #endregion

    #region Class DynamicPropertyDescriptor
    internal class DynamicPropertyDescriptor : PropertyDescriptor
    {
        private IServiceProvider serviceProvider;
        private PropertyDescriptor realPropertyDescriptor;

        public DynamicPropertyDescriptor(IServiceProvider serviceProvider, PropertyDescriptor descriptor)
            : base(descriptor, null)
        {
            this.serviceProvider = serviceProvider;
            this.realPropertyDescriptor = descriptor;
        }

        public IServiceProvider ServiceProvider
        {
            get
            {
                return this.serviceProvider;
            }
        }

        public PropertyDescriptor RealPropertyDescriptor
        {
            get
            {
                return this.realPropertyDescriptor;
            }
        }

        public override string Category
        {
            get
            {
                return this.realPropertyDescriptor.Category;
            }
        }

        public override AttributeCollection Attributes
        {
            get
            {
                ArrayList attributes = new ArrayList();
                attributes.AddRange(this.realPropertyDescriptor.Attributes);
                attributes.Add(new MergablePropertyAttribute(false));
                return new AttributeCollection((Attribute[])attributes.ToArray(typeof(Attribute)));
            }
        }

        public override TypeConverter Converter
        {
            get
            {
                return this.realPropertyDescriptor.Converter;
            }
        }

        public override string Description
        {
            get
            {
                return this.realPropertyDescriptor.Description;
            }
        }

        public override string DisplayName
        {
            get
            {
                return this.realPropertyDescriptor.DisplayName;
            }
        }

        public override Type ComponentType
        {
            get
            {
                return this.realPropertyDescriptor.ComponentType;
            }
        }

        public override Type PropertyType
        {
            get
            {
                return this.realPropertyDescriptor.PropertyType;
            }
        }

        public override bool IsReadOnly
        {
            get
            {
                return this.realPropertyDescriptor.IsReadOnly;
            }
        }

        public override void ResetValue(object component)
        {
            this.realPropertyDescriptor.ResetValue(component);
        }

        public override bool CanResetValue(object component)
        {
            return this.realPropertyDescriptor.CanResetValue(component);
        }

        public override bool ShouldSerializeValue(object component)
        {
            // work around: The real property descriptor is returning false for all the
            // SequentialWorkflow class's properties because they all get replaced with 
            // InheritedPropertyDescriptors on Initialization (in the ComponentDesigner
            // base class), which is causing problems in the code-only serialization.
            if (string.Equals(this.realPropertyDescriptor.GetType().FullName, "System.ComponentModel.Design.InheritedPropertyDescriptor", StringComparison.Ordinal))
                return true;

            return this.realPropertyDescriptor.ShouldSerializeValue(component);
        }

        public override object GetValue(object component)
        {
            // When a child property is of type event, component could be null.
            if (component == null)
                return null;

            return this.realPropertyDescriptor.GetValue(component);
        }

        public override void SetValue(object component, object value)
        {
            if (component is IComponent)
                this.realPropertyDescriptor.SetValue(component, value);
            else
                PropertyDescriptorUtils.SetPropertyValue(ServiceProvider, this.realPropertyDescriptor, component, value);
        }
    }
    #endregion

    #region Class ParameterInfoBasedPropertyDescriptor

    internal class ParameterInfoBasedPropertyDescriptor : PropertyDescriptor
    {
        private Type componentType;
        private string desc = string.Empty;
        private bool avoidDuplication = false;
        private object parameter = null; // Could be either ParameterInfo or PropertyInfo
        private Type parameterType = null;
        private const string parameterPrefix = "(Parameter) ";

        internal ParameterInfoBasedPropertyDescriptor(Type componentType, ParameterInfo paramInfo, bool avoidDuplication, params Attribute[] attributes)
            : base((paramInfo.Position == -1) ? "(ReturnValue)" : paramInfo.Name, attributes)
        {
            if (componentType == null)
                throw new ArgumentNullException("componentType");

            if (paramInfo == null)
                throw new ArgumentNullException("paramInfo");

            if (paramInfo.ParameterType == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_ParameterTypeResolution, paramInfo.Name));

            this.componentType = componentType;
            this.parameter = paramInfo;
            this.avoidDuplication = avoidDuplication;
            this.parameterType = paramInfo.ParameterType;

            //Build and cache description
            string qualifier = String.Empty;
            if ((paramInfo.ParameterType != null) && (paramInfo.ParameterType.IsByRef || (paramInfo.IsIn && paramInfo.IsOut)))
                qualifier = SR.GetString(SR.Ref);
            else if (paramInfo.IsOut || paramInfo.Name == null)
                qualifier = SR.GetString(SR.Out);
            else
                qualifier = SR.GetString(SR.In);
            this.desc = SR.GetString(SR.ParameterDescription, paramInfo.ParameterType.FullName);
        }


        internal ParameterInfoBasedPropertyDescriptor(Type componentType, string propertyName, Type propertyType, bool avoidDuplication, params Attribute[] attributes)
            : base(propertyName, attributes)
        {
            if (componentType == null)
                throw new ArgumentNullException("componentType");

            if (propertyType == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_ParameterTypeResolution, propertyName));

            this.componentType = componentType;
            this.parameterType = propertyType;
            this.avoidDuplication = avoidDuplication;
            this.desc = SR.GetString(SR.InvokeParameterDescription, propertyType.FullName.ToString());
        }

        internal Type ParameterType
        {
            get
            {
                Type type = this.parameterType;
                if (type.IsByRef)
                    type = type.GetElementType();
                return type;
            }
        }

        public override string Description
        {
            get
            {
                return this.desc;
            }
        }

        public override string Category
        {
            get
            {
                return SR.GetString(SR.Parameters);
            }
        }

        public override object GetEditor(Type editorBaseType)
        {
            return TypeDescriptor.GetEditor(PropertyType, editorBaseType);
        }

        public override string DisplayName
        {
            get
            {
                return this.Name;
            }
        }

        public override bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        public override Type ComponentType
        {
            get
            {
                return this.componentType;
            }
        }

        public override string Name
        {
            get
            {
                if (this.avoidDuplication)
                {
                    // WinOE Bug 10442: should only prefix with "(Parameter)" if there is and existing
                    // member of the same name.
                    return GetParameterPropertyName(this.componentType, base.Name);
                }
                else
                    return base.Name;
            }
        }

        internal static MemberInfo FindMatchingMember(string name, Type ownerType, bool ignoreCase)
        {
            MemberInfo matchingMember = null;
            foreach (MemberInfo memberInfo in ownerType.GetMembers(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
            {
                if (memberInfo.Name.Equals(name, ((ignoreCase) ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture)))
                {
                    matchingMember = memberInfo;
                    break;
                }
            }
            return matchingMember;
        }

        public override Type PropertyType
        {
            get
            {
                Type propertyType = ParameterType;
                if (propertyType == null)
                    propertyType = typeof(ActivityBind);
                return propertyType;
            }
        }

        public override TypeConverter Converter
        {
            get
            {
                //We return this to make sure that we can bind parameters through UI
                return new ActivityBindTypeConverter();
            }
        }

        public override AttributeCollection Attributes
        {
            get
            {
                ArrayList attributes = new ArrayList();
                attributes.AddRange(base.Attributes);
                attributes.AddRange(TypeDescriptor.GetAttributes(PropertyType));
                return new AttributeCollection((Attribute[])attributes.ToArray(typeof(Attribute)));
            }
        }

        public override void ResetValue(object component)
        {
            if (PropertyType != null && !PropertyType.IsValueType)
                SetValue(component, null);
        }

        public override bool CanResetValue(object component)
        {
            return false;
        }

        public override bool ShouldSerializeValue(object component)
        {
            return false;
        }

        public override void SetValue(object component, object value)
        {
            // the logic for notifications is borrowed from ReflectPropertyDescritpor
            if (component == null)
                return;

            IServiceProvider serviceProvider = GetSite(component);
            ComponentChangeDispatcher componentChange = (serviceProvider != null) ? new ComponentChangeDispatcher(serviceProvider, component, this) : null;

            try
            {
                WorkflowParameterBindingCollection parameters = GetParameterBindings(component);
                if (parameters != null)
                {
                    string propertyName = String.Empty;
                    if (this.Name.StartsWith(parameterPrefix, StringComparison.Ordinal))
                        propertyName = this.Name.Substring(parameterPrefix.Length);
                    else
                        propertyName = this.Name;

                    WorkflowParameterBinding binding = null;
                    if (parameters.Contains(propertyName))
                        binding = parameters[propertyName];
                    else
                    {
                        binding = new WorkflowParameterBinding(propertyName);
                        parameters.Add(binding);
                    }

                    if (value is ActivityBind)
                        binding.SetBinding(WorkflowParameterBinding.ValueProperty, value as ActivityBind);
                    else
                        binding.SetValue(WorkflowParameterBinding.ValueProperty, value);

                    OnValueChanged(component, EventArgs.Empty);
                }
            }
            catch (Exception t)
            {
                // If there was a problem setting the controls property then we get:
                // ArgumentException (from properties set method)
                // ==> Becomes inner exception of TargetInvocationException
                // ==> caught here
                // Propagate the original exception up
                if (t is TargetInvocationException && t.InnerException != null)
                    throw t.InnerException;
                else
                    throw t;
            }
            finally
            {
                // Now notify the change service that the change was successful.
                if (componentChange != null)
                    componentChange.Dispose();
            }
        }

        public override object GetValue(object component)
        {
            WorkflowParameterBindingCollection parameters = GetParameterBindings(component);
            string displayName = this.Name;
            string propertyName = (displayName.StartsWith(parameterPrefix, StringComparison.Ordinal)) ? displayName.Substring(parameterPrefix.Length) : displayName;
            if (parameters != null && parameters.Contains(propertyName))
            {
                if (parameters[propertyName].IsBindingSet(WorkflowParameterBinding.ValueProperty))
                    return parameters[propertyName].GetBinding(WorkflowParameterBinding.ValueProperty);
                else
                    return parameters[propertyName].GetValue(WorkflowParameterBinding.ValueProperty);
            }

            return null;
        }

        private WorkflowParameterBindingCollection GetParameterBindings(object component)
        {
            WorkflowParameterBindingCollection retVal = null;
            MemberInfo memberInfo = component.GetType().GetProperty("ParameterBindings", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.ExactBinding, null, typeof(WorkflowParameterBindingCollection), new Type[] { }, new ParameterModifier[] { });
            if (memberInfo != null)
                retVal = component.GetType().InvokeMember("ParameterBindings", BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.ExactBinding, null, component, new object[] { }, CultureInfo.InvariantCulture) as WorkflowParameterBindingCollection;
            return retVal;
        }

        public static string GetParameterPropertyName(Type componentType, string paramName)
        {
            string paramPropertyName = paramName;
            if (FindMatchingMember(paramName, componentType, false) != null)
                paramPropertyName = parameterPrefix + paramName;

            return paramPropertyName;
        }
    }
    #endregion

    #region IPropertyValueProvider Interface
    internal interface IPropertyValueProvider
    {
        ICollection GetPropertyValues(ITypeDescriptorContext typeDescriptorContext);
    }
    #endregion

    #region Class PropertyValueProviderTypeConverter
    internal class PropertyValueProviderTypeConverter : TypeConverter
    {
        public PropertyValueProviderTypeConverter()
        {
        }

        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            // grab all property values
            IPropertyValueProvider valuesProvider = null;
            object[] instances = context.Instance as object[];
            if (instances != null && instances.Length > 0)
                valuesProvider = instances[0] as IPropertyValueProvider;
            else
                valuesProvider = context.Instance as IPropertyValueProvider;

            ICollection values = new object[] { };
            if (valuesProvider != null)
                values = valuesProvider.GetPropertyValues(context);

            return new StandardValuesCollection(values);
        }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }
    }
    #endregion

    #region Class TypePropertyDescriptor
    internal class TypePropertyDescriptor : DynamicPropertyDescriptor
    {
        public TypePropertyDescriptor(IServiceProvider serviceProvider, PropertyDescriptor actualPropDesc)
            : base(serviceProvider, actualPropDesc)
        {
        }

        public override TypeConverter Converter
        {
            get
            {
                // work around: a direct type comparison would not work because the types in this file are compiled
                // into the component model and the activities dll separately.  The assembly name differs thus
                // the comparison fails.  Work around by getting the type from the same assembly before doing
                // the comparison.
                TypeConverter baseTypeConverter = base.Converter;
                string baseConverterTypeName = baseTypeConverter.GetType().FullName;
                Type baseConverterType = Assembly.GetExecutingAssembly().GetType(baseConverterTypeName);
                if (baseConverterType != null && typeof(TypePropertyTypeConverter).IsAssignableFrom(baseConverterType))
                    return baseTypeConverter;
                else
                    return new TypePropertyTypeConverter();
            }
        }

        public override object GetValue(object component)
        {
            if (component == null)
                throw new ArgumentNullException("component");

            object value = base.GetValue(component);

            if (value == null)
            {
                // See if there is a value in the user data DesignTimeTypeNames hashtable. 
                // If yes, it's probably a wrong type name.  Show the name anyway.
                DependencyObject dependencyObject = component as DependencyObject;
                if (dependencyObject != null)
                {
                    object key = DependencyProperty.FromName(this.RealPropertyDescriptor.Name, this.RealPropertyDescriptor.ComponentType);
                    value = Helpers.GetDesignTimeTypeName(dependencyObject, key);
                    if (string.IsNullOrEmpty(value as string))
                    {
                        key = this.RealPropertyDescriptor.ComponentType.FullName + "." + this.RealPropertyDescriptor.Name;
                        value = Helpers.GetDesignTimeTypeName(dependencyObject, key);
                    }
                }
            }

            return value;
        }

        public override void SetValue(object component, object value)
        {
            if (component == null)
                throw new ArgumentNullException("component");

            if (value != null)
            {
                Type type = value as Type;
                ITypeFilterProvider filterProvider = PropertyDescriptorUtils.GetComponent(new TypeDescriptorContext(ServiceProvider, RealPropertyDescriptor, component)) as ITypeFilterProvider;
                if (filterProvider != null)
                    filterProvider.CanFilterType(type, true); //this will throw an exception if the type is not correctly filterable
            }

            base.SetValue(component, value);
        }
    }
    #endregion

    #region Class TypePropertyValueProviderTypeConverter
    internal class TypePropertyValueProviderTypeConverter : TypePropertyTypeConverter
    {
        // NOTE: Copied from PropertyValueProviderTypeConverter.
        // The purpose of this type converter is so that we can both provide standard values and
        // convert System.Type to string.
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            // grab all property values
            IPropertyValueProvider valuesProvider = null;
            object[] instances = context.Instance as object[];
            if (instances != null && instances.Length > 0)
                valuesProvider = instances[0] as IPropertyValueProvider;
            else
                valuesProvider = context.Instance as IPropertyValueProvider;

            ICollection values = new object[] { };
            if (valuesProvider != null && context != null)
                values = valuesProvider.GetPropertyValues(context);

            return new StandardValuesCollection(values);
        }
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }
    }
    #endregion

    #region Class TypePropertyTypeConverter
    internal class TypePropertyTypeConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType == null)
                throw new ArgumentNullException("sourceType");

            if (TypeDescriptor.Equals(sourceType, typeof(string)))
                return true;

            return base.CanConvertFrom(context, sourceType);

        }

        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (destinationType == null)
                throw new ArgumentNullException("destinationType");

            if (TypeDescriptor.Equals(destinationType, typeof(Type)))
                return true;

            return base.CanConvertTo(context, destinationType);
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object valueToConvert)
        {
            string typeName = valueToConvert as string;
            if (String.IsNullOrEmpty(typeName))
                return null;

            if (context != null)
            {
                ITypeProvider typeProvider = context.GetService(typeof(ITypeProvider)) as ITypeProvider;
                if (typeProvider != null)
                    return typeProvider.GetType(typeName, true);
            }

            return base.ConvertFrom(context, culture, valueToConvert);
        }

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (value is Type && TypeDescriptor.Equals(destinationType, typeof(string)))
                return ((Type)value).FullName;

            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
    #endregion
}