From: Mr. X. on
Wow !!!
Great.
Some of the syntax - I didn't know till now (I.e aggregate).
Right now I am testing it,

I see that not of the properties have typeConverter, and I do some check
such as whether property.PropertyType.IsEnum.
I don't know if only properties that their type is ENum don't have
typeConverter.
I have to change my code, in order to check this out - I would let you know
if this totally solved my problem.

Thank you.
I appreciate your efforts. I think I would spend years, if you didn't tell
me that basics.

Thanks :)

"Armin Zingler" <az.nospam(a)freenet.de> wrote in message
news:uE9TpfZELHA.5668(a)TK2MSFTNGP04.phx.gbl...
> Am 21.06.2010 19:54, schrieb Mr. X.:
>> Sorry for being annoying.
>> And thanks you a lot for being so polite, and patient.
>>
>> I look at : How to: Implement a Type Converter.
>> It seems to tell me how to implement a type converter, so I need to do
>> the
>> conversion by myself finally (at the bottom line),
>> that's a thing I try to avid (I need to have more general solution).
>> Maybe I am wrong, but I don't think it's a good solution, that make
>> things
>> easier.
>
>
> You are not annoying! It would just be nice if you'd look at some
> things more thoroughly. Otherwise it's sometimes hard to help. Sure, we
> need challenges to develop (ourselves) but I suggest you making smaller
> steps before trying to accomplish the big picture. I always play around
> with things in test projects before putting it in the actual one.
>
> The information I took from the documentation was how to _use_ a type
> converter. I din't write one. I think you've only overlooked my other
> reply (from 15:56) with the 7 steps. I've tried it with the Location
> property
> (type Point). The type Point has a TypeConverterAttribute attached. It
> tells
> me that a PointConverter is available for conversion. An instance of it
> successfully converts Point<->String.
>
>
>> I get the whole thing from start :
>> =====================
>> I am doing a mini-IDE, save it to database (I succeeded doing so, as your
>> advice),
>> but retrieving it may be a problem.
>> (Maybe I should disable some properties, somehow).
>> I cannot put on database, something which is not string (an object).
>> The objects are not serializable (and there may be many elements).
>> So I am using reflection.
>> When retrieving - I have several objects, which I know only their names
>> and
>> properties names, and also the properties values.
>> For an object with 50 properties, and there are several objects, it is
>> almost impossible to make a translation for every property,
>> so I need to do something generic.
>
> Maybe you should first determine what _you_ want to store in your database
> for each kind of property type.
>
> In the end all types are made of value types, so I'd first determine how
> to
> store them, then recursively store all referenced objects. Just my 2c - I
> haven't done anything like that, yet. Be aware that there can be also
> public
> (and private) fields.
>
> Everything depends on the whole task! I don't have a general solution for
> this.
> I think nobody has. There _are_ general concepts like serialization and
> other
> design time support like the BrowsableAttribute, type converters, the
> DesignerSerializationVisibility attribute and so on. Apart from this,
> there are no
> general solutions for the task you're trying to accomplish. You must deal
> with
> each "what if..." on your own.
> And sometimes there are good reasons why objects are not serializable.
>
> There is nothing more I can say about it.
>
>
>> Maybe I don't understand, but I didn't find any samples around the
>> internet,
>> that don't have to override the base thing : convertFrom, and convertTo.
>
> No need to override them. Use the existing converters and just call their
> functions.
>
>
>
> Here's an example about type converters. It is not bullet proof code and
> it is not meant to be a solution to all your missions: ;-)
>
>
> Imports System.Reflection
> Imports System.ComponentModel
> '....
>
> Dim ctl As New Control
>
> Dim t = ctl.GetType
>
> For Each prop In t.GetProperties(BindingFlags.Public Or
> BindingFlags.Instance)
> If prop.CanRead AndAlso prop.CanWrite AndAlso
> prop.GetIndexParameters.Length = 0 Then
> For Each att As System.Attribute In
> prop.PropertyType.GetCustomAttributes(True)
> Dim convAtt = TryCast(att, TypeConverterAttribute)
>
> If convAtt IsNot Nothing Then
> Dim convType = Type.GetType(convAtt.ConverterTypeName)
>
> Dim ctorCount = Aggregate count In _
> From ctor In convType.GetConstructors _
> Where ctor.GetParameters.Count = 0 _
> Into Count()
>
> If ctorCount = 1 Then
> Dim Converter =
> TryCast(Activator.CreateInstance(convType), TypeConverter)
>
> If Converter IsNot Nothing Then
> Dim value = prop.GetValue(ctl, Nothing)
>
> Debug.Write(prop.Name & ": ")
> Debug.WriteLine(Converter.ConvertToString(value))
> End If
> End If
> End If
> Next
> End If
> Next
>
>
> --
> Armin

From: Mr. X. on
Great.
One issue - I need to do converter.ConvertToString(aType) when aType is
color, I.e (known only on runtime).

How can I pass a parameter to convertToString, when aType is, I.e., Color ?
If I declare
(When I.e the property that is searched is of type : color)
dim c as color
dim s as string
c = Red
s = converter.ConvertToString (c )
The above works !

but when I do :
dim c
c = color.red
s = converter.ConvertToString( c)
the above doesn't work !
I didn't find a way to pass the correct type to converter.ConvertString
I cannot declare a variable, which is known.
I have tried something like
c = tryCast(property.getValue(myControl, nothing), property.propertyType) '
this is not compiled !!!

Thanks :)


From: Mr. X. on
I'll ask that on separated thread ...

Thanks :)

"Mr. X." <nospam(a)nospam_please.com> wrote in message
news:OiuZ8QdELHA.1996(a)TK2MSFTNGP06.phx.gbl...
> Great.
> One issue - I need to do converter.ConvertToString(aType) when aType is
> color, I.e (known only on runtime).
>
> How can I pass a parameter to convertToString, when aType is, I.e., Color
> ?
> If I declare
> (When I.e the property that is searched is of type : color)
> dim c as color
> dim s as string
> c = Red
> s = converter.ConvertToString (c )
> The above works !
>
> but when I do :
> dim c
> c = color.red
> s = converter.ConvertToString( c)
> the above doesn't work !
> I didn't find a way to pass the correct type to converter.ConvertString
> I cannot declare a variable, which is known.
> I have tried something like
> c = tryCast(property.getValue(myControl, nothing), property.propertyType)
> ' this is not compiled !!!
>
> Thanks :)
>
>