Count Different Objects In A List That All Share The Same Interface?

May 26, 2011

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.

View 1 Replies


ADVERTISEMENT

Objects To Interface With The GUI Instead Of List(Of T)?

Mar 9, 2010

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?

View 1 Replies

Sql Server - Obtain A List Of Collections Which Contain Objects Which Implement An Interface In C#

Aug 28, 2010

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

View 2 Replies

LINQ Objects - Group All The MyObjects Together That Share The Same Value And Then Return That Value?

Nov 16, 2010

I am having trouble following some of the examples at MSDN for LINQ.Basically I have a List Of MyObject. MyObject has a property called Value which is an integer.I want to group all the MyObjects together that share the same Value and then return that Value where the count of the group is greater than 5.I have tried the following,

dim foak = From o as MyObject in MyObjectList _
Group o By o.Value into Count _
WHERE Count > 5 _
Select o.Value

View 2 Replies

List.count While Adding Items To The List Increments Returns 0

Jul 20, 2011

I am attempting to read the results from a SQL query into a List(Of) and I can see the List.count while adding items to the List increments, however in another part of my code when I am attempting to read the List the List.Count returns 0. My List is as follows:

[Code]...

View 4 Replies

Get Desired Column From Share Point List?

May 15, 2012

I am using the following Caml Query to get data from a share point list.

oSb.Append(" <OrderBy>")
oSb.Append(" <FieldRef Name=""Title"" />")
oSb.Append(" </OrderBy>")

But this query is giving me all columns of list. Is there any way to get only desired column from a share point list using Caml Query?

View 1 Replies

VS 2010 List Folders Under A Specific Share?

Feb 29, 2012

I am trying to list folders under a specific share example: \servernameshare I want the list to display in a listbox named folderlistBx I do not want to see file names or subfolders, just a list of folders

Private Sub ListBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBtn.Click
Dim FS As New FileSystemObject

[Code].....

View 1 Replies

VS 2010 WMI Code To List Remote Share Permissions?

Apr 30, 2010

I've been struggling for hours now to get some working code to list the share permissions of a remote share. I've got WMI code which uses win32_share which lists the shares and path and it works great. I"m now trying to add in a routine to get the share permissions as well.

I've searched just about every site for some sample code and can only find some C# (I think) code.

[Code]...

View 1 Replies

.net - Assigning Table Fields To Objects Within Form Based Off Of Count?

Apr 9, 2009

i saw jim example in the codebank and i added the percent progress parameter to report progress method (to change the progress bar value)this is jim example:-

vb.net
Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, _
ByVal e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork

[code]....

View 2 Replies

Interface And Graphics :: Count Number Of Pictureboxes Whose Image Is Not 'nothing'

Dec 5, 2008

I need to be able to count the number of pictureboxes whose image is not "nothing". At first, this seems really simple (and it probably is) but I'm unable to see a way to access the array I created. (This is a workaround to the .net framework's lack of support for control arrays.)Here's the code as it exists now. Please look at it and give me a pointer in the right direction.[code]

View 3 Replies

Interface Methods With Handles - Display The Current Count

Sep 26, 2011

I have a small application that consists of multiple forms that each need to have the ability to be updated (not repainted, the data/components values redefined) when called to. So for instance, if I had a form that contained a count of some sort and another form modified that count I would need to update the form that displays the current count. With that being said it needs to implement an interface with these methods (see below). My issue comes when I want to add events to these methods so if I call the UpdateData event it would trigger the OnDataUpdate method, but because of the syntax of implementing methods and handling events you cannot do so.

[Code]....

View 5 Replies

Create List Of Child Objects From List Of Parent Object?

Jun 2, 2011

I would like to create list of child objects from list of parent object. Like If i have list of bookingroom which has one member room then i would like to create list of room from it.

eg. code:

Dim BookingRoomList As List(Of BookingRoom) = New List(Of BookingRoom)
Dim RoomList As List(Of Room) = New List(Of Room)
BookingRoomList = BookingRooms.FillGrid()

[Code]....

Is there any short cut method instead of iterating over for earch?

View 1 Replies

VS 2005 Sort List Of Objects By Child List Order?

Jul 20, 2011

I'm having a bit of a 'brain doner' moment here

I have a list of Objects. Each of these Objects contains a list of other Objects (pseudo code) :-

Private Structure Object1
dim Name as string
dim ListOfObject2 as List(Of Object2)

[Code]....

I need to sort the list of Object1 by the Value in Object2. I have a comparison class which sorts Object2 by its Value nicely.

View 13 Replies

Creating A Command Line Interface With Objects?

Dec 16, 2011

Im considering making my own command line interface with custom commands etc. I was thinking the following objects would be sufficient:

Textbox - for input
Rich text box - for showing processes and output
Button - to insert input

