ConvertToInvariantString() public method

public ConvertToInvariantString ( ITypeDescriptorContext context, object value ) : string
context ITypeDescriptorContext
value object
return string
Exemplo n.º 1
0
    //</snippet2>

    // The following code example demonstrates how to use the
    // ConvertToInvariantString and ConvertToString methods.
    // This example is designed to be used with Windows Forms.
    // Paste this code into a form and call the ShowFontStringConversion
    // method when handling the form's Paint event, passing e
    // as PaintEventArgs.
    //<snippet3>
    private void ShowFontStringConversion(PaintEventArgs e)
    {
        // Create the FontConverter.
        System.ComponentModel.TypeConverter converter =
            System.ComponentModel.TypeDescriptor.GetConverter(typeof(Font));

        Font font1 = (Font)converter.ConvertFromString("Arial, 12pt");

        string fontName1 = converter.ConvertToInvariantString(font1);
        string fontName2 = converter.ConvertToString(font1);

        e.Graphics.DrawString(fontName1, font1, Brushes.Red, 10, 10);
        e.Graphics.DrawString(fontName2, font1, Brushes.Blue, 10, 30);
    }
Exemplo n.º 2
0
        private IPropertyChooser CreateChooserForProperty(PropertyInfo pi, object target)
        {
            IPropertyChooser chooser = null;

            if (pi.PropertyType == typeof(string))
                chooser = new StringChooser();

            else if (pi.PropertyType.IsEnumType())
                chooser = new EnumeratedTypeChooser(pi.PropertyType);

            else if (pi.PropertyType.IsIntegerType())
                chooser = new IntegerChooser(pi.PropertyType);
            
            else if (pi.PropertyType == typeof(bool))
                chooser = new BooleanChooser();
            
            else
                chooser = new StringChooser();

            if (chooser != null)
            {
                object val = pi.GetValue(target, null);

                TypeConverter tc = new TypeConverter();

                chooser.PropertyName = pi.Name;
                chooser.PropertyValue = val == null ?
                    Translator.Translate("TXT_NA") : tc.ConvertToInvariantString(val);
            }

            return chooser;
        }
Exemplo n.º 3
0
 private static string ConvertToString(TypeConverter typeConverter, object val)
 {
     return typeConverter.ConvertToInvariantString(val);
 }