I am trying to provide an interface to an abstract generic base class. I want to have a method exposed on the interface that consumes the generic type, but whose implementation is ultimately handled by the classes that inherit from my abstract generic base.
However I don't want the subclasses to have to downcast to work with the generi...
I have a class
public class A<T>
{
public static string B(T obj)
{
return TransformThisObjectToAString(obj);
}
}
The use of string above is purely exemplary. I can call the static function like this just fine on a known/specified type:
string s= A<KnownType>.B(objectOfKnownType);
How do I make this call, if I don't ...
I am trying to figure out a way to leverage generics so I can make the property Value be an actual type that initialized (not sure if this is the correct way of saying it) when my collection class is created.
I would like to have the syntax be something like:
var list = new ListItemCollection<Guid>(parameters would go here);
I have t...
I have a method like the following:
public IEnumerable<T> GetControls<T>()
: where T : ControlBase
{
// removed.
}
I then created a class:
public class HandleBase<TOwner> : ControlBase
: TOwner
{
// Removed
}
I'd like to be able to call
GetControls<HandleBase<this.GetType()>>;
where it would use the type of THIS class to pa...
Is it possible to pass a generic type T into an instance of a winform so T is usable throughout the form?
...
I have a problem when compiling a generic class with an inner class. The class extends a generic class, the inner class also.
Here the interface implemented:
public interface IndexIterator<Element>
extends Iterator<Element>
{
...
}
The generic super class:
public abstract class CompoundCollection<Element, Part extends Collecti...
How to split an IEnumerable of IEnumerables to one flat IEnumerable using LINQ (or someway else)?
...
I'm writing a couple of classes that all have generic type arguments, but I need to overload the classes because I need a different number of arguments in different scenarios. Basically, I have
public class MyGenericClass<T> { ... }
public class MyGenericClass<T, K> { ... }
public class MyGenericClass<T, K, L> { ... }
// it could go...
I was wondering if anyone could tell me if this kind of behaviour is possible in C# 4.0
I have an object hierarchy I'd like to keep strongly typed. Something like this
class ItemBase {}
class ItemType<T> where T : ItemBase
{
T Base { get; set; }
}
class EquipmentBase : ItemBase {}
class EquipmentType : ItemType<EquipmentBase> {}...
I have a list of dates that a machine has worked on, but it doesn't include a date that machine was down. I need to create a list of days worked and not worked. I am not sure of the best way to do this. I have started by incrementing through all the days of a range and checking to see if the date is in the list by iterating through the e...
Hi,
I am currently working with .Net 2.0 and have an interface whose generic type is used to define a method's return type. Something like
interface IExecutor<T> {
T Execute() { ... }
}
My problem is that some classes that implement this interface do not really need to return anything.
In Java you can use java.lang.Void for this p...
I have to confess that I hate membership provider. The default implementation is not very appropriate normally and I haven't seen so far a good implementation of a custom membership provider, probably because this is not possible :-)
So the question is:
In your opinion: which are the reasons for not having membership/role provider as a...
I'd like to create a lot of extension methods for some generic class, e.g. for
public class SimpleLinkedList<T> where T:IComparable
And I've started creating methods like this:
public static class LinkedListExtensions
{
public static T[] ToArray<T>(this SimpleLinkedList<T> simpleLinkedList) where T:IComparable
{
//// c...
I am porting some C# code over to Java. I am having trouble with the where Syntax, specifically new(). I understand that where is similar to Java's generic: T extends FOO.
How I can replicate the new() argument in Java?
"The new() Constraint lets the compiler know that any type argument supplied must have an accessible parameterless--...
Here's a design-view screenshot of my dbml-file.
The relationships are auto-generated by foreign keys on the tables.
When I try to serialize a query-result into JSON I get a circular reference error..:
public ActionResult Index()
{
return Json(new DataContext().Ingredients.Select(i => i));
}
But if I create my own collection ...
In the above declaration, what is the <T> for?
I would like to know the difference between having <T> and not having it? How does it affect the code?
...
To accomplish this (but failing to do so) I'm reflecting over properties of an expected and actual object and making sure their values are equal. This works as expected as long as their properties are single objects, i.e. not lists, arrays, IEnumerable... If the property is a list of some sort, the test fails (on the Assert.AreEqual(...)...
I have a problem using a parameterized class as the key-type of a Map. First create the parameterized class:
scala> sealed abstract class Foo[T]{ def t: T }
defined class Foo
Now create some imaginary collection of these across unknown parameters:
scala> var l: List[Foo[_]] = Nil
l: List[Foo[_]] = List()
Now create a Map to store ...
UPDATE: this is a duplicate of
Is the StaticFactory in codecampserver a well known pattern?
...
Hi,
My interface definition is:
public interface IInterface where T:UserControl
My class definition is:
public partial class App1Control : UserControl, IInterface
The unity section of my app.config looks as below:
<unity>
<typeAliases>
<typeAlias alias="singleton" type="Microsoft.Practices.Unity.Contai...