473,585 Members | 2,550 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
Jul 21 '05 #1
2 2186
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


Jul 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



Jul 21 '05 #3

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

Similar topics

0
1232
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
3409
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
1691
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...
3
1421
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?
2
3801
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
1188
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...
1
1478
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";
5
4950
by: ismail.mayat | last post by:
Hello, I am having a problem with Activator.CreateInstance. I have the following code Assembly asm = System.Reflection.Assembly.LoadFrom(assembly); if(asm!=null) { try {
11
2332
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 {
0
7904
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8195
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. ...
0
8334
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...
0
8209
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...
0
6596
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...
1
5707
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...
0
3831
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...
1
2340
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
0
1171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.