private global::Debugging.CustomType ConvertFromStringToCustomType(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, string value)
        {
            CustomType ct = new CustomType();

            string[] values = value.Split(',');
            if (values.Length != 3)
            {
                throw new ArgumentException("Invalid input string");
            }

            foreach (string val in values)
            {
                string[] keyValue = val.Split(':');
                switch (keyValue[0].Trim().ToUpper())
                {
                case "H":
                    ct.Height = int.Parse(keyValue[1]);
                    break;

                case "W":
                    ct.Width = int.Parse(keyValue[1]);
                    break;

                case "D":
                    ct.Depth = int.Parse(keyValue[1]);
                    break;

                default:
                    throw new ArgumentException("Invalid input string");
                }
            }

            return(ct);
        }
 /// <summary>
 /// Converts the class object representation of the custom type into a compatible string.
 ///
 /// The RectangleTypeConverter partial class contained in the GENERATED code has a method called "ConvertTo".
 /// This "ConvertTo" method makes a call to "ConvertToRectangleFromString". We actually implement the
 /// "ConvertToRectangleFromString" method here.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="culture"></param>
 /// <param name="value"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 private string ConvertToCustomBlockFromString(
     global::System.ComponentModel.ITypeDescriptorContext context,
     global::System.Globalization.CultureInfo culture,
     global::Samples.Configuration.ExternalTypes.CustomBlock value,
     global::System.Type type)
 {
     return(string.Format("H: {0}, W: {1}, D: {2}", value.Height, value.Width, value.Depth));
 }
Exemplo n.º 3
0
 public override object ConvertTo(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, object value, global::System.Type type)
 {
     // IMPORTANT NOTE: The code below does not build by default.
     // This is a custom type validator that must be implemented
     // for it to build. Place the following in a separate file
     // and implement the method.
     //
     // public partial class CustomBlockTypeConverter
     // {
     //
     //     private string ConvertToCustomBlockFromString(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::Samples.Configuration.ExternalTypes.CustomBlock value, global::System.Type type)
     //     {
     //         return value.ToString();
     //     }
     // }
     //
     return(this.ConvertToCustomBlockFromString(context, culture, ((global::Samples.Configuration.ExternalTypes.CustomBlock)(value)), type));
 }
 public override object ConvertFrom(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, object value)
 {
     // IMPORTANT NOTE: The code below does not build by default.
     // This is a custom type validator that must be implemented
     // for it to build. Place the following in a separate file
     // and implement the method.
     //
     // public partial class CustomTypeTypeConverter
     // {
     //
     //     private global::Debugging.CustomType ConvertFromStringToCustomType(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, string value)
     //     {
     //         throw new global::System.NotImplementedException();
     //     }
     // }
     //
     return(this.ConvertFromStringToCustomType(context, culture, ((string)(value))));
 }
 private string ConvertToCustomTypeFromString(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::Debugging.CustomType value, global::System.Type type)
 {
     return(string.Format("H: {0}, W: {1}, D: {2}", value.Height, value.Width, value.Depth));
 }
 private global::MichaelFramework.Utils.PaneState ConvertFromStringToPaneState(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, string value)
 {
     MichaelFramework.Utils.PaneState ps = new MichaelFramework.Utils.PaneState();
     string[] s = value.Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);
     ps.Visible       = bool.Parse(s[1].Trim());
     ps.Expanded      = bool.Parse(s[3].Trim());
     ps.WidthOrHeight = int.Parse(s[5].Trim());
     return(ps);
 }
 private string ConvertToPaneStateFromString(global::System.ComponentModel.ITypeDescriptorContext context, global::System.Globalization.CultureInfo culture, global::MichaelFramework.Utils.PaneState value, global::System.Type type)
 {
     return(string.Format("Visible={0},Expanded={1},WidthOrHeight={2}", value.Visible, value.Expanded, value.WidthOrHeight));
 }