473,394 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Custom Cast

I know vb.net does not support operator overloading... I want to creat
a simple custom casting... this will just take the public members of
one class, and assign their values to public members of another
class... methods and functions are ignored...

class type1
public value1, value2, value3
end class

class type2
public value1, value2, value3
end class

i want to make a function that does this:

dim t2 as new type2
t2.value1 = "this is value 1 in t2"
t2.value2 = "this is value 2 in t2"
t2.value3 = "this is value 3 in t2"

dim t1 as type1 = ChangeType(t2, Type1)

now, t1's value1, value2 and value3, will contain the same information
as in t2's...

Just as simple as that... Don't want complicated matter...

Note: ChangeType function is independent of class passed to it. it can
accept any classes, as long as they have members that match members in
converted class... if corresponding name is not found in the
destination class, then that member is ignored...

Thanks for your help in advance...

Jul 21 '05 #1
1 1565
tascien <ta******@ecoaches.com> wrote:
I know vb.net does not support operator overloading... I want to creat
a simple custom casting... this will just take the public members of
one class, and assign their values to public members of another
class... methods and functions are ignored...

class type1
public value1, value2, value3
end class

class type2
public value1, value2, value3
end class

i want to make a function that does this:

dim t2 as new type2
t2.value1 = "this is value 1 in t2"
t2.value2 = "this is value 2 in t2"
t2.value3 = "this is value 3 in t2"

dim t1 as type1 = ChangeType(t2, Type1)

now, t1's value1, value2 and value3, will contain the same information
as in t2's...

Just as simple as that... Don't want complicated matter...

Note: ChangeType function is independent of class passed to it. it can
accept any classes, as long as they have members that match members in
converted class... if corresponding name is not found in the
destination class, then that member is ignored...


I suggest you look into reflection, and GetProperties (or GetFields,
but I hope you don't have any public fields in the first place) in
particular.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

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

Similar topics

5
by: rufus | last post by:
Hi, I have a custom collection class that inherits from HashTable. When I add a new CustomObject to my CustomCollection I would like to ensure that it will only accept objects of type...
3
by: Laura T. | last post by:
The following code is driving me so crazy, that I'm thinking it's a "feature" or a.. ....dare I say it... a BUG. I'm using VS 2003. I've created a new value type (struct) called MyInt. MyInt has...
1
by: BillGatesFan | last post by:
I have a custom composite control which was made from a textbox control on my ASPX page. Why when I find the control using Page.FindControl, it is coming up as a regular...
5
by: Graham | last post by:
I have created a custom MembershipProvider called "LassieMembershipProvider" that derives from "MembershipProvider". This providor is located in a Businesslogic layer dll called...
14
by: Craig Buchanan | last post by:
If I have two custom vb.net classes, where 80% of the properties are alike and there is one method with a matching signature, can i cast between one and the other? do i need to have each class...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
0
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object ...
5
by: =?Utf-8?B?cGFnYXRlcw==?= | last post by:
Hello All, I am sure that I am just overlooking something, but here's something I can't quite get right... I want to be able to get the value of a parameter of an unknown custom attribute at...
0
by: Pieter | last post by:
Hi, I'm using NHibernate 1.2 (CR1), and I'm using a custom list (inherited from BindingList(Of T) ) for all my lists. The NHibernate documentation told me that I had to implement...
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.