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

GenericTypeArgumentConverter.cs « Presentation « Core « Activities « System « System.Activities.Core.Presentation « System.Activities.Presentation « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bf84af9e6b69a229a826a84390c39ef235350398 (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
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------

namespace System.Activities.Core.Presentation
{
    using System.Windows.Data;
    using System.Runtime;
    using System.Globalization;

    public sealed class GenericTypeArgumentConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Fx.Assert(targetType == typeof(Type), "GenericTypeArgumentConverter is expected to be a Type to Type converter with an integer parameter");
            Fx.Assert(value is Type, "GenericTypeArgumentConverter is expected to be a Type to Type converter with an integer parameter");
            Type source = value as Type;
            return source.GetGenericArguments()[Int32.Parse(parameter.ToString(), culture)];
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // It is theoretically impossible to convert from a generic type argument back to its original type.
            throw FxTrace.Exception.AsError(new NotSupportedException());
        }
    }
}