473,386 Members | 1,908 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,386 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 1563
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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,...

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.