Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/TypeConverters
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18183/Spring/Spring.Core/Objects/TypeConverters
Modified Files:
StringArrayConverter.cs
Log Message:
Added centralised Type resolution mechanism, runtime type converter, Xml Config handler, multiple documentation updates.
Index: StringArrayConverter.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/TypeConverters/StringArrayConverter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** StringArrayConverter.cs 6 Jul 2004 12:54:27 -0000 1.2
--- StringArrayConverter.cs 26 Jul 2004 07:47:57 -0000 1.3
***************
*** 14,30 ****
* limitations under the License.
*/
! using System;
! using System.ComponentModel;
! using System.Globalization;
using Spring.Util;
namespace Spring.Objects.TypeConverters
{
! /// <summary>
/// Convert a CVS String to a String array and vice-versa. This TypeConverter
/// is auotmatically registered with ObjectWrapper.
/// </summary>
public class StringArrayConverter : TypeConverter
{
/// <summary>
/// Create a converter
/// </summary>
public StringArrayConverter()
{
}
! /// <summary>
/// Can we convert from a the sourcetype to a StringArray. True if the sourceType
/// is a string. Otherwise see if the base TypeConverter can handle it (it can't).
/// </summary>
/// <param name="context">Description of the type</param>
/// <param name="sourceType">The type to convert from.</param>
/// <returns></returns>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom (context, sourceType);
}
/// <summary>
/// Convert from a string value to a string array
/// </summary>
/// <param name="context">The type context</param>
/// <param name="culture">Culture info. Ignored for now.</param>
/// <param name="val">string value to convert.</param>
/// <returns>A string array if successfull. Empty zero length string of val is null.</returns>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object val)
{
//TODO think about including culture....
! /*
! if (null == culture)
! {
! culture = CultureInfo.CurrentCulture;
! }
! string[] param = sValue.Split(new char[] {culture.TextInfo.ListSeparator[0] } );
! */
! if (val is string)
{
return StringUtils.CommaDelimitedListToStringArray((string)val);
}
return base.ConvertFrom(context, culture, val);
}
}
}
--- 14,57 ----
* limitations under the License.
*/
! using System;
using System.ComponentModel;
using System.Globalization;
using Spring.Util;
namespace Spring.Objects.TypeConverters
{
! /// <summary>
/// Convert a CVS <see cref="System.String"/> to a <see cref="System.String"/> array and vice-versa.
/// </summary>
/// <remarks>
/// <p>
/// This <see cref="System.ComponentModel.TypeConverter"/> should be
/// automatically registered with any <see cref="Spring.Objects.IObjectWrapper"/>
/// implementations.
/// </p>
/// </remarks>
/// <author></author>
/// <version>$Id$</version>
public class StringArrayConverter : TypeConverter
{
#region Constructor (s) / Destructor
/// <summary>
/// Create a new instance of the StringArrayConverter class.
/// </summary>
public StringArrayConverter ()
{
}
#endregion
! #region Methods
! /// <summary>
! /// Can we convert from a the sourcetype to a
! /// <see cref="System.String"/> array?
! /// </summary>
! /// <remarks>
! /// <p>
! /// Currently only supports conversion from a
! /// <see cref="System.String"/> instance.
! /// </p>
! /// </remarks>
! /// <param name="context">
! /// A <see cref="System.ComponentModel.ITypeDescriptorContext"/>
! /// that provides a format context.
! /// </param>
! /// <param name="sourceType">
! /// A <see cref="System.Type"/> that represents the
! /// <see cref="System.Type"/> you want to convert from.
! /// </param>
! /// <returns>True if the conversion is possible.</returns>
public override bool CanConvertFrom (
ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof (string))
{
return true;
}
return base.CanConvertFrom (context, sourceType);
}
/// <summary>
! /// Convert from a string value to a <see cref="System.String"/> array.
! /// </summary>
! /// <param name="context">
! /// A <see cref="System.ComponentModel.ITypeDescriptorContext"/>
! /// that provides a format context.
! /// </param>
! /// <param name="culture">
! /// The <see cref="System.Globalization.CultureInfo"/> to use
! /// as the current culture (currently ignored).
! /// </param>
! /// <param name="value">
! /// The value that is to be converted.
! /// </param>
! /// <returns>
! /// A <see cref="System.String"/> array if successful.
! /// An empty zero length <see cref="System.String"/> if
! /// <paramref name="value"/> is null.
! /// </returns>
public override object ConvertFrom (
ITypeDescriptorContext context, CultureInfo culture, object value)
{
//TODO think about including culture....
/*
if (null == culture)
{
culture = CultureInfo.CurrentCulture;
}
string[] param = sValue.Split(new char[] {culture.TextInfo.ListSeparator[0] } );
*/
if (value is string)
{
return StringUtils.CommaDelimitedListToStringArray ((string) value);
}
return base.ConvertFrom (context, culture, value);
}
#endregion
}
}
|