|
-
May 19th, 2006, 02:06 PM
#1
Thread Starter
Frenzied Member
help translating vb code to c#
i have this vb.net code, which may not even work in vb.net itself, but it's an example someone posted. It is suppose to copy all the properties of an object without having to code each individual property.
Code:
For Each [property] As PropertyInfo In o2.GetType().GetProperties()
[property].SetValue(o1, [property].GetValue(o2, Nothing), Nothing)
Next [property]
-
May 19th, 2006, 02:52 PM
#2
Re: help translating vb code to c#
You can use the VB.NET > C# converter page found here -
http://www.developerfusion.co.uk/uti...btocsharp.aspx
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 19th, 2006, 03:06 PM
#3
Re: help translating vb code to c#
If you want to copy an object, just use binary serialization.
You don't need to think about propeties at all.
I don't live here any more.
-
May 19th, 2006, 03:59 PM
#4
Re: help translating vb code to c#
 Originally Posted by benmartin101
i have this vb.net code, which may not even work in vb.net itself, but it's an example someone posted. It is suppose to copy all the properties of an object without having to code each individual property.
Code:
For Each [property] As PropertyInfo In o2.GetType().GetProperties()
[property].SetValue(o1, [property].GetValue(o2, Nothing), Nothing)
Next [property]
This shouldn't be difficult to convert at all. It's just syntax.
Also keep in mind that you don't need the icky brackets around "property" to differentiate it from "Property" in C#, since C# is case sensitive.
Code:
foreach(PropertyInfo property in o2.GetType().GetProperties())
{
property.SetValue(o1, property.GetValue(o2, null), null);
}
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
May 22nd, 2006, 05:02 PM
#5
Thread Starter
Frenzied Member
Re: help translating vb code to c#
thanks for the responses.
I'll try your suggestion sunburnt.
Wossname, I tried using serialization, but you see, I'm using a COM object. The class that i'm using is in a COM object and when I try to binary serialize, it won't let me. I think it's because I have to declare the class as being <serializable>. Unfortunately, I don't know how to make classes from a COM object to be serializable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|