So I have a simple validation rule pattern that I'm using to do validation on entity objects. Here is my ValidationRule class:
public class ValidationRule {
public Func<object, bool> Rule { get; set; }
public string ErrorMessage { get; set; }
public ValidationRule(string errorMessage, Func<object, bool> rule) {
R...
I have a class named Customer (with typical customer properties) and I need to pass around, and databind, a "chunk" of Customer instances. Currently I'm using an array of Customer, but I've also used Collection of T (and List of T before I knew about Collection of T). I'd like the thinnest way to pass this chunk around using C# and .NET ...
Intersection types allow you to (kinda sorta) do enums that have an inheritance hierarchy. You can't inherit implementation, but you can delegate it to a helper class.
enum Foo1 implements Bar {}
enum Foo2 implements Bar {}
class HelperClass {
static <T extends Enum<T> & Bar> void fooBar(T the enum) {}
}
This is useful when you ha...
Why is the following seen as better than the old way of casting?
MyObj obj = someService.find(MyObj.class, "someId");
vs.
MyObj obj = (MyObj) someService.find("someId");
...
Consider the following code:
string propertyName;
var dateList = new List<DateTime>() { DateTime.Now };
propertyName = dateList.GetPropertyName(dateTimeObject => dateTimeObject.Hour);
// I want the propertyName variable to now contain the string "Hour"
Here is the extension method:
public static string GetPropertyName<T>(this IList<...
I am trying to create a generic list class for use with tiOPF (an Object Persistence Framework for delphi @ www.tiopf.com). Specifically I am trying to take an existing generic class (TtiObjectList) and make a generic version that uses TtiObject descenants.
I have limited scope for altering the base classes as they need to compile und...
I am currently looking to make my own collection, which would be just like a regular list, except that it would only hold 10 items. If an item was added when there were already 10 items in the list, then the first item would be removed before the new item was appended.
What I want to do is create a class that extends System.Collections....
Hi,
I am struggling with setting up StructureMap without the use of the
generic fluent interface,
I can't use the generic methods, because I don't know the types at
design time.
Ie:
To choose a default constructor the only method I could find is using
'SelectConstructor<T>()', but I only know the type at runtime...
This is related: ...
In C# some collections such as ArrayList and HashTable have generic alternatives which are List<T> and Dictionary<TKey, TValue>.
Does Array also have a generic alternative?
...
I have a routine
public void SomeRoutine(List<IFormattable> list) { ... }
I then try to call this routine
List<Guid>list = new List<Guid>();
list.Add(Guid.NewGuid());
SomeRoutine(list);
And it fails with a compile-time error. System.Guid implements IFormattable, but the error I get is
cannot convert from
'System.Collections....
When calling a method that adds an object to a collection in GWT I get a null pointer error. I have no idea why as everything I have done creates a very simple object (only contains a string). Here is the code that calls the function and the function:
public class PlantMenu extends VerticalPanel {
private Collection<PlantData> pl...
Boy, I am sure am messing around with a lot of casting and such in this code below. It seems like there should be a smoother way. I'm basically trying to use a builder method (CreateNewPattern) to handle creating new objects of the passed sub-class type (by the CreateNewCircularPattern and CreateNewLinePattern methods). I presently only ...
class Program
{
static void Main(string[] args)
{
mylist myitems1 = new mylist("Yusuf","Karatoprak");
SelectedItemsList slist = new SelectedItemsList();
slist.Items.Add(myitems1);
foreach( object o in slist.Items)
Console.Write(o.ToString()+"\n");
...
How can i make the following code compile?
Action<MyClass<object, object>> func = x => Console.WriteLine(x.ToString());
public void Apply<T1, T2>(MyClass<T1, T2> target)
{
func.Invoke(target);
}
I know it doesnt work because a MyClass<T1, T2> isnt a MyClass<object, object>, but what can i do?
Can i make the f...
Hello, and thanks for any assistance.
How would I return from a method an unknown Generic.List type.
public void Main()
{
List<A> a= GetData("A");
}
public List<T> GetData(string listType)
{
if(listType == "A")
{
List<A> a= new List<A>()
...
return a;
}
else
{
List<B> b = new List<B>()
...
I have a generic method which has two generic parameters. I tried to compile the code below but it doesn't work. Is it a .NET limitation? Is it possible to have multiple constraints for different parameter?
public TResponse Call<TResponse, TRequest>(TRequest request) where TRequest : MyClass, TResponse : MyOtherClass
Thanks!
...
In C# I can do actually this:
//This is C#
static T SomeMethod<T>() where T:new()
{
Console.WriteLine("Typeof T: "+typeof(T));
return new T();
}
//And call the method here
SomeMethod<SomeClassName>();
But for some reason I can't get it to work in Java.
The thing I want to do is, to create a static method on a superclass, so the...
Hi,
Having the following generic class that would contain either string, int, float, long as the type:
public class MyData<T>
{
private T _data;
public MyData (T value)
{
_data = value;
}
public T Data { get { return _data; } }
}
I am trying to get a list of MyData<T> where each item would be of differen...
A)
List<? super Shape> shapeSuper = new ArrayList<Shape>();
shapeSuper.add(new Square()); //extends from SHAP
shapeSuper.add(new DoubleSquare()); //extends from SQ
shapeSuper.add(new TripleSquare()); //extends from DS
shapeSuper.add(new Rectangle()); //extends from SHAP
shapeSuper.add(new Circle()); //extends f...
I have a generic method that copies values between value types. The following approaches give a design time error, even with the struct constraint. Any idea how I can copy or cast between the values?
private Ttgt MyMethod<Tsrc,Ttgt>(Tsrc SourceObject)
where Tsrc:struct
where Ttgt:struct
{
//Error:cannot ...