I'm writing an immutable binary tree class where all of the methods (Insert, Remove, RotateLeft, etc) return a new instance of a tree instead of modifying it in place.
I'm going to be creating lots of different implementations of tree: Avl tree, red-black tree, splay tree, etc. I have the following:
public class AbstractBinaryTree<Tree...
Hi, I am refactoring a part of our legacy app which handles exporting and importing of DB tables from/to Excel sheets. We have a Formatter subclass for each table, to provide the definition of that table: how many columns it has, and what is the name, format and validator of each column. The getters which supply this data are then called...
I have the following code:
private static final Set<String> allowedParameters;
static {
Set<String> tmpSet = new HashSet();
tmpSet.add("aaa");
allowedParameters = Collections.unmodifiableSet(tmpSet);
}
And it cause:
Note: mygame/Game.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for detai...
I have the following code:
class Program
{
static void Main(string[] args)
{
new Program().Run();
}
public void Run()
{
// works
Func<IEnumerable<int>> static_delegate = new Func<IEnumerable<int>>(SomeMethod<String>);
MethodInfo mi = this.GetType().GetMethod("SomeMethod").MakeGeneri...
Hi everybody!
How do i setup the configuration in XML (for Windsor Castle) for the following class?
public class Repository<T> : IRepository<T> where T : class
{
....
}
I know how to do it in code but i must use XML file
Thanks in advance
...
Hey, I have one quick question... by using generics, do I completely get rid of boxing/unboxing operations?
For example, by using a List do I still get lots of boxing/unboxing?
I've read several docs on the internet but couldn't solve this specific question...
Thnaks in advance.
...
I'm refatoring a home-grown DAO container, hoping to make the class generic. It internally uses an ArrayList to store the retrieved objects.
One usage of this class puts the container's list into a request scope, and due to a limitation of Websphere, I can't pass the generic List<Foo> to the request scope (Websphere doesn't handle gener...
Hi all,
I have
class A
{}
class B : A
{}
I also have a method that expects a List parameter
void AMethod(List<A> parameter)
{}
Why can't I
List<B> bs = new List<B>();
AMethod(bs);
And secondly what is the most elegant way to make this work?
regards
...
i have a method as follows.
test(Object obj){
}
now within this method i want to get all fileds along with the datatypes of those fileds.
How can i do that??
...
I have the following decleration:
private Dictionary<string, Dictionary<string, File>> listFiles = new Dictionary<string,Dictionary<string,File>>();
How do i add an item to the dictionary? Is there a better way to do something like this?
Info: That stores a sourcefilename, destinationfilename, and the file itself.
Edit1: Just figured...
I have a list of integers that I would like to search for a sequence.
For example, if i have a master list:
1, 2, 3, 4, 9, 2, 39, 482, 19283, 19, 23, 1, 29
And I want to find sequence:
1, 2, 3, 4
I would like some easy way to fill a subset list with:
1, 2, 3, 4 + the next five integers in the master list
And then remove the integers ...
Why is this disallowed in C#?
Actually I'd like to be able to write
alias Y<A, B> : X<A, B>, X<B, A>
The unification is actually desired here; if the A = B then just one method should be defined.
...
I've got a data structure that is Key, Value, OtherValues(key, Value). So the OtherValues are attached to the first Key and aren't always there. I can do this as Dictionary<Key, ValueAndListOfOptionalValues> where ValueAndListOfOptionalValues is a class with a string and a Dictionary<string, string>.
I'm wondering if that's really the...
I'm trying to make use of the TheoryAttribute, introduced in NUnit 2.5. Everything works fine as long as the arguments are of a defined type:
[Datapoint]
public double[,] Array2X2 = new double[,] { { 1, 0 }, { 0, 1 } };
[Theory]
public void TestForArbitraryArray(double[,] array)
{
// ...
}
It does not work, when I use generics:
[D...
I have the following methods:
public <T> T fromJson( Reader jsonData, Class<T> clazz ) {
return fromJson( jsonData, (Type)clazz );
}
public <T> T fromJson( Reader jsonData, Type clazz ) {
...
}
The compiler is saying about the first method:
type parameters of <T>T cannot be determined;
no unique maximal instance exists for...
I just used StructureMap few days ago. I use StructureMap for collecting all validator class like the following code.
public class BaseClassA {}
public class ClassB : BaseClassA {}
public class ClassC : BaseClassB {}
public BaseClassAValidator : IValidator<BaseClassA>() {}
In StructureMap, I only register IValidator interface for B...
I am attempting to bind c# generics to a class and an interface like this:
public class WizardPage<T> where T : UserControl, IWizardControl
{
private T page;
public WizardPage( T page ) {
this.page = page;
}
}
And use it with this:
public class MyControl : UserControl, IWizardControl {
//...
}
Somehow C# do...
UPDATE: I should have mentioned in the original post that I want to learn more about generics here. I am aware that this can be done by modifying the base class or creating an interface that both document classes implement. But for the sake of this exercise I'm only really interested in solutions that do not require any modification to t...
I wonder if C# (or the underlying .NET framework) supports some kind of "generic delegate instances": that is a delegate instance that still has an unresolved type parameter, to be resolved at the time the delegate is invoked (not at the time the delegate is created). I suspect this isn't possible, but I'm asking it anyway...
Here is an...
Hi,
I'm trying to invoke this method in spring.net, but i'm having trouble getting the configuration right.
Method:
public void AddRepository<TEntity>(IRepository<TEntity> repository)
where TEntity : IEntity
{
Repositories.Add(repository.GetType().Name, repository);
}
Config:
<object type="Spring.Objects.Factory.Config.Method...