I am using a hierarchy of generic collection classes that derive from an abstract base class to store entity items that also derive from an abstract base class:
abstract class ItemBase { }
class MyItem : ItemBase
{
public MyItem()
{
}
}
abstract class CollectionBase<T> : Collection<T> where T : ItemBase, new() { }
class ...
I'm creating a list of <T>, but i want to know the type of that T-object. (i'm using reflection in my project, so i don't know the type when i'm creating my code.
So first i have my List --> List<T> values
Now i want to get all the properties of that T-object (for creating columns in a datagrid)
any help?
...
Hi,
I understand that a dictionary is not an ordered collection and one should not depend on the order of insertion and retrieval in a dictionary.
However, this is what I noticed:
Added 20 key value pairs to a Dictionary
Retrieved them by doing a foreach(KeyValuePair...)
The order of retrieval was same as the order in which they we...
I'm writing a method that forms part of the public interface of a Java class. It broadly allows the caller to specify the values to assign to a number of database entities - so they must supply both the IDs of the entities themselves, and the values to assign to them.
I'm wavering between implementing this as a List<Pair<Integer, Integ...
Very simple question, what would be your way of storing 100 KB - 2 MB objects in memory? Object is made of 3 doubles and two strings (both mostly under 5 chars long). Would using struct instead of class be any better?
EDIT: I don't know why I said double, it is float .. :S
...
Suppose I have a class TestCollection which is used to hold objects of type Test and is defined as
public class TestCollection : CollectionBase
This allows me to iterate through the collection either as
foreach(object o in collection)
...
or
foreach(Test t in collection)
but does not allow me to use new Linq queries.
If I cha...
Generic Methods in general are new to me. Need a method that returns a Collection of a generic type, but also takes a collection of the same generic type and takes
Expression<Func<GenericType, DateTime?>>[] Dates
parameter. T throughout the following function should be the same type, so right now I was using (simplified version):
...
Hi,
I'm trying to retreive data from a massive form using Asp.net MVC. Its top object L1 contains properties which are Collections of other types L2. However the Type L2 contains some properties which collections of type L3, and so on. There are probably 5 levels of nested collections.
I've seen the approach of binding to Lists in Asp....
There are some similar questions to this; I did not find one that I felt answered this use case. (Please feel free to correct me!)
A coworker asked me today how to add a range to a collection. He has a class that inherits from Collection<T>. There's a get-only property of that type that already contains some items. He wants to add the i...
Is it possible to attach a List of strings to a String property so that the user can select one of the strings from the Properties window? Should I implement ICollection or something of that sort?
...
If I want to narrow, say, an Iterable[A] for all elements of a particular type (e.g. String) I can do:
as filter { _.isInstanceOf[String] }
However, it's obviously desirable to use this as an Iterable[String] which can be done via a map:
as filter { _.isInstanceOf[String] } map { _.asInstanceOf[String] }
Which is pretty ugly. Of co...
I have used ObservableCollection<T> in the past, but that seems to belong to WPF and therefore .NET 3.
And if there isn't what would be the appropriate interface for that? INotifyPropertyChanged seems not to be a very good fit for collections, while INotifyCollectionChanged is again only supported in .NET 3 and higher.
...
If I have this class:
class Foo<T> implements SomeInterface
{
final private List<T> list = new ArrayList<T>();
final private Class<? extends T> runtimeClass;
public Foo(Class<? extends T> cl) { this.runtimeClass = cl; }
// method override from SomeInterface
@Override public boolean addChild(Object o)
{
...
I have a java application which uses JPA.
Say I have an entity called Product with name and price attributes (all entities have an id attribute).
Naturally I can get a List<Product> fairly easily (from a query or another entity), but often I want a List<String> (list of product names) or List<Long> (list of product prices or list of pr...
I have a List that is guaranteed to contain just one type object. This is created by some underlying code in a library that I cannot update. I want to create a List<ObjectType> based on the incoming List object so that my calling code is talking to List<ObjectType>.
What's the best way to convert the List (or any other object collect...
Hi there,
I have a collection of MyClass objects and i need to filter it by a combination of 17 fileds.
I implemented an object MyClassFilter with the 17 possible fields and the condition for each one and a method:
bool PassFilter(MyClass ObjectToEvaluate)
{
return PassFilterVal(this.Workstream, ObjectToEvaluate.WorkStream)
&& ...
Hello,
I am working on web application .net 3.5,asp.net,C#. In that i need to provide list of available printer at client side.
I have knowledge of how to get server side printers using
[1] System.Drawing.Printing.PrinterSettings.InstalledPrinters
[2] System.Management.ManagementObjectSearcher [using query "SELECT * FROM Win32_Prin...
Basically I want something like Dictionary<Tkey1, TKey2, TValue>, but not (as I've seen here in other question) with the keys in AND, but in OR. To better explain: I want to be able to find an element in the dictionary providing just one of the keys, not both.
I also think we should consider thread-safety and the ability to easily scale...
I have an application using JPA, Hibernate and ehcache, as well as Spring's declarative
transactions. The load on DB is rather high so everything is cached to speed things up,
including collections. Now it is not a secret that collections are cached separately
from the entities that own them so if I delete an entity that is an element of...
Is there a elegant way of obtaining only one Entry<K,V> from HashMap, without iterating, if key is not known.
As order of entry of entry is not important, can we say something like
hashMapObject.get(zeroth_index);
Although I am aware that there exist no such get by index method.
If I tried approach mentioned below, it would still ha...