See Properties Of A Generic Collection Object?

Apr 8, 2009

I have a class which extends HashSet(Of T).I am trying to evaluate some custom properties of this HashSet during execution and make decisions based on those values.

During debugging, I am pausing execution and adding a Watch on my instance of this HashSet.

The Watch only provides me with a view of the Count of the HashSet and the objects contained by the HashSet.How can I get the Watch to show me the other properties of the HashSet?

View 1 Replies


ADVERTISEMENT

C# Accessing Properties Of An Object From A Collection Class?

Jun 10, 2009

I am moving from VB to C#. I am trying to loop through a collection class which is a collection of data classes but I can't seem to get the actual values out of the data class properties(find the correct code to do so). I have a method that loops through the collection class(Contacts) and saves each record(Contact). I am using reflection because my method will not know if it is Contacts class or a Customer class and so forth. Here is my code in VB(watered down)

Public Function SaveCollection(ByVal objCollection as Object, ByVal TableName as string, ByVal spSave as string)
Dim objClass as Object

[Code]....

The C# code keeps returning null. In my locals window I can see the proprties on the class on objClass and the value of the propery but I can seem to figure out how to access it through code. I used the DictionaryBase because that seems to closely match would I need to do. My data class(Contact) has a bunch or properties that match the field names in the database of the Contact Table. After I get the propInfo variable set I then set up my SQLParameter with the fieldname, datatype etc and then set the value to the propInfo.value.

View 5 Replies

.net - Collection Initializes For Read-only Collection Properties?

Jul 25, 2011

I'm trying to support Basic.NET on my framework so I'm trying to convert C# 4 code to Basic.NET 10. Microsoft is committed to "co-evolve" these two but I'm having a problem with collection initialization... I found that I can initialize a collection much like in C#:

[Code]...

View 6 Replies

Convert One Generic Collection To Another?

Jan 23, 2010

I have the below code and it works fine, it's this way because I need to manually calculate some data before adding it to the Listview control.

Code:
Dim mList As List(Of ListViewItem) = mDataBase.GetRecords(LvwChecks, "CheckGroups", <Query>, GetType(CheckItem))
If mList.Count > 0 Then

[Code].....

View 6 Replies

InvalidOperationException Generic Collection?

Sep 14, 2011

I know its generally a big No-No to modify a collection that you are iterating through but unfortunately i didn't design the code that i'm trying to modify. All over the place the following is done:

for each log in Logs
logs.Delete(log.LogId)
Next

Delete pretty much just deletes the log from the database and removes it from the collection. Previously the Logs object was using a Non-Generic collection. I changed it to use a Collection(Of Log) so i can LINQify the object. Now every time i call next/.MoveNext is called after the first delete the following error happens:

InvalidOperationException:"Collection was modified; enumeration operation may not execute."

I understand why i'm getting the error but i don't understand why it never happened with the Non-Generic version. Is there anyway to get around this error? There really is no way i can take the time to change every place where the delete logs like this (codebase is large). Id like to just remove the code in the Delete function where it removes it from the current collection because i'm assuming no code does anything with the collection after its done but you know what happens when you assume.

View 3 Replies

Flattening An Object Hierarchy Using A Shim Class - Initializing Derived Object Properties From The Base Object?

Jul 10, 2010

I am somewhat new to object oriented programming and am attempting to flatten a Linq object hierarchy by using a shim class.how to initalize a derived class with property values from a base class?I have two objects, a base object with about 100 properties, and a derived object which inherits from the base object and adds a few additional properties beyond those of the base object. My simple constructor creates the derived object, but I am looking for a way to initialize the derived object properties with values from the base object.Right now I am using reflection to iterate over the properties individually and I suspect there may be a better way. The following example shows my shim class constructor for the derived class, and two properties:

newProperty1 - a new string property of the derived class

flattenedProperty2 - a new string property of the derived class, copied from a 2nd-level object of the base class

Code example:

Public Class derivedObj
Inherits baseObj
Private _newProperty1 As String[code].......

Is this the correct constructor approach to flatten the object hierarchy using a shim class? My second question relates to initialization of properties in the derived class. The constructor above creates the derived object, but what is the best way to initialize the derived object properties with values from the base object? The following code uses reflection to iterate over the properties individually, but I suspect there may be a better way.

Code example:

' property names are in the string array fieldNames

'baseObjQuery is an ienumerable of baseObj

