1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //------------------------------------------------------------
5 namespace System.Activities.Core.Presentation
7 using System.Windows.Data;
9 using System.Globalization;
11 public sealed class GenericTypeArgumentConverter : IValueConverter
13 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
15 Fx.Assert(targetType == typeof(Type), "GenericTypeArgumentConverter is expected to be a Type to Type converter with an integer parameter");
16 Fx.Assert(value is Type, "GenericTypeArgumentConverter is expected to be a Type to Type converter with an integer parameter");
17 Type source = value as Type;
18 return source.GetGenericArguments()[Int32.Parse(parameter.ToString(), culture)];
21 public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
23 // It is theoretically impossible to convert from a generic type argument back to its original type.
24 throw FxTrace.Exception.AsError(new NotSupportedException());