I'm trying to write a method which takes a Map[K, Collection[V]] and converts it to a map with a different type of Collection for its values. The method takes the "multimap" and a builder that will construct the new collections. I use it like this:
val multimap = new java.util.HashMap[Int, java.util.List[String]]
multimap.put(1, Arrays....
Hi,
I was wondering if there was a more elegant way than this example to use generic type as generic parameter:
public class Wrapper<TObject>
where TObject : MyBaseClass
{
}
public class WrapperCollection<TWrapper, TObject> : Collection<TWrapper>
where TWrapper : Wrapper<TObject>
where TObject : MyBaseClass
{
}
Actually,...
var mergedInstance = MergeFactory<InterfaceOne, InterfaceTwo>();
((InterfaceOne)mergedInstance).InterfaceOneMethod();
((InterfaceTwo)mergedInstance).InterfaceTwoMethod();
Can anyone recommend a design pattern or exact syntax that would make something like this work?
Inside the MergeFactory, I'm picturing something like this going on:...
Implementing Document-View pattern I faced the problem: standard generic collections and dictionaries (List<T>, HashSet<T> for example) don't provide events for modification (OnBeforeAdd, OnAfterAdd, OnRemove, Freeze/Unfreeze methods... )
I suppose events were not implemented for optimization purposes but I have to use and listen for s...
This question is strongly connected to this answer to "How to reference a generic type in the DataType attribute of a HierarchicalDataTemplate?"
I followed the basic idea of that answer and created this data structure:
<!-- for DictItemVM<string, Remote.Address> which is a viewmodel for a KeyValuePair<...> -->
<x:Array Type="{x:Type sy...
I am calling a function that returns an object and in certain circumstances this object will be a List.
A GetType on this object might gives me:
{System.Collections.Generic.List`1[Class1]}
or
{System.Collections.Generic.List`1[Class2]}
etc
I don't care what this type is, all I want is a Count.
I've tried:
Object[] methodArgs=...
I've looked through similar questions and have come up short, so here it goes;
public interface Predicate<T>{
boolean apply(T t);
}
public interface Function<F, T>{
T apply(F f);
}
public class ConcretePredicate extends Predicate<Foo>, Function<Bar, Boolean>{
@Override
public boolean apply(Foo foo){/*stuff*/}
@Overr...
Background:
I'm trying to implement a tab control. The tabs are as follows:
| Funds | Companies | Groups |
and are implemented as follows:
<ul class="ActionControl">
<li>
<%=Html.ActionLink(string.Format("Funds ({0})", Model.Summary.FundCount)
, "ResultsList", new {selectedTab = "Funds"} ) %>
</li>
//...
I have 3 types of objects: Red, Green, and Blue. I have 3 kinds of devices that handle each type of object, respectively. No device can handle more than 1 type of object. Each "object handler" has a reference to an object which it is currently handling.
In Java I'd do something like this:
public class RedObject {}
public class GreenObj...
Hi,
C# Language spec says:
The substitution process is based on
the semantic meaning of type
declarations, and is not simply
textual substitution.
I Apperciate if somebody could explain what above line means.
Thanks.
...
I'm not sure if this is possible in Delphi. I've looked around and can't seem to find an answer (Example or inidaction that it's not possible):
I have a generic list class, and I want to create an instance of the generic type. For example:
type
TTypeA = class(TObject);
procedure Test;
var
MyList: TobjectList<TTypeA>;
NewListObje...
I know its a common question asked several times on SO. But help me either way. Actually I have to upload data from my local machine to remote sql database. The remote sql database has a single table where 800,000 records are there. Now from here i have around 1,21311 records locally in my system, from which 75% records already exists on...
I frequently seems to come up to a situation where I have an abstract type which needs to be processed differently depending on which concrete implementation it has.
As an example, an abstract class Payment could be subclassed as class CreditCard or class StoredCredit. To actually process the payment, we want to use an implementation...
I'd like to start using generics and anonymous method, mainly to learn what that's all about and why I would want to use them.
Having Delphi 2009, I often read that generics and anonymous methods are not completely implemented or buggy, which was fixed in Delphi 2010.
I would like to avoid having to wonder if it's my fault or a bug in ...
I'm working with .NET Compact Framework and just started to refactor some UI code. I'm defining a base user control to encapsulate common functionality, the project compiles OK but when I try to open a child user control in design mode I'm getting an error.
I made my class hierarchy taking into account this question. My classes are like...
My code is simply:
public override C Calculator<C>(Team[] teams, Func<Team, C> calculatorFunc)
{
return teams.Average(calculatorFunc);
}
I get this error:
Error 2 The type arguments for method 'System.Linq.Enumerable.Average(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the u...
I need to be able to, at runtime, load two classes that share an unknown type, like this:
interface IProducer<out A>
{
public A CookOne();
}
interface IConsumer<in A>
{
public void EatOne(A food);
}
The entire list of possible involved types can't be known at compile time because they don't exist yet. The software that uses t...
I have a few domain model classes in my web app that have a hierarchical relationship to themselves. An example of one is the hierarchical category structure used to classify users postings.
There is some logic relating to the hierarchical nature of these classes that is common. So I tried to move the logic into a generic @MappedSupercl...
Here's my strategy for choosing which C# collection type to use:
if number of items in collection is fixed, then use an array, e.g.:
string[] directions = new string[] { "north", "south", "east", "west" };
otherwise always use List<T>
unless of course you need a more specialized collection, e.g. Stack<T>, Queue<T>, or Dictionary<TKey,...
I have a generics class Foo<T>. In a method of Foo, i want to get the class instance of type T. But i just can't call T.class
Please tell me your preferred way to get around with the T.class ?
...