bf84af9e6b69a229a826a84390c39ef235350398
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Core.Presentation / System / Activities / Core / Presentation / GenericTypeArgumentConverter.cs
1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------
4
5 namespace System.Activities.Core.Presentation
6 {
7     using System.Windows.Data;
8     using System.Runtime;
9     using System.Globalization;
10
11     public sealed class GenericTypeArgumentConverter : IValueConverter
12     {
13         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
14         {
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)];
19         }
20
21         public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
22         {
23             // It is theoretically impossible to convert from a generic type argument back to its original type.
24             throw FxTrace.Exception.AsError(new NotSupportedException());
25         }
26     }
27 }