[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / Editors / ImageSourceToImageConverter.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Editors 
5 {
6     using System;
7     using System.Globalization;
8     using System.Diagnostics.CodeAnalysis;
9     using System.Windows.Controls;
10     using System.Windows.Data;
11     using System.Windows.Media;
12
13     using System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.PropertyInspector;
14     using System.Activities.Presentation;
15
16     // <summary>
17     // Converter that takes an object and either returns it
18     // or wraps it in an Image control if the object is of type ImageSource.
19     // This class gets instantiated from XAML.
20     // </summary>
21     [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
22     internal class ImageSourceToImageConverter : IValueConverter 
23     {
24         // IValueConverter Members
25
26         public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
27         {
28
29             ImageSource imageSource = value as ImageSource;
30
31             if (imageSource == null)
32             {
33                 return value;
34             }
35
36             Image image = new Image();
37             image.Source = imageSource;
38             return image;
39         }
40
41         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
42         {
43             throw FxTrace.Exception.AsError(new InvalidOperationException());
44         }
45
46     }
47 }