If it can be done, how can I provide line breaks in the output on the rich textbox e.g.

line1: input instruction
Line2: <cp><textfile.txt>
Line3: I/O error, file not found, check file root.

My version of CLI will have no integration with the windows CMD.

View 2 Replies

Data Objects Implement An Interface IFillable?

Jan 19, 2011

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).

View 3 Replies

Interface And Graphics :: Resize Objects Dynamically In .net?

Oct 13, 2009

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

This does not work in VB.net.

View 3 Replies

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

[code]....

View 5 Replies

.net - Searching A List Of Objects In An Object List Using Linq?

Dec 22, 2010

I have 2 classes

Public Class Shipper
Public Property ShipperID As Long
Public Property CreateDate As DateTime

[Code].....

View 1 Replies

Linq - Create A List Of Integers From A List Of Objects?

Nov 23, 2011

I'm trying to create a list of days(integer) from a list of dates(date).

I tryed to do this....

[Code]...

View 4 Replies

Transform A Repeating List Into A List With A Count?

Jun 5, 2012

I have a list(Of transaction) :

[Code]....

How can I transform it to a list(Of transactionShortened) :

[Code]....

View 1 Replies

Interface And Graphics :: Panels - Drag Objects Without A Windows Frame?

Oct 1, 2010

How do you drag objects without a windows frame?

View 5 Replies

Interface And Graphics :: Drawing Objects To Picturebox With Floating Point Numbers?

Jul 17, 2009

If I try to draw a circle by using e.g.

Code:
e.Graphics.DrawEllipse(Pens.Red, 50.133, 100.321, 0.1, 0.1)

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?

View 6 Replies

Multithreading - Create Custom Objects/list Of Custom Objects In .NET?

Jan 24, 2010

I need two seperate lists, which every item is Integer, String, Bitmap - and one which every item is Integer, String String. However I don't know how to do this, or even where to look - I've googled for custom objects and custom object lists. What I'm trying to do is this.Custom Object1 is Integer, String, Bitmap Custom Object2 is Integer, String, String

In one thread I'll be adding items to List1(Of Object1), and processing them, and adding the results to List2(Of Object2), however I need to be able from other threads to look at the list and say only give me the items where Integer = (my thread ID), is this possible? Any help, or even links to information that would be relevant to this request would be helpful?

View 2 Replies

Count Items In A List Box?

Nov 22, 2009

So i have 4 items in a listbox how do i count then up together to show in a label [code]...

View 4 Replies

Count Up Bytes In List Box 5?

Jan 9, 2010

I'm using this code to count up bytes in list box 5. It works but when the value of bytes is 0 i get this {Width 100, height = 200,) I think the problem is the ToString So does anyone know how to count numbers in the list box?

vb
Dim total As Integer
Dim i As Integer
For i = 0 To ListBox5.Items.Count - 1

[Code].....

View 6 Replies

Display A List (Of Object) Which Has Single Objects And Child List (Of Object)?

Sep 6, 2011

Limited to using v2.0 of .Net framework (we use VB.net) due to environmental constraints on our servers.I've got an ASP.net webpage which pulls data from a webservice that performs checks on user accounts in active directory. Operators can check multiple accounts at one time using the web interface. The webservice returns a list(of AccountCheck) objects which themselves contain single properties like username, email address, and List(of AccountError) objects which contain multiple properties.[code]What I want to do is using some kind of repeater, create multiple panels or divs which contain labels showing the username, email etc, and a gridview which has the accounterror list bound to it to show all the errors. The users could be checking 2, 5, 7 accounts at once, and is dynamic.

View 2 Replies

Fast Count Of Same Object Within List?

Mar 28, 2012

I have an operation that will be performed MANY times and so I need it to be as fast as possible, thus I think keeping validations to a minimum is important here.I'm given an image, an offset and a size; and the idea is to take the color that appears the most within the area determined by the size and offset, so far I have this:

Private Shared Function someFunction(image As Bitmap, offset As Point, sampleSize As Size) As Color
Dim pixelsColors As New List(Of Color)

[code]....

View 1 Replies

List All CustomerID And Corresponding Count Of Orders

Sep 12, 2011

I have the following code for Customers and their orders. I want to list all the customerID and the corresponding count of orders. How do I achieve it using LINQ? [code]

View 3 Replies

VS 2008 Count Items In A List?

Mar 6, 2010

Im trying to count how many items are in a list(of)

I looked it up on google but still cant figure it out.

View 3 Replies

Count Items In List(Of Structure) Using Predicate .net 2.0?

Jul 26, 2011

I need to count the items that meet a criteria in a list(of structure) in .net 2.0. eg

Dim listcars as new list(or car)
Structure car
Dim Name as string
Dim year as integer
End structure

Now i need to count all cars with name toyota etc, how do i do it.

[URL]

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved