Use ISerializable Interface To Serialize An Arraylist Of Objects?
May 10, 2009
I have a class called Tree, it has an arraylist called alTreeNodes. alTreeNodes is an arraylist of TreeNode class. Since I am using ISerializable Interface, I have to provide a specific constructor. I know how to write it for string parameters such as name_value, but how should i do with arraylist of object then? See "???" in the code blog before.
Protected Sub New(ByVal info As SerializationInfo, _
ByVal context As StreamingContext)
If info Is Nothing Then
Private Sub MakeMeSomeXmlBeforeRyanGetsAngry() Dim db As New MyDBDataContext Dim customer = From c In db.Customers Select c
[code]....
I am attempting to serialize my linq collection of customers. But it keeps throwing
Type 'System.Data.Linq.DataQuery`1[MyDB.Customer]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types. My issue is that I have already marked the dbml Serialization Mode to UniDirectional and when I check the dbml codebehind all of the DataContract()> and DataMember()> elements are there. I have tried adding various dataloadoptions and setting deferredloading to false, but no luck.
I have one class with <Serialize> attribute called Tree. And Tree class has an arraylist of TreeNode classes. Is it possible to use Soap to convert the Tree class and arraylist of TreeNode classes to one xml file or binary file? If it is possible, do i need to use <Serialize> attribute on TreeNode classes too? If not, what should i do then?
I have an ArrayList in android that I'm trying to convert to a Base64 String, then passing that to a wcf service though JSON and the wcf service inserts the string into a database. Then I need to be able to read that from the database and deserialize it in a .NET application.
This is how I am serializing the ArrayList in android:
The ultimate goal is to be able to be able to create a list of these shapes in the .NET app or android app and be able to read the list in the .NET app and android app no matter where it was created from. I'm able to it when you create the Shape from .NET and read it into android using WCF but creating it in android.
How best to manage multiple dat files for serializable objects of the same class. If one of my data files goes past a particular size, I want to create a new file. I then loop through both files when I do processing. Is there any easier way to do this and what's the best size to do this at in terms of performance?
I use serializer classes for storing data and each class can hold an array of objects for the same class which is a key feature of the class. I declare this array as so:
myClassObjects(1000) as myClass
My question is- can I declare the array as an arraylist so I can sort and count objects in the array(list) quicker and easier and are there any drawbacks to taking this approach?
1. how do you edit objects in an ArrayList? 2. the code below works ok but is it ok to obtain a reference to an object from an ArrayList and then edit the object?
Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
I have an ArrayList that is populated with Objects. These Objects raise events at certain times. How can I capture these events from the ArrayList? i.e. I want something like this: Public Sub MyRaisedEvent(ByVal obj as MyObject) Handles MyArrayList.MyEvent End Sub
when i do a count it display a list of 25 items in the folderlist.Now i have a main class when i tried to use the following method
Dim MainClass as New ClassB
Console.writeline(MainClass.FolderList.count()) the value reflects as 0 items meaning is empty.i need to retrieve the arraylist from Class B using the MainClass to retrieve those items inside the arraylist.
I'm completely new to VB.NET and this is likely a few steps over my head, but have managed to get myself this far with just Google.I'm reading an XML file and creating an arraylist of classes for the values in there, as seen:
Public Class yresults 'Dim xdate As XmlNodeList = xDoc.GetElementsByTagName("Date") 'Dim link As XmlNodeList = xDoc.GetElementsByTagName("Link")
How can I sort an ArrayList of custom objects by public member? Example,If I have a list of article objects, and I'd like to sort the list by the rating member after I've filled the ArrayList
Public Class Article Public bulletin As String Public rating As Integer[code].....
Now I'd like to sort uniqueArticles by rating and print articles by rating order.How do I do perform that sort?
I have a group of objects stored in an arraylist. These custom type objects have a number of properties from their underlying class . I want to use one of the properties to sort the array. I cannot determine which Array.Sort method to use.
I want to sort based on an integer property. Virtually every example I can find involves sorting strings.
So, assume the Objects have the following properties.
Obj.name as string Obj.ID as integer Obj.Alive as boolean
The objects are kept in an arraylist called FriendsOfMine.
I want to be able to order the list by Obj.ID, both ascending and descending in value.
After going through some tutorials I set out to work on my own game. Right now it's simple, I have a ship that moves left, right and shoots. I also have Asteroids that fly at the ship.
The problem is that I have 3 asteroids in an array, and they all act the same... I would like random speeds and directions.
I'm writing a tabbed web browser for someone who is learning VB.NET, and I have got to the point where I can add/remove browser controls into tab pages, controlled by one set of buttons on the main form, but I can't handle events from the WebBrowser objects.I have tried this but it says that 'DocumentTitleChanged' isnt an event of 'Control'...
Dim browser As New ArrayList browser.Add(New WebBrowser) browser(0).parent = TabControl1.SelectedTab browser(0).dock = DockStyle.Fill AddHandler browser(0).DocumentTitleChanged, TitleChangedHandler()
I want to update the tab title with the web page title when it changes. I started using a timer to update the tabs but there must be a way to add an event handler here.
If a class is serialized and has events fired from it that are handled on a form you get the error "Form1 cannot be serialized" in c# you can use (to work around this):
I do have some classes that implement their own serialization/deserialization but I'm doing all of these without implementing system.runtime.serialization.ISerializable. so my question is what exactly is the benefit of using system.runtime.serialization.ISerializable ? in what example situation will we need to implement system.runtime.serialization.ISerializable?
I have started using BindingList(Of T) for my generic collections whenever I need the objects to interface with the GUI instead of List(Of T). This has worked well for me so far but a few of my collections are stored in Dictionary(Of TKey, TValue) and there doesn't appear to be a corresponding BindingDictionary(Of T).
Has anyone else come across the necessity to use this, and how did they achieve it? Should I implement this myself? (How?) or is there a better solution already available?
I have an object (MyObj) that itself will hold a List of other objects of various types and I want to count them as they are added to MyObj.That's the simple explanation, anyways...I have an Interface (MyInterface) that all sub-objects agree to. MyObj has a List(Of MyInterface) property that all the sub-objects are added to. MyInterface will expose a property that lets me figure out what subtype each object is (the sub-objects do not inherit from MyObj at all).
But I want to count these sub-objects as they are added to the list, and I'm trying to find a good way to do it. I don't need to worry about decrementing the count, as I am going to mimic the behavior of String and just create a new instance of MyObj if it ever changes, so all my counts will start from 0. This'll hit the garbage collector a bit, but I think this will allow for simpler (and safer) code. The only sane way I can think of to count objects is a very large structure in MyObj that uses bytes to hold the count (I will never have more than 255 of any given sub-object in the list in MyObj). But, even using bytes, this structure will be about 100-200 bytes big in memory (I have that many sub-objects), and I anticipate having a fair amount of MyObj copies running around, too.
I'll also need a large Select Case to know which count property to increment when a new sub-object is added. This seems to be a bit ugly, though I've used this approach several times already.What I am wondering is, instead of counting each object as it is added to the list, is there some way to query the list and count only the objects of a specific type? I wouldn't need to store this anywhere, since it would be dynamic, like querying a database and asking for a count of a specific column or type of record.I suspect Linq can do this, but Linq is also quite slow. Are there other approaches? Perhaps a predicate of some kind?VB (I am not a C# guy):
From i in MyObj.MyList Group i by i.GetType into g Let c as Int32 = g.Count() And that's it so far. I am still googling, but I am getting way too many C# and SQL references.
All my data objects implement an interface IFillable
Public Interface IFillable Sub Fill(ByVal Datareader As Data.IDataReader) End Interface
In the objects themselves you will typically see something like
Public Class Supplier Implements IFillable
[Code]...
Now here is the tricky bit. Given that all my property names WILL ALWAYS match my database column names what I want to do is using reflection generate the fill method at compile time and infer the types and column names for the datareader.I am assuming I will need to structure this functionality as some sort of a tool/vs plugin? What I am looking for is guidance on the best way to go about this.
PS: BTW: Obviously I could easily do this using reflection at runtime but I dont want to take the performance hit for it (Although theoretically if I could cache the values somehow (static class?) it might not be too bad).
I need to let the end user move and resize objects (like a textbox or button). There are several examples that demonstrate this in VB, but not in VB Express 2008, based upon VB.net.It looks like earlier you needed to access Windows API, but these calls does not work in VB.net. I understand that these call are replaced by "native" .net calls, but I cannot find any that does the job.
A typial example from old VB is:
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
I am new to .Net Programming and would like to know if Reflection is suitable for traversing an Object to discover Collections within an instance of a class. I am working with the Microsoft.SqlServer.Management.Smo Namespace.
The plan is to connect to a database, determine what collections exists, then for each of those collections, if the Collection exposes objects which implement the IScriptable Interface, generate a script for the object.How do i do the following (This is pseudo-code as I am seeking assistance with using reflection or some other method to do the following)
[Code]...
I would like to enumerate all objects in db with one function if possible
I will get an error message. I tried something like
Code: Public ObjectPoint As PointF Dim cpoint As New PointF() cpoint.ObjectPoint = New PointF(startX, startY) e.Graphics.DrawEllipse(Pens.Blue, cpoint.ObjectPoint, 0.4, 0.4)
but it didn't work for the location and the circle size. How to draw a circle(and rectangle) by using floating point numbers?
What I am doing is iterating through all the groups that belong to the top group (Generic reports). Then I take advantage of the GroupPrincipal.GetMembers(True) which will recurse through a given group name. I test to see if the user exits under that group and if true I put the group name in an arraylist.
I use the for each principal in GroupPrincipal.GetMembers to loop through each returned user to see if they exist.
Is there a way to put all the returned users Principal.Name from a given group in GroupPrincipal.GetMembers into an ArrayList? This would allow me to to use Arraylist1.IndexOf to search for user. Which would be much faster then iterating through a returned list using the for each construct.
Sub RetAllMbrs(strUser As String) Dim oPC As PrincipalContext = GetPrincipalContext() '<- this is function somewhere else in the code