TypeConverterValueSerializer.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Base / MS / Internal / Markup / TypeConverterValueSerializer.cs / 1 / TypeConverterValueSerializer.cs

                            //------------------------------------------------------------------------ 
//
//  Microsoft Windows Client Platform
//  Copyright (C) Microsoft Corporation, 2005
// 
//  File:      TypeConverterValueSerializer.cs
// 
//  Contents:  TypeConverter to ValueSerializer adapter 
//
//  Created:   04/28/2005 [....] 
//
//-----------------------------------------------------------------------

using System.ComponentModel; 
using System.Globalization;
using System.Windows.Markup; 
 
namespace MS.Internal.Serialization
{ 
    /// 
    /// The TypeConverter value serializer uses a TypeConverter to implement the translation
    /// to and from a string. The caller of the constructor must ensure the TypeConverter supports
    /// converstion to and from string. 
    /// 
    internal sealed class TypeConverterValueSerializer : ValueSerializer 
    { 
        private TypeConverter converter;
 
        public TypeConverterValueSerializer(TypeConverter converter)
        {
            this.converter = converter;
        } 

        public override bool CanConvertToString(object value, IValueSerializerContext context) 
        { 
            return converter.CanConvertTo(context, typeof(string));
        } 

        public override string ConvertToString(object value, IValueSerializerContext context)
        {
            return converter.ConvertToString(context, CultureInfo.GetCultureInfo("en-us"), value); 
        }
 
        public override bool CanConvertFromString(string value, IValueSerializerContext context) 
        {
            return true; 
        }

        public override object ConvertFromString(string value, IValueSerializerContext context)
        { 
            return converter.ConvertFrom(context, CultureInfo.GetCultureInfo("en-us"), value);
        } 
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------ 
//
//  Microsoft Windows Client Platform
//  Copyright (C) Microsoft Corporation, 2005
// 
//  File:      TypeConverterValueSerializer.cs
// 
//  Contents:  TypeConverter to ValueSerializer adapter 
//
//  Created:   04/28/2005 [....] 
//
//-----------------------------------------------------------------------

using System.ComponentModel; 
using System.Globalization;
using System.Windows.Markup; 
 
namespace MS.Internal.Serialization
{ 
    /// 
    /// The TypeConverter value serializer uses a TypeConverter to implement the translation
    /// to and from a string. The caller of the constructor must ensure the TypeConverter supports
    /// converstion to and from string. 
    /// 
    internal sealed class TypeConverterValueSerializer : ValueSerializer 
    { 
        private TypeConverter converter;
 
        public TypeConverterValueSerializer(TypeConverter converter)
        {
            this.converter = converter;
        } 

        public override bool CanConvertToString(object value, IValueSerializerContext context) 
        { 
            return converter.CanConvertTo(context, typeof(string));
        } 

        public override string ConvertToString(object value, IValueSerializerContext context)
        {
            return converter.ConvertToString(context, CultureInfo.GetCultureInfo("en-us"), value); 
        }
 
        public override bool CanConvertFromString(string value, IValueSerializerContext context) 
        {
            return true; 
        }

        public override object ConvertFromString(string value, IValueSerializerContext context)
        { 
            return converter.ConvertFrom(context, CultureInfo.GetCultureInfo("en-us"), value);
        } 
    } 
}

// 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