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
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