Prev: Reminder - Microsoft Responds to the Evolution of Community
Next: Use the propertyInfo to setValues
From: Mr. X. on 21 Jun 2010 07:02 Hello. I want to set to any type the value, by sending its string only. How can I do that ? I.e BorderStyle = "None" (I have "None" value as a string) Thanks :)
From: Armin Zingler on 21 Jun 2010 07:26 Am 21.06.2010 13:02, schrieb Mr. X.: > Hello. > I want to set to any type the value, by sending its string only. > How can I do that ? > > I.e > BorderStyle = "None" > (I have "None" value as a string) http://msdn.microsoft.com/en-us/library/ms171838(VS.90).aspx -- Armin
From: Mr. X. on 21 Jun 2010 08:52 I need to not create type editor for each type. The specific type is unknown, and I need a generic solution for any type. Thanks :) "Armin Zingler" <az.nospam(a)freenet.de> wrote in message news:uqgIyXTELHA.588(a)TK2MSFTNGP06.phx.gbl... > Am 21.06.2010 13:02, schrieb Mr. X.: >> Hello. >> I want to set to any type the value, by sending its string only. >> How can I do that ? >> >> I.e >> BorderStyle = "None" >> (I have "None" value as a string) > > http://msdn.microsoft.com/en-us/library/ms171838(VS.90).aspx > > > -- > Armin
From: Armin Zingler on 21 Jun 2010 08:56 Am 21.06.2010 13:26, schrieb Armin Zingler: > Am 21.06.2010 13:02, schrieb Mr. X.: >> Hello. >> I want to set to any type the value, by sending its string only. >> How can I do that ? >> >> I.e >> BorderStyle = "None" >> (I have "None" value as a string) > > http://msdn.microsoft.com/en-us/library/ms171838(VS.90).aspx I guess you will ask... To create a TypeConverter: 1. Get the type of the property (PropertyInfo.PropertyType) 2. Check the attributes of the type retrived in step 1. 3. If there is a System.ComponentModel.TypeConverterAttribute, get it's 'ConverterTypeName' property. 4. Pass the name from step 3 to System.Type.GetType 5. Create an instance of the type from step 4 by passing it to Activator.CreateInstance 6. Cast the object from step 5 to System.ComponentModel.TypeConverter. (Before, I'd check if it's really of that type. Just for safety, because I think the constructor of TypeConverterAttribute doesn't check the passed type.) 7. Read the documentation about the TypeConverter. :-) The ConvertFromString/ConvertToString methods seem to do the main job. I've never done all that. But that's how I'd do it. -- Armin
From: Armin Zingler on 21 Jun 2010 09:08 Am 21.06.2010 14:52, schrieb Mr. X.: > I need to not create type editor for each type. > The specific type is unknown, and I need a generic solution for any type. Man, I'm really patient. Very patient. Usually. But you guy seem to be not willing first to learn the things you need for your task. I don't believe you have already studied the topics in the link I gave you. The first line in the first sub topic says: "You can edit your property in place as a string. This requires a TypeConverter for your custom type. For more information, see How to: Implement a Type Converter." Isn't it what you are looking for? You ask for a general solution. There is not solution that is more general than described in the documentation. The TypeConverterAttribute is the most general solution I know of. I'm not talking about UI type editors here. -- Armin
|
Next
|
Last
Pages: 1 2 3 Prev: Reminder - Microsoft Responds to the Evolution of Community Next: Use the propertyInfo to setValues |