dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System/ComponentModel CharConverter.c


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System/ComponentModel CharConverter.cs, NONE, 1.1 CollectionConverter.cs, NONE, 1.1 CultureInfoConverter.cs, NONE, 1.1 DateTimeConverter.cs, NONE, 1.1 GuidConverter.cs, NONE, 1.1 ReferenceConverter.cs, NONE, 1.1 SyntaxCheck.cs, NONE, 1.1 TimeSpanConverter.cs, NONE, 1.1 TypeListConverter.cs, NONE, 1.1 BaseNumberConverter.cs, 1.5, 1.6 EnumConverter.cs, 1.5, 1.6 TypeConverter.cs, 1.6, 1.7
Date: Thu, 07 Aug 2003 22:56:52 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System/ComponentModel
In directory subversions:/tmp/cvs-serv14971/System/ComponentModel

Modified Files:
        BaseNumberConverter.cs EnumConverter.cs TypeConverter.cs 
Added Files:
        CharConverter.cs CollectionConverter.cs 
        CultureInfoConverter.cs DateTimeConverter.cs GuidConverter.cs 
        ReferenceConverter.cs SyntaxCheck.cs TimeSpanConverter.cs 
        TypeListConverter.cs 
Log Message:


More converter classes for System.ComponentModel.


--- NEW FILE ---
/*
 * CharConverter.cs - Implementation of the
 *              "System.ComponentModel.ComponentModel.CharConverter" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;
using System.Collections;
using System.Globalization;

public class CharConverter : TypeConverter
{
        // Constructor.
        public CharConverter()
                        {
                                // Nothing to do here.
                        }

        // Determine if we can convert from a specific type to this one.
        public override bool CanConvertFrom
                                (ITypeDescriptorContext context, Type 
sourceType)
                        {
                                if(sourceType == typeof(String))
                                {
                                        return true;
                                }
                                else
                                {
                                        return base.CanConvertFrom(context, 
sourceType);
                                }
                        }

        // Convert from another type to the one represented by this class.
        public override Object ConvertFrom(ITypeDescriptorContext context,
                                                                           
CultureInfo culture,
                                                                           
Object value)
                        {
                                if(value is String)
                                {
                                        String val = (String)value;
                                        if(val.Length == 0)
                                        {
                                                return '\0';
                                        }
                                        else if(val.Length == 1)
                                        {
                                                return val[0];
                                        }
                                }
                                return base.ConvertFrom(context, culture, 
value);
                        }

        // Convert this object into another type.
        public override Object ConvertTo(ITypeDescriptorContext context,
                                                                         
CultureInfo culture,
                                                                         Object 
value, Type destinationType)
                        {
                                if(destinationType == null)
                                {
                                        throw new 
ArgumentNullException("destinationType");
                                }
                                if(destinationType == typeof(String))
                                {
                                        char ch = (char)value;
                                        if(ch != '\0')
                                        {
                                                return new String(ch, 1);
                                        }
                                        else
                                        {
                                                return String.Empty;
                                        }
                                }
                                else
                                {
                                        return base.ConvertTo(context, culture, 
value,
                                                                                
  destinationType);
                                }
                        }

}; // class CharConverter

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

--- NEW FILE ---
/*
 * CollectionConverter.cs - Implementation of the
 *              "System.ComponentModel.ComponentModel.CollectionConverter" 
class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;
using System.Collections;
using System.Globalization;

public class CollectionConverter : TypeConverter
{
        // Constructor.
        public CollectionConverter()
                        {
                                // Nothing to do here.
                        }

        // Convert this object into another type.
        public override Object ConvertTo(ITypeDescriptorContext context,
                                                                         
CultureInfo culture,
                                                                         Object 
value, Type destinationType)
                        {
                                if(destinationType == null)
                                {
                                        throw new 
ArgumentNullException("destinationType");
                                }
                                if(destinationType == typeof(String))
                                {
                                        if(value is ICollection)
                                        {
                                                return "(Collection)";
                                        }
                                }
                                return base.ConvertTo(context, culture, value,
                                                                          
destinationType);
                        }

        // Get the properties for an object.
        public override PropertyDescriptorCollection GetProperties
                                (ITypeDescriptorContext context, Object value,
                                 Attribute[] attributes)
                        {
                                return null;
                        }

        // Determine if the "GetProperties" method is supported.
        public override bool GetPropertiesSupported
                                (ITypeDescriptorContext context)
                        {
                                return false;
                        }

}; // class CollectionConverter

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

--- NEW FILE ---
/*
 * CultureInfoConverter.cs - Implementation of the
 *              "System.ComponentModel.ComponentModel.CultureInfoConverter" 
class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;
using System.Collections;
using System.Globalization;
using System.ComponentModel.Design.Serialization;

public class CultureInfoConverter : TypeConverter
{
        // Constructor.
        public CultureInfoConverter()
                        {
                                // Nothing to do here.
                        }

        // Determine if we can convert from a specific type to this one.
        public override bool CanConvertFrom
                                (ITypeDescriptorContext context, Type 
sourceType)
                        {
                                if(sourceType == typeof(String))
                                {
                                        return true;
                                }
                                else
                                {
                                        return base.CanConvertFrom(context, 
sourceType);
                                }
                        }

        // Determine if we can convert from this type to a specific type.
        public override bool CanConvertTo
                                (ITypeDescriptorContext context, Type 
destinationType)
                        {
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        return true;
                                }
                        #endif
                                return base.CanConvertTo(context, 
destinationType);
                        }

        // Convert from another type to the one represented by this class.
        [TODO]
        public override Object ConvertFrom(ITypeDescriptorContext context,
                                                                           
CultureInfo culture,
                                                                           
Object value)
                        {
                                // TODO
                                return base.ConvertFrom(context, culture, 
value);
                        }

        // Convert this object into another type.
        [TODO]
        public override Object ConvertTo(ITypeDescriptorContext context,
                                                                         
CultureInfo culture,
                                                                         Object 
value, Type destinationType)
                        {
                                if(destinationType == null)
                                {
                                        throw new 
ArgumentNullException("destinationType");
                                }
                                if(destinationType == typeof(String))
                                {
                                        // TODO
                                        return String.Empty;
                                }
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                else if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        // TODO
                                        return null;
                                }
                        #endif
                                else
                                {
                                        return base.ConvertTo
                                                (context, culture, value, 
destinationType);
                                }
                        }

        // Return a collection of standard values for this data type.
        [TODO]
        public override StandardValuesCollection GetStandardValues
                                (ITypeDescriptorContext context)
                        {
                                // TODO
                                return null;
                        }

        // Determine if the list of standard values is an exclusive list.
        public override bool GetStandardValuesExclusive
                                (ITypeDescriptorContext context)
                        {
                                return false;
                        }

        // Determine if "GetStandardValues" is supported.
        public override bool GetStandardValuesSupported
                                (ITypeDescriptorContext context)
                        {
                                return true;
                        }

}; // class CultureInfoConverter

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

--- NEW FILE ---
/*
 * DateTimeConverter.cs - Implementation of the
 *              "System.ComponentModel.ComponentModel.DateTimeConverter" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;
using System.Collections;
using System.Globalization;
using System.ComponentModel.Design.Serialization;

public class DateTimeConverter : TypeConverter
{
        // Constructor.
        public DateTimeConverter()
                        {
                                // Nothing to do here.
                        }

        // Determine if we can convert from a specific type to this one.
        public override bool CanConvertFrom
                                (ITypeDescriptorContext context, Type 
sourceType)
                        {
                                if(sourceType == typeof(String))
                                {
                                        return true;
                                }
                                else
                                {
                                        return base.CanConvertFrom(context, 
sourceType);
                                }
                        }

        // Determine if we can convert from this type to a specific type.
        public override bool CanConvertTo
                                (ITypeDescriptorContext context, Type 
destinationType)
                        {
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        return true;
                                }
                        #endif
                                return base.CanConvertTo(context, 
destinationType);
                        }

        // Convert from another type to the one represented by this class.
        public override Object ConvertFrom(ITypeDescriptorContext context,
                                                                           
CultureInfo culture,
                                                                           
Object value)
                        {
                                if(value is String)
                                {
                                        String val = ((String)value).Trim();
                                        if(val.Length == 0)
                                        {
                                                return DateTime.MinValue;
                                        }
                                        else
                                        {
                                                return DateTime.Parse
                                                        (val, 
DateTimeFormatInfo.GetInstance(culture));
                                        }
                                }
                                return base.ConvertFrom(context, culture, 
value);
                        }

        // Convert this object into another type.
        [TODO]
        public override Object ConvertTo(ITypeDescriptorContext context,
                                                                         
CultureInfo culture,
                                                                         Object 
value, Type destinationType)
                        {
                                if(destinationType == null)
                                {
                                        throw new 
ArgumentNullException("destinationType");
                                }
                                if(destinationType == typeof(String))
                                {
                                        DateTime val = (DateTime)value;
                                        if(val == DateTime.MinValue)
                                        {
                                                return String.Empty;
                                        }
                                        else
                                        {
                                                DateTimeFormatInfo dfi;
                                                String pattern;
                                                dfi = 
DateTimeFormatInfo.GetInstance(culture);
                                                if(val.TimeOfDay.Ticks == 0)
                                                {
                                                        pattern = 
dfi.ShortDatePattern;
                                                }
                                                else
                                                {
                                                        pattern = 
dfi.ShortDatePattern + " " +
                                                                          
dfi.ShortTimePattern;
                                                }
                                                return val.ToString(pattern, 
dfi);
                                        }
                                }
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                else if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        // TODO
                                        return null;
                                }
                        #endif
                                else
                                {
                                        return base.ConvertTo
                                                (context, culture, value, 
destinationType);
                                }
                        }

}; // class DateTimeConverter

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

--- NEW FILE ---
/*
 * GuidConverter.cs - Implementation of the
 *              "System.ComponentModel.ComponentModel.GuidConverter" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;
using System.Collections;
using System.Globalization;
using System.ComponentModel.Design.Serialization;

public class GuidConverter : TypeConverter
{
        // Constructor.
        public GuidConverter()
                        {
                                // Nothing to do here.
                        }

        // Determine if we can convert from a specific type to this one.
        public override bool CanConvertFrom
                                (ITypeDescriptorContext context, Type 
sourceType)
                        {
                                if(sourceType == typeof(String))
                                {
                                        return true;
                                }
                                else
                                {
                                        return base.CanConvertFrom(context, 
sourceType);
                                }
                        }

        // Determine if we can convert from this type to a specific type.
        public override bool CanConvertTo
                                (ITypeDescriptorContext context, Type 
destinationType)
                        {
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        return true;
                                }
                        #endif
                                return base.CanConvertTo(context, 
destinationType);
                        }

        // Convert from another type to the one represented by this class.
        public override Object ConvertFrom(ITypeDescriptorContext context,
                                                                           
CultureInfo culture,
                                                                           
Object value)
                        {
                                if(value is String)
                                {
                                        return new Guid((String)value);
                                }
                                else
                                {
                                        return base.ConvertFrom(context, 
culture, value);
                                }
                        }

        // Convert this object into another type.
        [TODO]
        public override Object ConvertTo(ITypeDescriptorContext context,
                                                                         
CultureInfo culture,
                                                                         Object 
value, Type destinationType)
                        {
                                if(destinationType == null)
                                {
                                        throw new 
ArgumentNullException("destinationType");
                                }
                                if(destinationType == typeof(String))
                                {
                                        return value.ToString();
                                }
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                else if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        // TODO
                                        return null;
                                }
                        #endif
                                else
                                {
                                        return base.ConvertTo
                                                (context, culture, value, 
destinationType);
                                }
                        }

}; // class GuidConverter

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

--- NEW FILE ---
/*
 * ReferenceConverter.cs - Implementation of the
 *              "System.ComponentModel.ComponentModel.ReferenceConverter" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;
using System.Collections;
using System.Globalization;
using System.ComponentModel.Design;

public class ReferenceConverter : TypeConverter
{
        // Internal state.
        private Type type;

        // Constructor.
        public ReferenceConverter(Type type)
                        {
                                this.type = type;
                        }

        // Determine if we can convert from a specific type to this one.
        public override bool CanConvertFrom
                                (ITypeDescriptorContext context, Type 
sourceType)
                        {
                                if(sourceType == typeof(String))
                                {
                                        return true;
                                }
                                else
                                {
                                        return base.CanConvertFrom(context, 
sourceType);
                                }
                        }

        // Convert from another type to the one represented by this class.
        public override Object ConvertFrom(ITypeDescriptorContext context,
                                                                           
CultureInfo culture,
                                                                           
Object value)
                        {
                                if(value is String)
                                {
                                        String val = (String)value;
                                        IReferenceService service;
                                        IContainer container;
                                        if(val == "(none)")
                                        {
                                                return null;
                                        }
                                        if(context != null)
                                        {
                                                service = (IReferenceService)
                                                        
(context.GetService(typeof(IReferenceService)));
                                                if(service != null)
                                                {
                                                        return 
service.GetReference(val);
                                                }
                                                container = context.Container;
                                                if(container != null)
                                                {
                                                        return 
container.Components[val];
                                                }
                                        }
                                        return null;
                                }
                                return base.ConvertFrom(context, culture, 
value);
                        }

        // Convert this object into another type.
        public override Object ConvertTo(ITypeDescriptorContext context,
                                                                         
CultureInfo culture,
                                                                         Object 
value, Type destinationType)
                        {
                                if(destinationType == null)
                                {
                                        throw new 
ArgumentNullException("destinationType");
                                }
                                if(destinationType == typeof(String))
                                {
                                        IReferenceService service;
                                        String name;
                                        if(value == null)
                                        {
                                                return "(none)";
                                        }
                                        if(context != null)
                                        {
                                                service = (IReferenceService)
                                                        
(context.GetService(typeof(IReferenceService)));
                                                if(service != null)
                                                {
                                                        name = 
service.GetName(value);
                                                        if(name != null)
                                                        {
                                                                return name;
                                                        }
                                                }
                                        }
                                        if(value is IComponent)
                                        {
                                                ISite site = 
((IComponent)value).Site;
                                                if(site != null)
                                                {
                                                        name = site.Name;
                                                        if(name != null)
                                                        {
                                                                return name;
                                                        }
                                                }
                                        }
                                        return String.Empty;
                                }
                                else
                                {
                                        return base.ConvertTo
                                                (context, culture, value, 
destinationType);
                                }
                        }

        // Return a collection of standard values for this data type.
        public override StandardValuesCollection GetStandardValues
                                (ITypeDescriptorContext context)
                        {
                                IReferenceService service;
                                Object[] refs;
                                ArrayList list;

                                // Bail out if there is no context.
                                if(context == null)
                                {
                                        return new StandardValuesCollection(new 
Object [] {null});
                                }

                                // Start with a list that contains null.
                                list = new ArrayList();
                                list.Add(null);

                                // Try using the reference service to get the 
values.
                                service = (IReferenceService)
                                        
(context.GetService(typeof(IReferenceService)));
                                if(service != null)
                                {
                                        refs = service.GetReferences();
                                        foreach(Object obj in refs)
                                        {
                                                if(IsValueAllowed(context, obj))
                                                {
                                                        list.Add(obj);
                                                }
                                        }
                                }
                                else if(context.Container != null)
                                {
                                        // Determine the references from the 
context components.
                                        foreach(IComponent component in
                                                                
context.Container.Components)
                                        {
                                                
if(type.IsInstanceOfType(component) &&
                                                   IsValueAllowed(context, 
component))
                                                {
                                                        list.Add(component);
                                                }
                                        }
                                }

                                // Sort the list of references.
                                list.Sort(new ValueComparer(this));

                                // Convert the list into a standard values 
colleciton.
                                return new StandardValuesCollection(list);
                        }

        // Determine if the list of standard values is an exclusive list.
        public override bool GetStandardValuesExclusive
                                (ITypeDescriptorContext context)
                        {
                                return true;
                        }

        // Determine if "GetStandardValues" is supported.
        public override bool GetStandardValuesSupported
                                (ITypeDescriptorContext context)
                        {
                                return true;
                        }

        // Determine if a particular value is allowed.
        protected virtual bool IsValueAllowed
                                        (ITypeDescriptorContext context, Object 
value)
                        {
                                return true;
                        }

        // Compare values in a standard values list.
        private sealed class ValueComparer : IComparer
        {
                // Internal state.
                private ReferenceConverter converter;

                // Constructor.
                public ValueComparer(ReferenceConverter converter)
                                {
                                        this.converter = converter;
                                }

                // Implement the IComparer interface.
                public int Compare(Object obj1, Object obj2)
                                {
                                        return String.CompareOrdinal
                                                
(converter.ConvertToString(obj1),
                                                 
converter.ConvertToString(obj2));
                                }

        }; // class ValueComparer

}; // class ReferenceConverter

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

--- NEW FILE ---
/*
 * SyntaxCheck.cs - Implementation of the
 *              "System.ComponentModel.ComponentModel.SyntaxCheck" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;
using System.IO;

public class SyntaxCheck
{
        // Cannot instantiate this class.
        private SyntaxCheck() {}

        // Perform a syntax check on a machine name.
        public static bool CheckMachineName(String value)
                        {
                                if(value != null)
                                {
                                        value = value.Trim();
                                        if(value.Length == 0)
                                        {
                                                return false;
                                        }
                                        if(value.IndexOf('\\') != -1 ||
                                           value.IndexOf('/') != -1)
                                        {
                                                return false;
                                        }
                                        return true;
                                }
                                else
                                {
                                        return false;
                                }
                        }

        // Perform a syntax check on a network share path.
        public static bool CheckPath(String value)
                        {
                                if(value != null)
                                {
                                        value = value.Trim();
                                        if(value.Length >= 2 &&
                                           (value[0] == '\\' || value[0] == 
'/') &&
                                           (value[1] == '\\' || value[1] == 
'/'))
                                        {
                                                return true;
                                        }
                                        else
                                        {
                                                return false;
                                        }
                                }
                                else
                                {
                                        return false;
                                }
                        }

        // Perform a syntax check on a rooted path.
        public static bool CheckRootedPath(String value)
                        {
                                if(value != null)
                                {
                                        value = value.Trim();
                                        if(value.Length > 0)
                                        {
                                                return Path.IsPathRooted(value);
                                        }
                                        else
                                        {
                                                return false;
                                        }
                                }
                                else
                                {
                                        return false;
                                }
                        }

}; // class SyntaxCheck

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

--- NEW FILE ---
/*
 * TimeSpanConverter.cs - Implementation of the
 *              "System.ComponentModel.ComponentModel.TimeSpanConverter" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;
using System.Collections;
using System.Globalization;
using System.ComponentModel.Design.Serialization;

public class TimeSpanConverter : TypeConverter
{
        // Constructor.
        public TimeSpanConverter()
                        {
                                // Nothing to do here.
                        }

        // Determine if we can convert from a specific type to this one.
        public override bool CanConvertFrom
                                (ITypeDescriptorContext context, Type 
sourceType)
                        {
                                if(sourceType == typeof(String))
                                {
                                        return true;
                                }
                                else
                                {
                                        return base.CanConvertFrom(context, 
sourceType);
                                }
                        }

        // Determine if we can convert from this type to a specific type.
        public override bool CanConvertTo
                                (ITypeDescriptorContext context, Type 
destinationType)
                        {
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        return true;
                                }
                        #endif
                                return base.CanConvertTo(context, 
destinationType);
                        }

        // Convert from another type to the one represented by this class.
        public override Object ConvertFrom(ITypeDescriptorContext context,
                                                                           
CultureInfo culture,
                                                                           
Object value)
                        {
                                if(value is String)
                                {
                                        return 
TimeSpan.Parse(((String)value).Trim());
                                }
                                else
                                {
                                        return base.ConvertFrom(context, 
culture, value);
                                }
                        }

        // Convert this object into another type.
        [TODO]
        public override Object ConvertTo(ITypeDescriptorContext context,
                                                                         
CultureInfo culture,
                                                                         Object 
value, Type destinationType)
                        {
                                if(destinationType == null)
                                {
                                        throw new 
ArgumentNullException("destinationType");
                                }
                                if(destinationType == typeof(String))
                                {
                                        if(value != null)
                                        {
                                                return value.ToString();
                                        }
                                        else
                                        {
                                                return String.Empty;
                                        }
                                }
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                else if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        // TODO
                                        return null;
                                }
                        #endif
                                else
                                {
                                        return base.ConvertTo
                                                (context, culture, value, 
destinationType);
                                }
                        }

}; // class TimeSpanConverter

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

--- NEW FILE ---
/*
 * TypeListConverter.cs - Implementation of the
 *              "System.ComponentModel.ComponentModel.TypeListConverter" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.ComponentModel
{

#if CONFIG_COMPONENT_MODEL

using System;
using System.Collections;
using System.Globalization;
using System.ComponentModel.Design.Serialization;

public class TypeListConverter : TypeConverter
{
        // Internal state.
        private Type[] types;

        // Constructor.
        public TypeListConverter(Type[] types)
                        {
                                this.types = types;
                        }

        // Determine if we can convert from a specific type to this one.
        public override bool CanConvertFrom
                                (ITypeDescriptorContext context, Type 
sourceType)
                        {
                                if(sourceType == typeof(String))
                                {
                                        return true;
                                }
                                else
                                {
                                        return base.CanConvertFrom(context, 
sourceType);
                                }
                        }

        // Determine if we can convert from this type to a specific type.
        public override bool CanConvertTo
                                (ITypeDescriptorContext context, Type 
destinationType)
                        {
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        return true;
                                }
                        #endif
                                return base.CanConvertTo(context, 
destinationType);
                        }

        // Convert from another type to the one represented by this class.
        public override Object ConvertFrom(ITypeDescriptorContext context,
                                                                           
CultureInfo culture,
                                                                           
Object value)
                        {
                                if(value is String)
                                {
                                        String val = (String)value;
                                        if(val == "(none)")
                                        {
                                                return null;
                                        }
                                        if(types != null)
                                        {
                                                foreach(Type t in types)
                                                {
                                                        if(t.FullName == val)
                                                        {
                                                                return t;
                                                        }
                                                }
                                        }
                                }
                                return base.ConvertFrom(context, culture, 
value);
                        }

        // Convert this object into another type.
        [TODO]
        public override Object ConvertTo(ITypeDescriptorContext context,
                                                                         
CultureInfo culture,
                                                                         Object 
value, Type destinationType)
                        {
                                if(destinationType == null)
                                {
                                        throw new 
ArgumentNullException("destinationType");
                                }
                                if(destinationType == typeof(String))
                                {
                                        if(value != null)
                                        {
                                                return ((Type)value).FullName;
                                        }
                                        else
                                        {
                                                return "(none)";
                                        }
                                }
                        #if CONFIG_COMPONENT_MODEL_DESIGN
                                else if(destinationType == 
typeof(InstanceDescriptor))
                                {
                                        // TODO
                                        return null;
                                }
                        #endif
                                else
                                {
                                        return base.ConvertTo
                                                (context, culture, value, 
destinationType);
                                }
                        }

        // Return a collection of standard values for this data type.
        public override StandardValuesCollection GetStandardValues
                                (ITypeDescriptorContext context)
                        {
                                if(types != null)
                                {
                                        return new StandardValuesCollection
                                                ((Type[])(types.Clone()));
                                }
                                else
                                {
                                        return new 
StandardValuesCollection(null);
                                }
                        }

        // Determine if the list of standard values is an exclusive list.
        public override bool GetStandardValuesExclusive
                                (ITypeDescriptorContext context)
                        {
                                return true;
                        }

        // Determine if "GetStandardValues" is supported.
        public override bool GetStandardValuesSupported
                                (ITypeDescriptorContext context)
                        {
                                return true;
                        }

}; // class TypeListConverter

#endif // CONFIG_COMPONENT_MODEL

}; // namespace System.ComponentModel

Index: BaseNumberConverter.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System/ComponentModel/BaseNumberConverter.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** BaseNumberConverter.cs      7 Aug 2003 06:34:29 -0000       1.5
--- BaseNumberConverter.cs      8 Aug 2003 02:56:50 -0000       1.6
***************
*** 80,83 ****
--- 80,84 ----
                                if(val != null)
                                {
+                                       val = val.Trim();
                                        if(val.StartsWith("0x") || 
val.StartsWith("0X") ||
                                           val.StartsWith("&h") || 
val.StartsWith("&H"))

Index: EnumConverter.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/ComponentModel/EnumConverter.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** EnumConverter.cs    29 May 2003 05:38:17 -0000      1.5
--- EnumConverter.cs    8 Aug 2003 02:56:50 -0000       1.6
***************
*** 1,7 ****
  /*
!  * EnumConverter.cs - Implementation of "System.ComponentModel.EnumConverter" 
   *
!  * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
!  * Copyright (C) 2002  Free Software Foundation,Inc.
   *
   * This program is free software; you can redistribute it and/or modify
--- 1,7 ----
  /*
!  * EnumConverter.cs - Implementation of the
!  *            "System.ComponentModel.ComponentModel.EnumConverter" class.
   *
!  * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
***************
*** 19,91 ****
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
-  
- using System;
- using System.Globalization;
- using System.Collections;
  
  namespace System.ComponentModel
  {
  #if CONFIG_COMPONENT_MODEL
!       public class EnumConverter: TypeConverter
!       {
!               private Type type;
! 
!               public EnumConverter(Type type)
!               {
!                       this.type = type;
!               }
! 
!               public override bool CanConvertFrom(ITypeDescriptorContext 
context, 
!                                                                               
        Type sourceType)
!               {
!                       if (sourceType == typeof(string))
                                return true;
!                       /* TODO: Find a better way ? */
!                       return base.CanConvertFrom(context, sourceType);
!               }
! 
!               public override bool CanConvertTo(ITypeDescriptorContext 
context, 
!                                                                               
Type destinationType)
!               {
!                       /* TODO: Find a better way ? */
!                       return base.CanConvertTo(context, destinationType);
!               }
! 
!               [TODO]
!               public override Object ConvertFrom(ITypeDescriptorContext 
context, 
!                                                                               
        CultureInfo culture, Object value)
