ResourceReferenceExpressionConverter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / ResourceReferenceExpressionConverter.cs / 1 / ResourceReferenceExpressionConverter.cs

                            //---------------------------------------------------------------------------- 
//
// File: ResourceReferenceExpressionConverter.cs
//
// Description: 
//   TypeConverter for a resource value expression
// 
// Copyright (C) 2003 by Microsoft Corporation.  All rights reserved. 
//
//--------------------------------------------------------------------------- 

using System;
using System.ComponentModel;
using System.Globalization; 
using System.ComponentModel.Design.Serialization;
using System.Diagnostics; 
 
using System.Windows;
 
namespace System.Windows.Markup
{
    /// 
    ///     TypeConverter for a resource value expression 
    /// 
    public class ResourceReferenceExpressionConverter : ExpressionConverter 
    { 
        /// 
        ///     TypeConverter method override. 
        /// 
        /// 
        ///     ITypeDescriptorContext
        ///  
        /// 
        ///     Type to convert from 
        ///  
        /// 
        ///     true if conversion is possible 
        /// 
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return base.CanConvertFrom(context, sourceType); 
        }
 
        ///  
        ///     TypeConverter method override.
        ///  
        /// 
        ///     For avalon serialization this converter
        ///     returns true for string types only if the
        ///     target element with the resource 
        ///     dictionary for the current resource
        ///     reference is also being serialized. Else 
        ///     it returns false and the serialization 
        ///     engine must serialize the evaluated
        ///     value of the expression. 
        /// 
        /// 
        ///     ITypeDescriptorContext
        ///  
        /// 
        ///     Type to convert to 
        ///  
        /// 
        ///     true if conversion is possible 
        /// 
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            // Validate Input Arguments 
            if (destinationType == null)
            { 
                throw new ArgumentNullException("destinationType"); 
            }
 
            //MarkupExtention
            if (destinationType == typeof(MarkupExtension))
                return true;
 
            return base.CanConvertTo(context, destinationType);
        } 
 
        /// 
        ///     TypeConverter method implementation. 
        /// 
        /// 
        ///     ITypeDescriptorContext
        ///  
        /// 
        ///     current culture (see CLR specs) 
        ///  
        /// 
        ///     value to convert from 
        /// 
        /// 
        ///     value that is result of conversion
        ///  
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        { 
            return base.ConvertFrom(context, culture, value); 
        }
 
        /// 
        ///     TypeConverter method implementation.
        /// 
        ///  
        ///     ITypeDescriptorContext
        ///  
        ///  
        ///     current culture (see CLR specs)
        ///  
        /// 
        ///     value to convert from
        /// 
        ///  
        ///     Type to convert to
        ///  
        ///  
        ///     converted value
        ///  
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            // Validate Input Arguments
            ResourceReferenceExpression expr = value as ResourceReferenceExpression; 
            if (expr == null)
            { 
                throw new ArgumentException(SR.Get(SRID.MustBeOfType, "value", "ResourceReferenceExpression")); 
            }
            if (destinationType == null) 
            {
                throw new ArgumentNullException("destinationType");
            }
 
            // MarkupExtension
            if (destinationType == typeof(MarkupExtension)) 
            { 
                return new DynamicResourceExtension(expr.ResourceKey);
            } 

            return base.ConvertTo(context, culture, value, destinationType);
        }
    } 
}
 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------------------- 
//
// File: ResourceReferenceExpressionConverter.cs
//
// Description: 
//   TypeConverter for a resource value expression
// 
// Copyright (C) 2003 by Microsoft Corporation.  All rights reserved. 
//
//--------------------------------------------------------------------------- 

using System;
using System.ComponentModel;
using System.Globalization; 
using System.ComponentModel.Design.Serialization;
using System.Diagnostics; 
 
using System.Windows;
 
namespace System.Windows.Markup
{
    /// 
    ///     TypeConverter for a resource value expression 
    /// 
    public class ResourceReferenceExpressionConverter : ExpressionConverter 
    { 
        /// 
        ///     TypeConverter method override. 
        /// 
        /// 
        ///     ITypeDescriptorContext
        ///  
        /// 
        ///     Type to convert from 
        ///  
        /// 
        ///     true if conversion is possible 
        /// 
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return base.CanConvertFrom(context, sourceType); 
        }
 
        ///  
        ///     TypeConverter method override.
        ///  
        /// 
        ///     For avalon serialization this converter
        ///     returns true for string types only if the
        ///     target element with the resource 
        ///     dictionary for the current resource
        ///     reference is also being serialized. Else 
        ///     it returns false and the serialization 
        ///     engine must serialize the evaluated
        ///     value of the expression. 
        /// 
        /// 
        ///     ITypeDescriptorContext
        ///  
        /// 
        ///     Type to convert to 
        ///  
        /// 
        ///     true if conversion is possible 
        /// 
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            // Validate Input Arguments 
            if (destinationType == null)
            { 
                throw new ArgumentNullException("destinationType"); 
            }
 
            //MarkupExtention
            if (destinationType == typeof(MarkupExtension))
                return true;
 
            return base.CanConvertTo(context, destinationType);
        } 
 
        /// 
        ///     TypeConverter method implementation. 
        /// 
        /// 
        ///     ITypeDescriptorContext
        ///  
        /// 
        ///     current culture (see CLR specs) 
        ///  
        /// 
        ///     value to convert from 
        /// 
        /// 
        ///     value that is result of conversion
        ///  
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        { 
            return base.ConvertFrom(context, culture, value); 
        }
 
        /// 
        ///     TypeConverter method implementation.
        /// 
        ///  
        ///     ITypeDescriptorContext
        ///  
        ///  
        ///     current culture (see CLR specs)
        ///  
        /// 
        ///     value to convert from
        /// 
        ///  
        ///     Type to convert to
        ///  
        ///  
        ///     converted value
        ///  
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            // Validate Input Arguments
            ResourceReferenceExpression expr = value as ResourceReferenceExpression; 
            if (expr == null)
            { 
                throw new ArgumentException(SR.Get(SRID.MustBeOfType, "value", "ResourceReferenceExpression")); 
            }
            if (destinationType == null) 
            {
                throw new ArgumentNullException("destinationType");
            }
 
            // MarkupExtension
            if (destinationType == typeof(MarkupExtension)) 
            { 
                return new DynamicResourceExtension(expr.ResourceKey);
            } 

            return base.ConvertTo(context, culture, value, destinationType);
        }
    } 
}
 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK