I knew than one of the benefits from using repository pattern make it easy to switch between ORM, for example will implement data access code using Linq to sql and also using Ado.net entity framework, then using Dependency injection switch which one to use.
I saw KIGG doing the same "but its class diagram is complicated a little, at lea...
i want to dispatch messages to specific handlers through a common message processor
//
// Library code
//
abstract class Processor<M extends MessageHandler<? extends Message>> {
HashMap<Class<Message>, M> handlerMap;
void addHandler(M, Class<Message>);
void run() {
while(true) {
...
}
}
/...
I have a List that is guaranteed to contain just one type object. This is created by some underlying code in a library that I cannot update. I want to create a List<ObjectType> based on the incoming List object so that my calling code is talking to List<ObjectType>.
What's the best way to convert the List (or any other object collect...
Hi all,
I have a dumb silly question, but sometimes you have to ask them anyways.
I got an Object[] instance in my left hand (it comes from non-generic swing) and a method that accepts a let's say Integer[] as its argument (in my case it's actually a vararg) in my right hand. I'm sure of the content of the array (or I'm ready to pay t...
I have a situation in code where a Dictionary<string, string> seemed like the best idea - I need a collection of these objects and I need them to be accessible via a unique key. Exactly what the Dictionary concept is for, right?
Well, the requirements have expanded to the point where I now need to hold an additional bit of information p...
Hi,
I am using C# and ASP.NET 3.5.
I stored a generic list in HttpContext.Current.Application so that all the pages of a website can have access to it. When I assign its value to a local variable on a local page for some local use, any change I make to the local variable gets reflected back in the original list in the Application State...
I'm having some problems with using generics in combination with parallel class hierarchies. I have coded myself into this mess several times already.
Let's say I have the following class hierarchies:
TableColumn -> subclasses SqlTableColumn, OracleTableColumn
Table -> subclasses SqlTable, OracleTable
Database -> subsclasses SqlDatabase...
I'm looping all the properties in an object via reflection:
For Each p As PropertyInfo In values.[GetType]().GetProperties()
If p.CanRead Then
'Do stuff
End If
Next
Can anyone tell me how to determine whether the property in question is a generic List(Of T)? If it is I need to loop the list it...
Basically I want something like Dictionary<Tkey1, TKey2, TValue>, but not (as I've seen here in other question) with the keys in AND, but in OR. To better explain: I want to be able to find an element in the dictionary providing just one of the keys, not both.
I also think we should consider thread-safety and the ability to easily scale...
I'm fairly new to generics so I wonder if somebody can explain the following problem I'm having. In virtually all my controllers in an ASP.NET MVC application I need to return a filtered list (to populate a JqGrid as it happens where the user will have specified certain filtering criteria). Each controllers list method will return a diff...
Hi all,
Surfing on the source code of Java, I found the following declaration:
public abstract class Enum<E extends Enum<E>>
How should it be interpreted? I'm stuck with it...
Thank you.
...
I'm designing a validation service and I'm debating between two different method signatures for Validate(). Both use lambda Expressions to get the object type and property of the object to validate the given value. There are defined as:
public interface IValidationService
{
/// <summary>
/// Validates the value of the property r...
In the signature of a method I specify a Func, like so:
public void Method (Func<string, bool> func)
In LINQ, which method (from IEnumerable) will let me pass in a Func from the method parameter to the LINQ query? The other issue is, my func can have any type parameter(s) so the Method from IEnumerable/LINQ must support generic type p...
Hi everyone,
I have a specialized class, BusinessObjectList, with this declaration:
public class BusinessObjectList<T> : List<BusinessObject> where T: BusinessObject {}
And I want to serialize objects of this class, like:
info.AddValue("myList", myList);
I tried to add the interface ISerializable, but with no success.
public cla...
I've defined a generic class "Lazy<T>", for lazy evaluation and caching of the result of a delegate Func<T>.
I also define two implicit cast operators so I can create a Lazy<T> from a Func<T>s, and I can assign a Lazy<T> to a T (gets the Value of the Lazy<T>)
The idea is that you can pass around a Lazy<T> in place of an instance of T, ...
So, the group I work with has reduced the amount of code we have to type for certain things. In this case, a Spring web page that displays a list using the DisplayTag libraries. The way it's done is with a class using generics extending the Controller object, and then a subclass of that for each page it should work on.
This controller...
I have the following code
String innerText = null;
innerText = this.getException(detail.getChildElements());
causing this warning
Type safety: The expression of type Iterator needs unchecked conversion to conform
to Iterator
The referenced method is
private String getException(Iterator<OMElementImpl> iterator) { ... }
The...
Assuming a base type of "Message"...
Public Class Message
Public ID As Int64
Public Text As String
Public MessageType as String
End Class
...and then two derived classes...
Public Class PhoneMessage
Inherits Message
Public MessageLength As Int64
End Class
Public Class MailMessage
Inherits Message
Public Postage ...
I have a C# class to store my User details and another for storing JOBS details.The scenario is like each User can have multiple JOBS. I have UserId,UserName,Age etc as my User class properties. Now i want to associate the of JOBS class objects to a property called JOBS so that i can store multiple jobs associated with this user to that...
I have an interface A, which class B implements.
The following generic method works
public static <T, U extends T> List<T> listFactory(Collection<U> source) {
return new ArrayList<T>(source);
}
but
public static <T> List<T> listFactory(Collection<? extends T> source) {
return new ArrayList<T>(source);
}
does not (compilation err...