Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

VB.Net Byte Arrays


XerShade
 Share

Recommended Posts

Okay compiled this from my engine for VB.Net because I am tired of seeing all the people porting Eclipse to .Net and still using CopyMemory. There is an example project as well as the stand alone DLL file.

Be sure to mark your custom classes as ****or it will error, binary formatter is picky about that.

**Updated Project Files**

[attachment=602:ByteArrayTestWithVBFunctions.zip]

**The DLL FIle**

[attachment=598:Extensions.ByteArrays.zip]
Link to comment
Share on other sites

You should have included the source for your library, but that's okay. I'll explain it.

Basically, he's got a function that returns a serialized object as a byte array and a function that returns an object deserialized from a byte array. Might look something like the solution I've attached.

[attachment=601:ByteArrayConverter.zip]
Link to comment
Share on other sites

> The source for the library is C#. Also no offense but you really should have used type casting with that, makes using it easier.

Why would you need to type-cast in the method when you can do it outside of the method, young padawan? ![;)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/wink.png)

```

static void Main(string[] args)

{

TestObject to = new TestObject() { DateOfBirth = DateTime.Now, Email = "[email protected]", Name = "Budweiser" };

byte[] testArray = to.ObjectToByteArray();

foreach (byte bt in testArray)

Console.WriteLine(bt.ToString());

TestObject ts = (TestObject)testArray.ByteArrayToObject();

string output = string.Format("Name: {0}, Email: {1}, Date of Birth: {2}", ts.Name, ts.Email, ts.DateOfBirth);

Console.WriteLine(output);

}

[Serializable]

public class TestObject

{

public string Name { get; set; }

public string Email { get; set; }

public DateTime DateOfBirth { get; set; }

}

```

And I fixed an error in the Library and converted the methods to extension methods that can be used with any byte array or object (objects have to be serializable). Here's the new library with an updated example:

[attachment=601:ByteArrayConverter.zip]
Link to comment
Share on other sites

Ues and tell me how you use default(Object) then, Object does not equal a custom class and then you would get a bad object back, especially if the custom class had data that is built when it is constructed. And they can easily get the source code by looking at my project on my website, I see no reason for your posts.

Edit: This is for vb.net, why would they want C# code to begin with.
Link to comment
Share on other sites

> Ues and tell me how you use default(Object) then, Object does not equal a custom class and then you would get a bad object back, especially if the custom class had data that is built when it is constructed. And they can easily get the source code by looking at my project on my website, I see no reason for your posts.
>
> Edit: This is for vb.net, why would they want C# code to begin with.

Like I told you in the shoutbox it's in the code I provided. There's an explicit type conversion when the extension method of the byte array returns an object. Type casting is not required for serializing the class into a byte array.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...