I don't even think I have the question correct as I am just starting with generics and my knowledge isn't very great.
Say I have the following method:
public class Wrapper
{
public List<TInfoType> GetInfo<TInfoType>(Array data, EdmCmd edmCmd)
{
switch (edmCmd.meCmdType)
{
case EdmCmdType.EdmCmd_PostAdd:
...
A co-worker of mine asked me last week if it were possible in C# to extend a generic class from its generic parameter. He said it was possible in C++.
What he wanted makes actually sense. He wanted a generic decorator to annotate an arbitrary class with additional information. Something like:
pubic class Decorator<T> : T
{
public obj...
Hi folks,
been struggling with this for a couple of days now and still stumped.
i have a data structure that starts with containers that can hold other containers, and eventually leaf nodes. i'm looking for a way of being to iterate thru elements of a type directly, without pulling them into another collection so i can operate on them i...
Can I contain two different types in a collection? For example, can I have List< String U Integer > ?
...
I'm looking for best practices here. Sorry. I know it's subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this.
I have a custom object called Employee. That object has seven properties like name, phone, email, and so on. There is also a table in my SQL database called tblEmployees...
or the other way around?
I use generic lists all the time. But I hear occasionally about IEnumerables, too, and I honestly have no clue (today) what they are for and why I should use them. So, at the risk of having something on the net forever more proclaiming my ignorance, I humbly post this question.
...
Given the following models adapted from http://www.djangoproject.com/documentation/models/generic%5Frelations/
class TaggedItem(models.Model):
"""A tag on an item."""
tag = models.SlugField()
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeig...
Possible Duplicate:
IList<Type> to IList<BaseType>
I am programming in C# using .NET 2.0 and I don't understand why the cast below results in a null reference.
If you have an IList<IChild>, why can't you cast it to an IList<IParent> where IChild implements IParent.
using System.Collections.Generic;
namespace InterfaceTest
{
...
I am trying to do the following:
Given TypeInfo after reflecting on a LINQ-to-SQL object with various EntitySet<> child collections, retrieve the collection
Do some operations on the collection
The code below does not compile, obviously - just looking for another way to do this [Note, "Facade" is the L2S object in question). The thi...
When we declare (example) List<T> I can understand the declaration, but suppose I declare
IEnumerable<T<T1, T2>>
What did I actually declare?
Does it mean, IEnumerable<T> contains two generic types? (What is the way to use it?)
Can I have deep nested level like Person<T<T2<T3<P1,P2>>>>?
Simple example will really helpful.
...
Basically, I want a class to be able to implement two different versions of the same generic interface.
Consider this code
type
// a generic interface
ITest<T> = interface
['{6901FE04-8FCC-4181-9E92-85B73264B5DA}']
function Val: T;
end;
// a class that purports to implement two different types of that interface
TTe...
1)When I have
Static void Sample<T>(T a,T b)
Does the declaration Sample enforce that all parameters need to be of type T ?
2) Does the declaration Static void Sample(T a,T b) not a Generic method unless i specify
Sample<T>?
...
Following on from another question I asked, I wanted to understand a bit more about the Scala method TraversableLike[A].map whose signature is as follows:
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
Notice a few things about this method:
it takes a function turning each A in the traversable into a B
i...
public class StuffDoer<T>
{
// do stuff
}
I want that this is always of type string, so instead of doing this:
StuffDoer<string> stuffer = new StuffDoer<string>();
I want to be able to do this:
StuffDoer stuffer = new StuffDoer();
and if I need a StuffDoer of type int, just define that with generics.
StuffDoer<int> stuffer =...
I'm missing a trick here I think and can't believe I've never done this before. However, how can I cast a generic type using the as keyword?
[Serializable]
public abstract class SessionManager<T> where T : ISessionManager
{
protected SessionManager() { }
public static T GetInstance(HttpSessionState session)
{
// E...
Is it possible to constrain the type of generic to, say, two different classes?
Like so:
TSomeClass<T: FirstClass; T: SecondClass> = class
// ...
end;
(Sorry about the lack of formatting - the SO tool bar has disappeared from my browser).
I know the above won't compile, its only written so to give you guys an idea. I tried
TSomeCl...
In this code:
TTest<IntfT: IInterface> = class
protected
fObj : TInterfacedObject;
public
function GetVal: IntfT;
end;
How would I implement the GetVal function if I want it to return fObj as an IntfT?
I've tried:
result := fObj as IntfT;
and
fObj.QueryInterface(IntfT,result);
and
result := fObj as IInterface;
but noth...
I'm looking to create a set of functions which all implementations of a certain Interface can be extended to use. My question is whether there's a way to do this without using a proxy or manually extending each implementation of the interface?
My initial idea was to see if it was possible to use generics; using a parameterized type as t...
I have some code that works like the below. I was wondering if its possible to get a Type object for the generic type passed to the DoSomething function. I realise that T is a type parameter but how would i turn this into a type object. The dosomething function is in a class where I want to know the underlying type used by the list ob...
When i need to pass a Generic Type I can use the Syntax
(Example : Ofcourse it is not a Generic Method)
public void Sample(T someValue)
{
......
}
What is the benefit of declaring Sample<T> ?
I mean
public void Sample<T> (T someValue)
{
......
}
...