1 // -------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
3 // -------------------------------------------------------------------
4 //From \\authoring\Sparkle\Source\1.0.1083.0\Common\Source\Framework\Data
5 namespace System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.Data
8 using System.Collections.Generic;
9 using System.ComponentModel;
10 using System.Diagnostics;
11 using System.Globalization;
12 using System.Reflection;
14 using System.Windows.Data;
15 using System.Windows.Markup;
16 using System.Windows.Media;
17 using System.Activities.Presentation;
20 // Transformer which maps from input values to output values, based on a list of SwitchCase children.
21 // This isn't strictly a C-style 'switch' statement, since cases aren't guaranteed to be unique.
24 [ContentProperty("Cases")]
25 internal class SwitchConverter : DependencyObject, IValueConverter
27 static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register("DefaultValue", typeof(object), typeof(SwitchConverter));
28 private List<SwitchCase> cases;
30 public SwitchConverter()
32 this.cases = new List<SwitchCase>();
35 public List<SwitchCase> Cases
37 get { return this.cases; }
40 public object DefaultValue
42 get { return this.GetValue(SwitchConverter.DefaultValueProperty); }
43 set { this.SetValue(SwitchConverter.DefaultValueProperty, value); }
46 // IValueConverter implementation
47 public object Convert(object o, Type targetType, object parameter, CultureInfo culture)
49 foreach (SwitchCase switchCase in this.Cases)
51 if (object.Equals(switchCase.In, o))
53 return switchCase.Out;
57 return this.DefaultValue;
60 public object ConvertBack(object o, Type targetType, object parameter, CultureInfo culture)
62 throw FxTrace.Exception.AsError(new InvalidOperationException(ExceptionStringTable.SwitchConverterIsOneWay));
68 // Represents a mapping from an input value to an output value.
70 internal class SwitchCase : DependencyObject
72 static readonly DependencyProperty InProperty = DependencyProperty.Register("In", typeof(object), typeof(SwitchCase));
73 static readonly DependencyProperty OutProperty = DependencyProperty.Register("Out", typeof(object), typeof(SwitchCase));
82 get { return (object)this.GetValue(InProperty); }
83 set { this.SetValue(InProperty, value); }
88 get { return this.GetValue(OutProperty); }
89 set { this.SetValue(OutProperty, value); }
94 // Convenience class for getting at a particular type. Useful for databinding.
95 // Used in XAML as: <TypeReference Type="*typeof(Foo)" />
97 internal sealed class TypeReference : DependencyObject
99 static readonly DependencyProperty TypeProperty = DependencyProperty.Register("Type", typeof(Type), typeof(TypeReference));
103 get { return (Type)this.GetValue(TypeProperty); }
104 set { this.SetValue(TypeProperty, value); }