473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TypeConverter.C reateInstance How does it works

Hi all
i have a class that i have made and i made an Typeconverter as well, and my
problem is
the code genereated in my form is

Dim ClassTest1 As TestApplication .ClassTest = New TestApplication .ClassTest
Me.MyClassTest = ClassTest1

Wich is quite good, but my problem is in my property browser i cannot change
any of my properties
' need the "DesignerSerial izationVisibili ty " this in visible because this
is a form that must be inherited and i don´t want this property tobe writen
in the child form. unless it was changed in the child form .

i have declare my property like this

<LocalizableAtt ribute(True), _
Browsable(True) , _
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Visible), _
MergablePropert y(False)> _
Public Property MyClassTest() As ClassTest
Get
Return xMyClassTest
End Get
Set(ByVal Value As ClassTest)
xMyClassTest = Value
xMyClassTest_Ch angedProperty()
End Set
End Property
please see the code below

<System.Compone ntModel.TypeCon verter(GetType( ClassTypeConver ter)), _
EditorBrowsable (EditorBrowsabl eState.Always), _
Serializable()> _
Public Class ClassTest
Inherits System.MarshalB yRefObject
Implements System.IDisposa ble
Private xText As String = "Texto"
Private xColor As System.Drawing. Color = Color.Red
Public Event ChangedProperty ()
Event testesss As EventHandler
Public Property Text() As String
Get
Return xText
End Get
Set(ByVal Value As String)
xText = Value
RaiseEvent ChangedProperty ()
End Set
End Property
Public Property Color() As System.Drawing. Color
Get
Return xColor
End Get
Set(ByVal Value As System.Drawing. Color)
xColor = Value
RaiseEvent ChangedProperty ()
End Set
End Property
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Color() As Boolean
Return Not Me.Color.Equals (Color.Red)
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetColor()
Me.Color = Color.Red
End Sub
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Text() As Boolean
Return Me.Text <> "Texto"
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetText()
xText = "Texto"
End Sub

