473,569 Members | 2,788 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 3799
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
2181
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
1229
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
3407
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
1420
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
1187
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
1476
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
1693
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
2326
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
3883
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...
0
7697
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
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8120
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
6283
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
5512
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
5219
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...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
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
937
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.