Ok I have a generic interface
public IConfigurationValidator<T>
{
void Validate();
}
a class that implements it:
public class SMTPServerValidator : IConfigurationValidator<string>
{
public void Validate(string value)
{
if (string.IsNullOrEmpty(value))
{
throw new Exceptio...
I'm not sure what I'm wanting to do is even a good idea, but here's the problem anyway: I have MyClass which I want to implement two different types of the generic IEnumerable class, e.g.
public class MyClass : IEnumerable<KeyValuePair<string, string>>,
IEnumerable<KeyValuePair<MyEnum, string>>
Now, the problem...
I'm working on a CRUD testing class because I got tired of duplicating the same test patterns when validating my NHibernate mappings.
I've refactored the code and have reached the point where everything is working the way I envisioned it with one glaring irritation. Everything is based on strings which are used by reflection methods t...
Hi
Why can I not cast a List<ObjBase> as List<Obj>? Why does the following not work:
internal class ObjBase
{
}
internal class Obj : ObjBase
{
}
internal class ObjManager
{
internal List<Obj> returnStuff()
{
return getSomeStuff() as List<Obj>;
}
private List<ObjBase> getSomeStuff()
{
...
Hi All,
I'm trying to figure a way to create a generic class for number types only, for doing some calculations.
Is there a common interface for all number types (int, double, float...) that I'm missing???
If not, what will be the best way to create such a class?
UPDATE:
The main thing I'm trying to achieve is checking who is the bi...
The following method generates a warning, but it looks safe to me. I'm sure the problem is with me:
public <S extends CharSequence> S foo(S s) {
return (S) new StringBuilder(s);
}
It looks like this will always return the argument s. Can anyone show an example that would cause this method to throw an exception?
Edit: I'm not p...
Yesterday I attempted to create an array of objects, belonging to a non-static inner class of a generic class. It seems that there is no nice way of doing so.
First attempt:
public class Wibble<T>{
public static void main(String...args){
new Wibble<String>();
}
public Wibble(){
Bar...
Got this idea from this previous question.
http://stackoverflow.com/questions/529085/java-how-to-generic-array-creation
Anyway, my code is like this:
public class Slice<E>
{
private E[] data;
public Slice(Class<E> elementType, int size)
{
//@SuppresWarnings({"unchecked"})
data = (E[])Array.newInstance(elementType...
I would like to do something like the below
public interface IFormatter<TData, TFormat>
{
TFormat Format(TData data);
}
public abstract class BaseFormatter<TData> : IFormatter<TData, XElement>
{
public abstract XElement Format(TData data);
}
However, when I do the above I get an error about "The type or method has 2 generic p...
I have a set-up similar to WPF's DependencyProperty and DependencyObject system. My properties however are generic. A BucketProperty has a static GlobalIndex (defined in BucketPropertyBase) which tracks all BucketProperties. A Bucket can have many BucketProperties of any type. A Bucket saves and gets the actual values of these BucketProp...
Hi all,
I want to check if a generic variable is of a certain type but don't want to check the generic part.
Let's say I have a variable of List<int> and another of List<double>. I just want to check if it is of type List<>
if(variable is List) {}
And not
if (variable is List<int> || variable is List<double>) {}
is this possible...
Hi,
When doing some not really fancy things with Java, I came over an error with generics that I was not able to understand why it doesn't work. The code is:
package test;
import java.util.*;
public class TestClass {
public static class A extends C{}
public static class B extends C{}
public static class C{}
public static class ...
Since generics are only checked during compile time with Java 5, can they avoid ClassCastExceptions in all
situations?
...
Possible Duplicate:
Upcasting and generic lists
Ok, I want to send a List<CardHolder> as an IEnumerable<ICardHolder> where CardHolder : ICardHolder. However, the compiler errors:
Error 4 Argument '1': cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'
This seems strange to me...
Hi, I am trying to make an extension method that will shuffle the contents of a generic list collection regardless of its type however im not sure what to put in between the <..> as the parameter. do i put object? or Type? I would like to be able to use this on any List collection i have.
Thanks!
public static void Shuffle(this List<??...
If I want a method that returns the default value of a given type and the method is generic I can return a default value like so:
public static T GetDefaultValue()
{
return default(T);
}
Can I do something similar in case I have the type only as a System.Type object?
public static object GetDefaultValue(Type type)
{
//???
}
...
Can I pass a method with an out parameter as a Func?
public IList<Foo> FindForBar(string bar, out int count) { }
// somewhere else
public IList<T> Find(Func<string, int, List<T>> listFunction) { }
Func needs a type so out won't compile there, and calling listFunction requires an int and won't allow an out in.
Is there a way to do th...
I'm designing a reporting engine for my project. The project will have several reports, each of which can be expressed as a Linq query; some will have parameters, while others won't.
Now in order to meet my clients' requirements, I need to return the results of the queries in XML format, so that they can apply an XSL transform to make ...
I'm writing a system that has a set of protocol buffers (using protobuf-net), I want to define something like this in an abstract class they all inherit off:
public byte[] GetBytes()
however, the protocol buffer serealiser requires a type argument, is there some efficient way to get the type of the inheriting class?
Example:
public ...
What is
Type<Type> type;
called (opposed to)
Type type;
You know, where you put the angle brackets around the type? I use this a lot, but don't know the name - it's bugging me. It's very hard to search for - Google ignores the <> characters.
(note: this is Java)
...