Convert a BindingList<T> to an array of T
What's the easiest way to convert a BindingList<T> to a T[] ? EDIT: I'm on 3.0 for this project, so no LINQ. ...
What's the easiest way to convert a BindingList<T> to a T[] ? EDIT: I'm on 3.0 for this project, so no LINQ. ...
In the code below, I would like the second method to be generic, too, but since I create the Calendar object inside the method, because of type erasure, I don't see how. One possibility would be to pass in the Calendar object, but that would defeat the main purpose for having this method at all (not having to think about the Calendar obj...
In this question, TofuBeer was having problems creating a genericized IterableEnumeration. The answer came from jcrossley3 pointing to this link http://www.javaspecialists.eu/archive/Issue107.html which pretty much solved the problem. There is still one thing I don't get. The real problem, as effectively pointed out by erickson, was ...
What is the most efficient way to remove alternate (odd indexed or even indexed) elements in an List<T> without using a place holder list variable? Also it would be appreciated if you could mention the cost with each of your answer. I'm looking for an efficient way to do this Thanks in advance ...
What does where T : somevalue mean? I just saw some code that said where T : Attribute. I think this has something to do with generics but I am not sure what this means or what it is doing. Does anyone know? ...
Here is some code that I can't seem to understand how it works. I know it is using generics but what does the "new" in the where clause mean? public class MediaPresenter<T> where T : Media, new() { public MediaPresenter(string mediaPath, params string[] extensions) { _mediaPath = mediaPath; _fileExtensions =...
Before the introduction to generics to the Java language I would have written classes encapsulating collections-of-collections-of-collections. For example: class Account { private Map tradesByRegion; //KEY=Region, VALUE=TradeCollection } class TradeCollection { private Map tradesByInstrument; //KEY=Instrument, Value=Trade } Of ...
Does anyone have any idea what the practical differences are between the System.Collections.Specialized.StringDictionary object and System.Collections.Generic.Dictionary? I've used them both in the past without much thought as to which would perform better, work better with Linq, or provide any other benefits. Any thoughts or suggestio...
Why can an IEnumerable = null be passed without error but an IList=Null will not compile? ...
var _pool = new Dictionary<Type, Dictionary<EntityIdType, Object>>(); public IEnumerable<EntityType> GetItems<EntityType>() { Type myType = typeof(EntityType); if (!_pool.ContainsKey(myType)) return new EntityType[0]; //does not work, always returns null // return _pool[myType].Values; as IEnumerable<EntityType...
FIXED The problem was fixed by simply telling netbeans to do a clean rebuild of my application. Thanks for your comments guys. I've tried to create a generic Observable class that I can use in my program: public class GeoGolfObserver<T> extends Observable { public GeoGolfObserver() { super(); } public void p...
I want to make a List and add derived classes to this list. I see here that this is not possible by design in .NET: http://msdn.microsoft.com/en-us/library/aa479859.aspx#fundamentals_topic12 So what is the best practice solution to this? I guess I can box my derived classes to make them look like my superclass but that feels a little ...
Let's say I have a data object, but this object can hold one of several types of data. class Foo { int intFoo; double doubleFoo; string stringFoo; } Now, I want to create an accessor. Some way to get at this data. Obviously, I could create multiple accessors: public int GetIntFoo(); public double GetDoubleFoo(); public ...
I have an object that I ended up with via a reflection call: object readOnlyCollectionObject = propertyInfo.GetValue(someEntity, null); I know this object is a generic ReadOnlycollection. It could be a ReadOnlyCollection<Cat>, ReadOnlyCollection<Dog>, etc. For argument sake, lets just say it is a ReadOnlyCollection<T>. Even though a D...
I wanted to create an interface for copying an object to a destination object of the same class. The simple way is to use casting: import org.junit.Test; import org.junit.internal.runners.JUnit4ClassRunner; import org.junit.runner.RunWith; @RunWith(JUnit4ClassRunner.class) public class TestGenerics { public static interface Copyable { ...
I have two parallel inheritance chains: Chain1: Animal <- Lion <- Gazelle Chain2: Food <- Meat <- Grass I want to implement the "Eats" polymorphic property on Animal. This is how it looks like: public abstract class Animal { public abstract Food Eats { get; set;} } public class Lion : Animal { public override F...
If I want to use objects as the keys for a Dictionary, what methods will I need to override to make them compare in a specific way? Say I have a a class which has properties: class Foo { public string Name { get; set;} public int FooID {get; set;} ... } And I want to create a: Dictionary<Foo, List<Stuff>> I want Foo ob...
I'd like to implement a method that takes an Object as argument, casts it to an arbitrary type, and if that fails returns null. Here's what I have so far: public static void main(String[] args) { MyClass a, b; a = Main.<MyClass>staticCast(new String("B")); } public static class MyClass { } public static <T> T staticCast(Objec...
I need to validate an object to see whether it is null, a value type, or IEnumerable<T> where T is a value type. So far I have: if ((obj == null) || (obj .GetType().IsValueType)) { valid = true; } else if (obj.GetType().IsSubclassOf(typeof(IEnumerable<>))) { // TODO: check whether the generic parameter is a value type. } ...
I have a repository base class that gets called from my controllers in my mvc application Each controller gets it own repository like this public class ServiceRepository : Bluegrass.Mvc.RepositoryBase<Models.Service> { public ServiceRepository() { this._db = new iSppms.Models.iSppmsDataContext(); } } And gets us...