!               {
!                       /* TODO: Find a better way ? */
!                       string val = value as string;
!                       if (val == null)
!                               return base.ConvertFrom(context, culture, 
value);
!                       string[] values = val.Split(new char[] {','});
!                       object temp;
! 
!                       foreach (string s in values)
!                       {
!                               temp = Enum.Parse(type, s, true);
!                               if (temp != null)
!                                       return temp;
!                       }
!                       return null;
!               }
! 
!               public override Object ConvertTo(ITypeDescriptorContext 
context, 
!                               CultureInfo culture, Object value, Type 
destinationType)
!               {
!                       /* TODO: Find a better way ? */
!                       if (destinationType == typeof(string))
!                               return value.ToString();
!                       return base.ConvertTo(context, culture, value, 
destinationType);
!               }
! 
!               public override bool IsValid(ITypeDescriptorContext context, 
!                                                                       Object 
value)
!               {
!                       return Enum.IsDefined(type, value);
!               }
! 
!       }
! #endif        
! }//namespace
--- 19,188 ----
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  namespace System.ComponentModel
  {
+ 
  #if CONFIG_COMPONENT_MODEL
! 
! using System;
! using System.Collections;
! using System.Globalization;
! using System.ComponentModel.Design.Serialization;
! 
! public class EnumConverter : TypeConverter
! {
!       // Internal state.
!       private Type type;
!       private StandardValuesCollection standardValues;
! 
!       // Constructor.
!       public EnumConverter(Type type)
!                       {
!                               this.type = type;
!                       }
! 
!       // Get a comparer to use to check the values.
!       protected virtual IComparer Comparer
!                       {
!                               get
!                               {
!                                       return Comparer.DefaultInvariant;
!                               }
!                       }
! 
!       // Get the enumerated type underlying this converter.
!       protected Type EnumType
!                       {
!                               get
!                               {
!                                       return type;
!                               }
!                       }
! 
!       // Get or set the standard value list.
!       protected StandardValuesCollection Values
!                       {
!                               get
!                               {
!                                       return standardValues;
!                               }
!                               set
!                               {
!                                       standardValues = value;
!                               }
!                       }
! 
!       // Determine if we can convert from a specific type to this one.
!       public override bool CanConvertFrom
!                               (ITypeDescriptorContext context, Type 
sourceType)
!                       {
!                               if(sourceType == typeof(String))
!                               {
!                                       return true;
!                               }
!                               else
!                               {
!                                       return base.CanConvertFrom(context, 
sourceType);
!                               }
!                       }
! 
!       // Determine if we can convert from this type to a specific type.
!       public override bool CanConvertTo
!                               (ITypeDescriptorContext context, Type 
destinationType)
!                       {
!                       #if CONFIG_COMPONENT_MODEL_DESIGN
!                               if(destinationType == 
typeof(InstanceDescriptor))
!                               {
!                                       return true;
!                               }
!                       #endif
!                               return base.CanConvertTo(context, 
destinationType);
!                       }
! 
!       // Convert from another type to the one represented by this class.
!       public override Object ConvertFrom(ITypeDescriptorContext context,
!                                                                          
CultureInfo culture,
!                                                                          
Object value)
!                       {
!                               if(value is String)
!                               {
!                                       return Enum.Parse(type, (String)value, 
true);
!                               }
!                               else
!                               {
!                                       return base.ConvertFrom(context, 
culture, value);
!                               }
!                       }
! 
!       // Convert this object into another type.
!       [TODO]
!       public override Object ConvertTo(ITypeDescriptorContext context,
!                                                                        
CultureInfo culture,
!                                                                        Object 
value, Type destinationType)
!                       {
!                               if(destinationType == null)
!                               {
!                                       throw new 
ArgumentNullException("destinationType");
!                               }
!                               if(destinationType == typeof(String))
!                               {
!                                       return value.ToString();
!                               }
!                       #if CONFIG_COMPONENT_MODEL_DESIGN
!                               else if(destinationType == 
typeof(InstanceDescriptor))
!                               {
!                                       // TODO
!                                       return null;
!                               }
!                       #endif
!                               else
!                               {
!                                       return base.ConvertTo
!                                               (context, culture, value, 
destinationType);
!                               }
!                       }
! 
!       // Return a collection of standard values for this data type.
!       public override StandardValuesCollection GetStandardValues
!                               (ITypeDescriptorContext context)
!                       {
!                               if(standardValues != null)
!                               {
!                                       return standardValues;
!                               }
!                               Array array = Enum.GetValues(type);
!                               IComparer comparer = Comparer;
!                               if(comparer != null)
!                               {
!                                       Array.Sort(array, 0, array.Length, 
comparer);
!                               }
!                               standardValues = new 
StandardValuesCollection(array);
!                               return standardValues;
!                       }
! 
!       // Determine if the list of standard values is an exclusive list.
!       public override bool GetStandardValuesExclusive
!                               (ITypeDescriptorContext context)
!                       {
!                               // The list is exclusive if it does not contain 
flags.
!                               return !(type.IsDefined(typeof(FlagsAttribute), 
false));
!                       }
! 
!       // Determine if "GetStandardValues" is supported.
!       public override bool GetStandardValuesSupported
!                               (ITypeDescriptorContext context)
!                       {
                                return true;
!                       }
! 
!       // Determine if an object is valid for this type.
!       public override bool IsValid(ITypeDescriptorContext context, Object 
value)
!                       {
!                               return Enum.IsDefined(type, value);
!                       }
! 
! }; // class EnumConverter
! 
! #endif // CONFIG_COMPONENT_MODEL
! 
! }; // namespace System.ComponentModel

Index: TypeConverter.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/ComponentModel/TypeConverter.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** TypeConverter.cs    1 Jun 2003 18:56:24 -0000       1.6
--- TypeConverter.cs    8 Aug 2003 02:56:50 -0000       1.7
***************
*** 289,293 ****
                public StandardValuesCollection (ICollection values)
                {
!                       this.values = values;
                }
  
--- 289,300 ----
                public StandardValuesCollection (ICollection values)
                {
!                       if(values != null)
!                       {
!                               this.values = values;
!                       }
!                       else
!                       {
!                               this.values = new Object [0];
!                       }
                }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]