typeconverter

TypeConverter for serialization

Is it normal practice to use a TypeConverter for serialization? There is a class that I do not own that has a "lossy" TypeConverter. When converting to a string, it formats its floating point data with "G4", so that when this type is displayed in a PropertyGrid, it's easily readable. I would like to also use this TypeConverter to conve...

Can you assign a TypeConverter without a TypeConverterAttribute?

Dependency requirements are forcing me to have a class and its TypeConverter in different assemblies. Is there a way to assign a TypeConverter to a class without using a TypeConverterAttribute, and thus causing circular assembly references. Thanks. ...

How to make a custom TypeConverter for a given type with XmlSerializer?

The question is how to create a custom TypeConverter for a type such as Boolean when de/serializing Xml in C#? <Root> <Flag>True</Flag> </Root> Currently this does not work because the value 'True' has a capital letter. I want the TypeConverter to take care of converting value to a Boolean. I know there are a couple ways to achiev...

convert from short to byte and viceversa in Java

Hi there, I'm trying to convert a short into 2 bytes...and then from those 2 bytes try to get the same short value. For that, I've written this code: short oldshort = 700; byte 333= (byte) (oldshort); byte byte2= (byte) ((oldshort >> 8) short newshort = (short) ((byte2 << 8) + byte1); Sy...

Winforms data binding: Can a TypeConverter be used instead of the Format/Parse events?

In a Winforms form, I want to provide visual cues to the user when an input field contains an invalid value. To that end, I want to bind the ForeColor property of a input field's label to the (boolean) IsPropertyValid property of the underlying model such that the label turns red when IsPropertyValid == false. What I currently have is a...

How to define TypeConverter for enumeration drop down in Propertygrid in Visual C++ Winforms?

I would like to create a drop-down in a propertygrid in Visual C++ where I define text for each item of an enumeration. I cannot seem to find any help for this anywhere - all the help seems to be targeted to C# users and I am unable to convert to Visual C++. I believe I need to create a TypeConverter that converts my enumeration to Strin...

how to convert int to NSTimeInteravl in Objective-C?

Hello, Please do tel me how to convert int to NSTimeInterval? Thank You. ...

Issue with custom TypeConverter and nested properties in the designer

I'm trying to add a nested property to my custom control using a TypeConverter, here is my test code: public class TestNestedOptionConverter : TypeConverter { public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] filter) { return TypeDescriptor.GetPro...

Getting the converter for the type

In the MSDN I've read this about EnumConverter: You should never create an instance of an EnumConverter. Instead, call the GetConverter method of the TypeDescriptor class. For more information, see the examples in the TypeConverter base class. Does anybody know why and is it true for my own implemented converters? For example, I h...

How can I find out, whether a certain type has a string converter attached?

Here is the problem: I have a property of a certain object. This property is of Type t. I need to find out, if a string value can be attached to this property. For example: I have an instance of a Windows.Controls.Button. I need a mechanism, that will return true for property Button.Background, but false for Button.Template. Can anybo...

How to specify a specific type converter for a given property using AutoMapper

How can I override the type converter being used by AutoMapper for a given property? For example, if I have: public class Foo { public string Name { get; set; } } public class Bar { public string Name { get; set; } } Now I simply want to map Foo.Name to Bar.Name but using a specified type converter. I see how I can do it usi...

MVC 2 & TypeConverters, Get the destination type in ConvertFrom where the context is null

I have a TypeConverter on the base class in my project. [TypeConverter(typeof(CodeTypeConverter))] abstract class CodeBase I have a number of classes which inherit this base class TitleCode : CodeBase class PreferenceCode : CodeBase When the thing that calls the type converter (ValueProvider.ConvertSimpleType) it does not create a ...

How can I save the values entered at design time for a complex property?

I'm still learning the ropes when it comes to implementing custom editors for complex properties at design time. As a simple starting point, I'm trying to enable design-time editing of a property of type ICollection<string>. What I've done so far is: Wrote a StringsEditor class, which derives from UITypeEditor and displays a drop-dow...

StringConverter GetStandardValueCollection

I am trying to use property grid for displaying data. I have to write StringConverters for my predefined string constants so that they can be shown on a combo box. Consider a list of colors and another list of angles 0,90,180,270. There are many such lists I want to display on the grid. I am writing new classes deriving from StringCo...