Cannot call action method 'System.Web.Mvc.PartialViewResult FooT' on controller 'Controller' because the action method is a generic method
<% Html.RenderAction("Foo", model = Model}); %>
Is there a workaround for this limitation on ASP MVC 2? I would really prefer to use a generic. The workaround that I have come up with is to change...
Is it possible to do the following with generics in C#.NET
public abstract class A
{
public abstract T MethodB<T>(string s);
}
public class C: A
{
public override DateTime MethodB(string s)
{
}
}
i.e. have a generic method in a base class and then use a specific type for that method in a sub class.
...
I was reading a question on making a generic property, but I'm a little confused by the last example from the first answer (I've included the relevant code below):
You have to know the type at compile
time. If you don't know the type at
compile time then you must be storing
it in an object, in which case you can
add the follo...
The following code fails to compile (using VS2010) and I don't see why. The compiler should be able to infer that List<TestClass> is 'compatible' (sorry for lack of a better word) with IEnumerable<ITest>, but somehow it doesn't. What am I missing here?
interface ITest {
void Test();
}
class TestClass : ITest {
public void Te...
I have an application with lots of generics and IoC. I have an interface like this:
public interface IRepository<TType, TKeyType> : IRepo
Then I have a bunch of tests for my different implementations of IRepository. Many of the objects have dependencies on other objects so for the purpose of testing I want to just grab one that is val...
Yesterday I've implemented the code:
CustomerProductManager productsManager = container.Resolve<CustomerProductManager>();
It was compilable and working.
Today (probably I've modified something I am constantly getting the error:
The non-generic method
'Microsoft.Practices.Unity.IUnityContainer.Resolve(System.Type,
string, par...
Using Castle Windsor, I want to configure a generic service with a type parameter; and have it implemented by a known concrete type that implements the service with a specific type as the generic parameter. Expressed as a unit test, I would like to get the following to work:
[TestClass]
public class WindsorTests
{
[TestMethod]
p...
Please help me with this:
If Lion IS-A Animal and given Cage<T>:
Cage<? extends Animal> c = new Cage<Lion>(); // ok,
but
Set<Cage<? extends Animal>> cc = new HashSet<Cage<Lion>>(); // not ok
What I don't see here?
...
Browsing through Guava libraries I saw this weird signature on a readLines method from Files class:
public static <T> T readLines(File file,
Charset charset,
LineProcessor<T> callback)
I know a little bit about generics in java, but this baffled me.
What does the double T mean here...
Let's I have a method to remove duplicates in an integer Array
public int[] RemoveDuplicates(int[] elems)
{
HashSet<int> uniques = new HashSet<int>();
foreach (int item in elems)
uniques.Add(item);
elems = new int[uniques.Count];
int cnt = 0;
foreach (var item in uniques)
...
I have defined the following interface:
public interface IStateSpace<State, Action>
where State : IState
where Action : IAction<State, Action> // <-- this is the line that bothers me
{
void SetValueAt(State state, Action action);
Action GetValueAt(State state);
}
Basically, an IStateSpace interface should be something like a c...
UPDATE: After some additional reading, what I really wanted was guaranteed early binding (which should translated to an immediate call for non-virtual functions and non-PIC code), which can be done by passing a (member) function as a template parameter. The problem I had was that gcc < 4.5 and icc 11.1 can generate some funky instruction...
I remember seeing a question on my official MS 70-536 exam that talked about a simple class that was designed to be exposed for COM calling clients and etc. of all the members defined in the classes I chose the answer D. The one that used a generic.
My question to you guys is this: If you were designing a .net custom type that was to be...
Suppose I have a class T that I want to use as a key in a Dictionary<T,U> collection.
What must I implement in T so that these keys are based on values of T rather than T references?
I'm hoping it's just GetHashCode().
...
I have a method to which I pass an IEnumerable<TModel>. Then depending on the type of TModel, the method carries out a set of instructions as below:
public void MyMethod<TModel>(IEnumerable<TModel> items) where TModel : class
{
int operationType;
switch (typeof(TModel))
{
case typeof(MyModelOn...
I have a method that counts the number of Contacts each Supplier, Customer and Manufacturer has (this is a scenario to try make explaining easier!)
The models are all created by Linq to SQL classes. Each Supplier, Customer and Manufacturer may have one or more Contacts
public int CountContacts<TModel>(TModel entity) where TModel : clas...
I have a object with some TObjectList<>-fields that I try to encode as JSON with help form SuperObject.
TLogs = TObjectList<TLog>;
TMyObject = class(TObject)
private
FLogs: TLogs;
end;
Deep inside SuperObjects code, there is a ToClass procedure, iterating the fields and add them to the json result.
In this loop, there is a check on...
What are some good java interview questions and answers regarding generics and annotations?
...
Can someone tell me what the difference is between the following
public class CarCollection<T>:List<T> where T:Car{}
and
public class CarCollection:List<Car>{}
To me they seem to do the same thing, create type-safe collection of "Car" objects.
...
I am currently facing a very disturbing problem:
interface IStateSpace<Position, Value>
where Position : IPosition // <-- Problem starts here
where Value : IValue // <-- and here as I don't
{ // know how to get away this
// circular...