'derivedObjList is a list of derivedObj[code].....

Is there a simple way to initialize values for the properties in the derived object based upon the values of the common properties in the base object?

View 7 Replies

Serializing A Generic Collection With XMLSerializer?

Jul 11, 2009

Why won't XMLSerializer process my generic list?

Sub Main()
Serializing()
End Sub

[Code]....

I get an exception on the "Dim ser" line, saying "Testing.Module1 is inaccessible due to its protection level. Only public types can be processed." ("Testing is the name of the application, and "Module1" is the name of the module; this is a console application).

View 1 Replies

VS 2010 Generic Collection Queue?

Apr 16, 2011

Ok say I have this Dim MyQueueOfClients as new Queue (Of TcpClient) I also have two threads.

In thread one a TcpListener waits for connections then adds a connected TcpClient to MyQueueOfClients.

MyQueueOfClients.Enqueue (TcpClient)In thread two I then check to see if there are any Clients in MyQueueOfClients. If so I then remove them from the MyQueueOfClients.

MyTcpClient = MyQueueOfClients.Dequeue I think the question Im asking is this thread safe?

Can I Enqueue and Dequeue at the same time from different threads?

Well it helps if you read everything. I have just read this as well

A Queue(Of T) can support multiple readers concurrently, as long as the collection is not modified. Even so, enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

View 4 Replies

Pick Last 1000 Elements From A Generic Collection?

Mar 1, 2011

Say a collection grow. Once it's size reach 10k, I want to get rid the first 9k. How to do so?Oh ya I could use removeRange.Is there another function that will output say, the last 1k of the element, say if I do not want to remove anything? Something like tail or something.

View 7 Replies

Index Out Of Range Exception In Custom Generic Collection?

Feb 25, 2009

I wrote a class which imports System.Collections.ObjectModel. For the management of the collection, I've written:

Default Public ReadOnly Property Item(ByVal vntIndexKey As Integer) As ItemType
Get
Return CType(mCol.Item(vntIndexKey), ItemType)

[code].....

View 4 Replies

VS 2008 Transfer A Custom Event Through The Generic Collection?

Dec 22, 2009

To the point: I need to transfer a custom object's event through a generic collection object containing these items so that any class using the collection can see that changes were made to one of the items in the collection.

I.E. An item event that triggers a collection event

[Code].....

Due to the application requirements, I need the Collection and Items to send immediate notice of various changes that occur to the Collection Class and its items. I've already got my events set-up regarding for the Collection Class, but I'm struggling with coming up with a workable solution for raising events for the items.

I've got an event for the DeviceLayer item set-up, but how do you transfer that event through the CollectionClass so that any other class using it will see that there was a change to one of the items in the collection?

View 3 Replies

Working With System.collection.generic.Ienumerable/XML Linq Queries?

Oct 22, 2009

This is really a continuation from my earlier post. I've never worked with this datatype/collection (system.collection.generic.Ienumerable) before so I'm struggling to declare the query globally so I can reference the results within other sub routines/functions. I also am struggling to convert it to other types.how I can convert the collection of xml elements/system.collection.generic.Ienumerable into an xmltextreader (I know I will have to change the query below as it select the value of the node and not the node itself) I imagine by converting the query result to system.IO.stream My first port of call was MSDN but I find the material very difficult to understand for this particular subject.

[Code]...

View 3 Replies

.net - Use Generic Method To Replace Duplicated Properties?

Jul 29, 2011

Currently my code has the following properties:

[Code]...

View 3 Replies

Make Several Similar Properties Call One Generic One?

Sep 14, 2011

I'm wondering if it's possible in VB.NET to make similar properties call one generic one?A sentence doesn't explain it well so here's a code example.I have a bit field defined like this:

<Flags()> _
Enum E_Operation As Integer
Upload = 1

[code]....

View 1 Replies

Alter Items Added To Generic Collection (as Property Of Custom Class)

Jun 19, 2009

I have several custom classes in a VB.NET (VS2008) project which are related to each other through generic list collections. The lower tier classes refer directly to some of the parent classes (to make it easier to refer backwards up the chain). My question is, is it possible to add the reference to the parent class when the item is added to a collection, when that collection is a property?

Below is some sampling of code to illustrate.
Public Class FlexServer
Private m_FlexLicenses As List(Of FlexLicense)
Private m_Modules As List(Of FlexModule)
Public Property FlexLicenses() As List(Of FlexLicense)
[code] .....

In the code above I have the FlexServer class which refers has two lists as properties, one for FlexLicense and one for Modules. The FlexLicense class has a property to refer back to the FlexServer class that "owns" it. In order to update this property in code, I have to add the FlexLicense to the FlexServer.FlexLicenses list AND set the FlexLicense.FlexServer property. What I am looking for is, is there a way (in the property definition or wherever) to both add the item to the list and alter it at the same time?

View 1 Replies

Request For Peer-Review KeyedBindingList (Of TKey / T) Generic Collection Concept

Aug 18, 2011

There are a lot of different generic collections available, so the wisdom in creating a new one may be questionable right from the start.However, I often find myself wanting the same features from my custom generic lists, but cannot quite find all of those features in an existing object; namely, I would like to have a generic collection which works like a List or Dictionary (much like the System.Collections. ObjectModel. Keyed Collection(Of TKey, TValue)), but also works like a BindingSource does when it is bound to an ADO object (that is, it supports full sorting and filtering as well as currency).A feature I almost never need however, is transactional adds (the BindingSource's ability to 'cancel add-new').Again, with so many existing collections out there, I should take a moment to go over the reasons why none of them quite meet my needs.There is the System. ComponentModel. BindingList(Of T) which would provide some of the functionality of a BindingSource, but has strict requirements about the type {T} implementing IComparable in order to support sorting, and does not provide filtering (it is not an IBindingListView).It also only maintains a base item list by index, so does not provide keyed access.We could use simple databinding with a custom list inheriting from System.Collections. ObjectModel. Keyed Collection(Of TKey, TValue) bound to a BindingSource, but again TValue would have to implement IComparable to support sorting and we would still not have filter support.So to get all the features I was after, I decided that the best thing would be to create a new generic collection object which implemented IList, IDictionary, IBindingList, and IBindingListView (along with a few others) and would be capable of serving as a simple list, or as a binding source while providing full sorting and filtering over any newable object type.

To that end, I've created the KeyedObjectModel which contains the KeyedBindingList(Of TKey, T) generic collection/binding source. This collection can be used as a typical list, or as a binding source (you do not need an additional BindingSource component between the collection and UI controls, although you could certainly have one).Various constructors are provided in order to initialize an instance of the collection as either an enhanced list-dictionary, or as a complete BindingSource.Any object that has a public constructor which takes no arguments can be used at type {T}, providing that the object has a property of type {TKey} which will contain unique values for each entity in a given collection.If the object implements System.ComponentModel.NotifyPropertyChanged then the collection will also bubble up property changes on the current item to the collection's CurrentItemChanged event.An implementation of IComparable on type {T} is irrelevant because sorting and filtering are performed on the property values of {T} based on the type of the specified property.The current design of KeyedBindingList(Of TKey, T) is in an 'alpha' stage.The class is mostly complete from a feature implementation standpoint, however, the code has not yet been optimized and the base collections of values, keys, and view are being maintianed in generic lists of their own, rather than raw arrays.However, even without performance tuning, the collection appears to be performing quite well, up to a few thousand entries, given the amount of flexibility and funcitonality it provides.At this stage, I would really love to get some peers to try using the compiled DLL and beat up the collection a bit.Once the code has been proven and optimized, I will publish it as an example.It is a fairly complex class though (currently made up of eleven or so partial classes) so I don't really want to post the code until it has been optimized. [code]

View 4 Replies

OrderBy Nullable Properties In A Generic List Throwing InvalidCastException?

Jun 13, 2012

I need to return an a generic list in the correct order for my project, and I'm getting InvalidCastException errors. Here is the code:

Dim lDt As List(Of Comment) = RemapCommentsForE1(so.CommentList). _
OrderBy(Function(x) x.CreateDate.Value). _
ThenBy(Function(x) x.Sequence). _

[code].....

View 2 Replies

Multiple Properties In A Collection

Aug 10, 2010

I want to create a collection with multiple properties.

View 15 Replies

Asp.net Mvc - Dynamic Object Properties In A MVC Helper On Entity Framework Object

Jul 20, 2009

I want to build a MVC helper function for which I pass a Entity Framework object and have it build a select. Generally speaking I tried something like this:

Public Function RenderSelect(ByVal helper As HtmlHelper, ByVal sSelectName As String, ByVal aItmes As Array, Optional ByVal sTitleKeyName As String = "name", Optional ByVal sValueKeyName As String = "id") As String
' open select

[Code].....

However, it isn't working. It would be great to have a way to do this and pass the current entity object.

View 3 Replies

Dynamic Object Properties In A MVC Helper On A Entity Framework Object?

Oct 26, 2010

Dynamic Object Properties in a MVC Helper on a Entity Framework object

View 1 Replies

Hide / Omit Some Properties In Binding Of A Collection?

Mar 26, 2010

My problem is similar to the one described in this article, but I'm trying to use a different grid(DevExpress.xtraGrid) and therefore the answer (if it even works) does not apply for me: Binding Collection to DataGrid without showing all columns

Briefly, I'm binding the grid to the collection of custom objects - cMessage - to grid's datasource, but I don't want all the propertieties of the cMessage to be shown in the grid. Is there any way to hide some properties from the binding, while leaving them acessible from outside (ie.leave them as public or friend)?

View 1 Replies

Iterate Through Class / Object Properties - Saving Them Each To Another Object

Dec 15, 2011

I'd like to have something like:

[Code]...

View 1 Replies

Collection Properties Display To List And Labels In Main Form

May 12, 2012

I'm having trouble with collections and how it works, what I have so far is classes and I have attempted to do collection but it is not working properly. I am trying to have the collection hold the classPerson,classCustomer, and classPreferredCustomer properties, and then display it to list and labels in the Main form. [Code]

View 7 Replies

Expose Methods And Properties Of User Controls Contained In A Collection?

Mar 9, 2009

at some points, I need to call the same method on those controls (ex. user presses the clear button on the big control, I want to call the clear f(x) on each of the controls)I thought to toss the controls in a collection, and then be able to handle them something like this:
nextturns out, and I should have realized, methods and properties of controls are not exposed when treated this way. The only thing that can be seen is the stuff that the base class (control, I guess) has.

View 2 Replies

Hide Or Omit Some Properties In Binding Of A Collection To Grid Control?

Mar 26, 2010

My problem is similar to the one described in this article, but I'm trying to use a different grid (DevExpress.xtraGrid) and therefore the answer (if it even works) does not apply for me: [URL]

Briefly, I'm binding the grid to the collection of custom objects - cMessage - to grid's datasource, but I don't want all the propertieties of the cMessage to be shown in the grid. Is there any way to hide some properties from the binding, while leaving them acessible from outside (ie.leave them as public or friend)?

View 2 Replies

Generic Object With Default Value Possible?

May 25, 2011

I have relations between two object, but is there a way to load an object when calling a property? I tought about a generic class above a object, where the value is set. On request of the property i can load a value out of the database at that moment.. This
can work i think but the problem is that i must call a sub property of Reference(of TObject) like pObject.Value to access the ObjectB.

So my question is, is there a way to execute code before loading a property (like with a base class or something else) or is it possible to set a default output to ObjectB for Reference(Of ObjectB) so i don`t have to access pObject.Value to walk trought ObjectB?

[Code]....

View 1 Replies

Casting From Generic IList To Object During DataBind?

Feb 18, 2010

Okay, so I have a Generic IList of custom objects that I want to use as a datasource for a repeater.

Dim productRows As IList(Of MyCustomObject)()
'fill list with data
rptResults.DataSource = productRows

[code]......

View 1 Replies

Get Value From Property Member Of A Class As Generic Object?

May 29, 2010

I have a routine that accepts a List of Objects, a property name and a value to search for and simply returns whether or not it found it.The code I have hangs up at the For loop in the findit routine.[code]

View 4 Replies

How To Filter Object With Specified Type In Generic Collections

Jan 3, 2012

given the following class structures:[code]I add the following property to MyList, trying to answer questions like "find out the number of elements with specified type, say Derived1, inside MyList?"[code]

View 1 Replies

Instantiate A Generic Class Using Concrete Object?

Sep 27, 2011

i've got a generic class for xml serialization and deserialization.

Public Class clsXMLHandler(Of T)
Public Sub serializeFromObject(ByVal filePath As String, ByVal [object] As T)
Dim creater As New FileStream(filePath, FileMode.Create)
Dim xml As New XmlSerializer([object].GetType)
xml.Serialize(creater, [object])

[Code]...

View 1 Replies







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