Public Sub Dispose() Implements System.IDisposa ble.Dispose
xColor = Nothing
End Sub
End Class
' Type Converter Class
Imports System.Reflecti on
Imports System.Componen tModel
Imports System
Imports System.Drawing
Imports System.Drawing. Design
Imports System.Componen tModel.Design.S erialization
Public Class ClassTypeConver ter
Inherits ExpandableObjec tConverter
Public Overloads Overrides Function CanConvertTo(By Val context As
System.Componen tModel.ITypeDes criptorContext, ByVal destinationType As
System.Type) As Boolean
Try
If destinationType Is GetType(Instanc eDescriptor) Then
Return True
End If
Return MyBase.CanConve rtTo(context, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro CanConvertTo " & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Try
If destinationType Is Nothing Then
Throw New ArgumentNullExc eption("Argumen tos Invalidos")
End If
If destinationType Is GetType(Instanc eDescriptor) Then
Dim ci As ConstructorInfo =
GetType(ClassTe st).GetConstruc tor(Type.EmptyT ypes)
Return New InstanceDescrip tor(ci, Nothing, False)
End If
Return MyBase.ConvertT o(context, culture, value, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro ConvertTo" & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function CreateInstance( ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal propertyValues As
System.Collecti ons.IDictionary ) As Object
Return New ClassTest 'Activator.Crea teInstance(GetT ype(ClassTest))
End Function
Public Overloads Overrides Function GetCreateInstan ceSupported(ByV al context
As System.Componen tModel.ITypeDes criptorContext) As Boolean
Return True
End Function

End Class
Nov 21 '05 #1
2 3813
hi there ,,
just try to put aonther property in your MyProperty structure but not add it
to the constructor.
and then try to change the vaule at design time. :(
thsk
JSB

"joeycalisa y" <hcalisay@_spam killer_codex-systems.com> wrote in message
news:uX******** ******@TK2MSFTN GP10.phx.gbl...
sorry but i cannot do a vb.net equivalent.

try to browse my attached example to get some ideas...

--
Joey Calisay
http://spaces.msn.com/members/joeycalisay/
"João Santa Bárbara" <jo****@i24port ugal.com> wrote in message
news:eD******** ******@tk2msftn gp13.phx.gbl...
Hi all
i have a class that i have made and i made an Typeconverter as well, and

my
problem is
the code genereated in my form is

Dim ClassTest1 As TestApplication .ClassTest = New

TestApplication .ClassTest
Me.MyClassTest = ClassTest1

Wich is quite good, but my problem is in my property browser i cannot

change
any of my properties
' need the "DesignerSerial izationVisibili ty " this in visible because

this
is a form that must be inherited and i don´t want this property tobe

writen
in the child form. unless it was changed in the child form .

i have declare my property like this

<LocalizableAtt ribute(True), _
Browsable(True) , _
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Visible),

_
MergablePropert y(False)> _
Public Property MyClassTest() As ClassTest
Get
Return xMyClassTest
End Get
Set(ByVal Value As ClassTest)
xMyClassTest = Value
xMyClassTest_Ch angedProperty()
End Set
End Property
please see the code below

<System.Compone ntModel.TypeCon verter(GetType( ClassTypeConver ter)), _
EditorBrowsable (EditorBrowsabl eState.Always), _
Serializable()> _
Public Class ClassTest
Inherits System.MarshalB yRefObject
Implements System.IDisposa ble
Private xText As String = "Texto"
Private xColor As System.Drawing. Color = Color.Red
Public Event ChangedProperty ()
Event testesss As EventHandler
Public Property Text() As String
Get
Return xText
End Get
Set(ByVal Value As String)
xText = Value
RaiseEvent ChangedProperty ()
End Set
End Property
Public Property Color() As System.Drawing. Color
Get
Return xColor
End Get
Set(ByVal Value As System.Drawing. Color)
xColor = Value
RaiseEvent ChangedProperty ()
End Set
End Property
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Color() As Boolean
Return Not Me.Color.Equals (Color.Red)
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetColor()
Me.Color = Color.Red
End Sub
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Text() As Boolean
Return Me.Text <> "Texto"
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetText()
xText = "Texto"
End Sub

Public Sub Dispose() Implements System.IDisposa ble.Dispose
xColor = Nothing
End Sub
End Class
' Type Converter Class
Imports System.Reflecti on
Imports System.Componen tModel
Imports System
Imports System.Drawing
Imports System.Drawing. Design
Imports System.Componen tModel.Design.S erialization
Public Class ClassTypeConver ter
Inherits ExpandableObjec tConverter
Public Overloads Overrides Function CanConvertTo(By Val context As
System.Componen tModel.ITypeDes criptorContext, ByVal destinationType As
System.Type) As Boolean
Try
If destinationType Is GetType(Instanc eDescriptor) Then
Return True
End If
Return MyBase.CanConve rtTo(context, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro CanConvertTo " & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Try
If destinationType Is Nothing Then
Throw New ArgumentNullExc eption("Argumen tos Invalidos")
End If
If destinationType Is GetType(Instanc eDescriptor) Then
Dim ci As ConstructorInfo =
GetType(ClassTe st).GetConstruc tor(Type.EmptyT ypes)
Return New InstanceDescrip tor(ci, Nothing, False)
End If
Return MyBase.ConvertT o(context, culture, value, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro ConvertTo" & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function CreateInstance( ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal propertyValues As
System.Collecti ons.IDictionary ) As Object
Return New ClassTest 'Activator.Crea teInstance(GetT ype(ClassTest))
End Function
Public Overloads Overrides Function GetCreateInstan ceSupported(ByV al

context
As System.Componen tModel.ITypeDes criptorContext) As Boolean
Return True
End Function

End Class


Nov 21 '05 #2
and why would you not add it to the constructor of the struct? I believe
you have to because you will be instructing your TypeConverter which
constructor to use and if you will be using the old one (my two parameter
constructor), how will you serialize the value for the additional property?
Perhaps you can customize that with a custom CodeDom but it will be really
easier (and practical IMO) if your constructor (which the typeconverter will
use) properly initializes your struct instance...

--
Joey Calisay
http://spaces.msn.com/members/joeycalisay/
"João Santa Bárbara" <jo****@i24port ugal.com> wrote in message
news:uo******** ******@TK2MSFTN GP14.phx.gbl...
hi there ,,
just try to put aonther property in your MyProperty structure but not add it to the constructor.
and then try to change the vaule at design time. :(
thsk
JSB

"joeycalisa y" <hcalisay@_spam killer_codex-systems.com> wrote in message
news:uX******** ******@TK2MSFTN GP10.phx.gbl...
sorry but i cannot do a vb.net equivalent.

try to browse my attached example to get some ideas...

--
Joey Calisay
http://spaces.msn.com/members/joeycalisay/
"João Santa Bárbara" <jo****@i24port ugal.com> wrote in message
news:eD******** ******@tk2msftn gp13.phx.gbl...
Hi all
i have a class that i have made and i made an Typeconverter as well,
and my
problem is
the code genereated in my form is

Dim ClassTest1 As TestApplication .ClassTest = New

TestApplication .ClassTest
Me.MyClassTest = ClassTest1

Wich is quite good, but my problem is in my property browser i cannot

change
any of my properties
' need the "DesignerSerial izationVisibili ty " this in visible because

this
is a form that must be inherited and i don´t want this property tobe

writen
in the child form. unless it was changed in the child form .

i have declare my property like this

<LocalizableAtt ribute(True), _
Browsable(True) , _
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Visible), _
MergablePropert y(False)> _
Public Property MyClassTest() As ClassTest
Get
Return xMyClassTest
End Get
Set(ByVal Value As ClassTest)
xMyClassTest = Value
xMyClassTest_Ch angedProperty()
End Set
End Property
please see the code below

<System.Compone ntModel.TypeCon verter(GetType( ClassTypeConver ter)), _
EditorBrowsable (EditorBrowsabl eState.Always), _
Serializable()> _
Public Class ClassTest
Inherits System.MarshalB yRefObject
Implements System.IDisposa ble
Private xText As String = "Texto"
Private xColor As System.Drawing. Color = Color.Red
Public Event ChangedProperty ()
Event testesss As EventHandler
Public Property Text() As String
Get
Return xText
End Get
Set(ByVal Value As String)
xText = Value
RaiseEvent ChangedProperty ()
End Set
End Property
Public Property Color() As System.Drawing. Color
Get
Return xColor
End Get
Set(ByVal Value As System.Drawing. Color)
xColor = Value
RaiseEvent ChangedProperty ()
End Set
End Property
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Color() As Boolean
Return Not Me.Color.Equals (Color.Red)
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetColor()
Me.Color = Color.Red
End Sub
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Text() As Boolean
Return Me.Text <> "Texto"
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetText()
xText = "Texto"
End Sub

Public Sub Dispose() Implements System.IDisposa ble.Dispose
xColor = Nothing
End Sub
End Class
' Type Converter Class
Imports System.Reflecti on
Imports System.Componen tModel
Imports System
Imports System.Drawing
Imports System.Drawing. Design
Imports System.Componen tModel.Design.S erialization
Public Class ClassTypeConver ter
Inherits ExpandableObjec tConverter
Public Overloads Overrides Function CanConvertTo(By Val context As
System.Componen tModel.ITypeDes criptorContext, ByVal destinationType As
System.Type) As Boolean
Try
If destinationType Is GetType(Instanc eDescriptor) Then
Return True
End If
Return MyBase.CanConve rtTo(context, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro CanConvertTo " & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Try
If destinationType Is Nothing Then
Throw New ArgumentNullExc eption("Argumen tos Invalidos")
End If
If destinationType Is GetType(Instanc eDescriptor) Then
Dim ci As ConstructorInfo =
GetType(ClassTe st).GetConstruc tor(Type.EmptyT ypes)
Return New InstanceDescrip tor(ci, Nothing, False)
End If
Return MyBase.ConvertT o(context, culture, value, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro ConvertTo" & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function CreateInstance( ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal propertyValues As
System.Collecti ons.IDictionary ) As Object
Return New ClassTest 'Activator.Crea teInstance(GetT ype(ClassTest))
End Function
Public Overloads Overrides Function GetCreateInstan ceSupported(ByV al

context
As System.Componen tModel.ITypeDes criptorContext) As Boolean
Return True
End Function

End Class



Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2195
by: João Santa Bárbara | last post by:
Hi all i have a class that i have made and i made an Typeconverter as well, and my problem is the code genereated in my form is Dim ClassTest1 As TestApplication.ClassTest = New TestApplication.ClassTest Me.MyClassTest = ClassTest1 Wich is quite good, but my problem is in my property browser i cannot change any of my properties
0
1238
by: João Santa Bárbara | last post by:
Hi all i have a class that i have made and i made an Typeconverter as well, and my problem is the code genereated in my form is Dim ClassTest1 As TestApplication.ClassTest = New TestApplication.ClassTest Me.MyClassTest = ClassTest1 Wich is quite good, but my problem is in my property browser i cannot change any of my properties
2
3419
by: kw | last post by:
I'm getting different behavior from what I would expect and was hoping someone could clue me in. At run time I need to examine a property of an object for a custom TypeConverter, then use that converter on a value. Here's the deal: object attrs=(object)PropertyInfo.GetCustomAttributes(typeof(TypeConverterAttribu te),false);
1
1702
by: Sky Sigal | last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols) I've been looking lately for a way to keep the Properties panel for Controls 'clean'... My goal is to keep similar public properties of a custom Control neatly tied together -- rather than all over the IDE. One such set of values that will rarely be changed, so should have little priority in the IDE Properties panel, and therefore a good candidate for
3
1428
by: Oskar Vaia | last post by:
Hi, in the .NET Framework Class Library there is the following text in the "Remarks"-section: "Use this method for objects that are immutable, but for which you want to provide changeable properties." .... objects that are immutable ... - what does this mean? Can someone please insert here an example?
0
1195
by: Alex Clark | last post by:
Hi all, Apologies for the cross-post but I can't determine if this is a VS .NET problem or a VB.NET language issue. I'm using .NET 1.1 SP1, VS 2003 EA, VB.NET. I'm coding a custom component which is designed to be dropped onto a form and have it's properties manipulated at runtime. I have a custom implementation of the TypeConverter class called UniversalTypeConverter which inherits from ExpandableObjectConverter, and for the most...
1
1483
by: Matthias Heise | last post by:
Hello everybody, I have a problem towards the following topic. There is a class like MyColor and a class like MyRectangle that has a property called FillColor which is of type MyColor. Now it should be able to say MyRectangle rect1 = new MyRectangle(); rect1.FillColor = "Red";
4
1701
by: swartzbill2000 | last post by:
Hello, I have a TypeConverter for converting between this Enum and Strings. Public Enum DeviceNameEnum dnNone dn2500 dnMirror End Enum 'DeviceNameEnum
11
2345
by: Rolf Welskes | last post by:
Hello, the problem seems to be complex and is in all developments of web-controls which uses own TypeConverter. For this I have here a simple demo-program of the problem: The Control-code: A class MyString which is a class which is similar to a string public class MyString {
6
3892
by: Larry Smith | last post by:
Hi there, Can anyone provide any insight on why MSFT introduced "TypeConverter.GetProperties()". There are two classes for dealing with metadata in .NET, 'Type" and "TypeDescriptor". Each has a "GetProperites()" method so why complicate the situation even more than it already is by adding a "GetProperties()" method to "TypeConverter". The class is supposed to be for converting types so "GetProperties()" seems misplaced and redundant (as...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.