I've got an implementation similar to this: http://stackoverflow.com/questions/1710875/better-way-of-doing-strongly-typed-asp-net-mvc-sessions
for quick access to frequently-needed user data... but i have two questions:
1) will there ever be a time when a user is logged in, but the session would be invalid or reset? I always thought th...
In a recent question of mine I learned that if there are more than one extension methods with constraints that match the given type, the most specific one will be chosen. This got me thinking - how does the compiler determine which one is "more specific"? And what will the outcome be?
Let's say I have the following classes:
public MyCl...
Hi,
I am to adding genericity to one of my projects.
I love generics as this makes my code more robust, self-documented and erases all those ugly casts.
However, I came across a tough case and have some issues trying to express a "recursive" constraint for one of my structures.
This is basically some kind of "generic" tree, with dou...
What is the 'best' way to sort (or iterate) over a StringDictionary in order of Value (not Key)
E.g. Key - Value
1 - X label
2 - A label
3 - Other label
would give
2 - A label
3 - Other label
1 - X label
EDIT - I meant to say "using .NET 2.0 features". Sorry, me bad...
...
I want create a generic(genaral) method which accepts the return types of LINQ 2 SQL query (a list of objects- IEnumerable) againist different table as the parameter of the function. How can i define my parameter for the function ? I will use this function to bind the data to a grid.
Thanks in advance
...
I have the following setup
Class A
property x as string
property y as int
property z as String
End Class
Class CollOfA
inherits List(Of A)
End Class
What I would like is a Item property in the collection that I can say
dim c as new CollOfA
c.item("this", 2, "that")
I have tried implementing the following in CollOfA
C...
I'm trying to implement a service contract that contains a method which takes a generic interface, and that generic interface itself is given an interface parameter. I've decorated the service interface with ServiceKnownType, I have decorated the service implementation with regular KnownType, and I have decorated the datacontract impleme...
Hello all,
An easy one ;-)
I declared:
xmlns:om="clr-namespace:System.Collections.ObjectModel;assembly=System"
I try to set a generaic as the DataType:
<DataGrid d:DataContext="{
d:DesignInstance Type=om:ObservableCollection<System:Int32>}" />
But I'm receiving an error: "Invalid format for a type".
Anybody ha...
I'm having a heap of trouble with Java coming from a PHP background. I've got a parent class Entity containing generic database methods, such as a static method getById(int id). My aim is to have children of this class, such as Person, so that I can call:
Person p = Person.getById(1);
At the moment this doesn't work, as getById(1) re...
I discovered that a list of concrete objects cannot be added to a list of interface object.
public static void AddJob(List<IJob> masterJobs, List<Job> jobs)
{
masterJobs.AddRange(jobs); //fail to compile
}
Instead, one needs to use the following code:
public static void AddJob(List<IJob> masterJobs, List<Job> jobs)
{
masterJ...
Hi,
So, I'm a bit out of my comfort zone when dealing with Func<>, Generics and lambda expressions but I think I get the general idea (sort of) but still a bit confused.
I've implemented the SortableObservableCollection class (taken from online somewhere - thanks to whoever it was I got it from!) and it is used like this:
_lookuplistV...
This post contains a lot of code, but I would really appreciate it if you took the some to read and understand it...and hopefully come up with a solution
Let's assume that I am structuring a network-game where the entities need to be drawn and some of them updated from the server accordingly.
The Drawable class is in charge of drawing ...
I am using this code to make a Simple Command:
public class SimpleCommand : ICommand
{
public Predicate<object> CanExecuteDelegate { get; set; }
public Action<object> ExecuteDelegate { get; set; }
#region ICommand Members
public bool CanExecute(object parameter)
{
if (CanExecuteDelegate != null)
...
In Java, how would I use generics to create a max function that takes as parameters two Comparable objects of the same type and returns the larger one?
I tried:
public static <T extends Comparable> T max(T obj1, T obj2)
{
return ( ((obj1).compareTo(obj2) >= 0) ? obj1 : obj2);
}
(It returns obj1 if they are both equal.)
The metho...
Hi,
I want to write a type-safe map method in Java that returns a Collection of the same type as the argument passed (i.e. ArrayList, LinkedList, TreeSet, etc.) but with a different generic type (that between the angled brackets), determined by the generic type of another parameter (the resulting type of the generic mapping function).
...
I have a class similar to the following:
public abstract class Manager<T, TInterface> : IManager<T> where TInterface : IRepository<T>
{
protected abstract TInterface Repository { get; }
public virtual List<T> GetAll()
{
return Repository.GetAll();
}
}
This works perfectly fine, however, is there a way to get a...
Eclipse is saying "HashMap is a raw type" When I use the following code
HashMap = new HashMap();
Any idea what could be wrong?
...
I could very will be imagining things, but I seem to recall in Java that I can declare a field or parameter as such:
public class BarHandler{
public Class<? extends Foo> fooType;
public ProcessedBar Process(string xml){
Foo foo = fooType.GetInstance();
return foo.process(xml)
}
}
This can be useful for fa...
Linq is great, but it always seems to confuse me a bit.
This is my latest confusion:
Say I have two List<String> objects. We will call them sourceList and destList.
I need a way to find the list of strings that are in sourceList and not in destList AND find the list of strings that are in destList and not in SourceList.
This is a bi...
This is the code I'm trying to develop:
Public Structure Statistic(Of t)
Dim maxStat As t
Dim curStat As t
Public Sub New(ByVal pValue As t)
maxStat = pValue
curStat = pValue
End Sub
Public Property Level() As t
Get
Return curStat
...