generic

Generic view 'archive_year' produces blank page

I am using Django's generic views to create a blog site. The templates I created, entry_archive_day, entry_archive_month, entry_archive, and entry_detail all work perfectly. But entry_archive_year does not. Instead, it is simply a valid page with no content (not a 404 or other error. It looks like it sees no objects in **object_lis...

Is there a way to add something like the params option for generic types?

I have a function that looks similar to the following. I'd like to modify it so I can pass in multiple types to filter on instead of just one. I don't suppose there's a params/paramarray option for type parameters, is there? Public Shared Function Filter(Of T)() Dim results As New List(Of T) For Each item In GlobalCollection.Al...

C# : obtain generic enumerator from an array

In C#, how does one obtain a generic enumerator from a given array? In the code below, MyArray is an array of MyType objects. I'd like to obtain MyIEnumerator in the fashion shown, but it seems that I obtain an empty enumerator (although I've confirmed that MyArray.Length > 0). MyType [ ] MyArray = ... ; IEnumerator<MyType> MyIEnu...

Store a generic dictionary in an asp.net profile?

Hi, Is there any way of storing a generic dictionary object in an asp.net profile? I have tried using this but it still doesn't like it: http://weblogs.asp.net/pwelter34/default.aspx Thanks, Nick ...

How do I implement a matching algorithm using predicates?

I understand how to use delegates and I am okay with lambda expressions to make use of predicates. I've come to a point where I want to implement a method that uses a predicate as an argument and can't figure out how to reference the predicate to find the matches in my collection: private static T FindInCollection<T>(ICollection<T> col...

WPF Generic Windows

Hi! I want to make a reusable WPF Window suitable for different types T. I have a designer and a codebehind file. can I do something like this? /* Code behind file */ public partial class MyWindows<T> : Window {} ...

How can I shorten List<List<KeyValuePair<string, string>>>?

I want to store an list of key value pair lists in a lightweight structure. This seems too cumbersome. What's better? Does List<Dictionary<string, string>> add much a overhead? What other options are available? ...

Implement an Interface with Generic Methods

I'm drawing a blank on this one and can't seem to find any previous example that I wrote. I'm trying to implement a generic interface with a class. When I implement the interface I think something isn't working right because Visual Studio continually produces errors saying that I'm not implmenting all of the methods in the Generic Interf...

C# - Multiple generic types in one list II

Hi all, Could you please clarify for me the question asked here. Why it is important that originally defined class: public class Metadata<DataType> where DataType : struct { private DataType mDataType; } is replaced with one derived from the same interface or abstract class is it maybe because IList<> members must share some ...

CRUD pattern for urls.py, passing object from URI to view

Can the object value be looked up and passed to the generic view? Would the generic views need to be moved to views.py in order to support the object lookup? urls.py urlpatterns = patterns('myapp.views', url(r'^mymodel/create/$', view='mymodel_create', name='mymodel_create'), ) urlpatterns += patterns('django.views.generic', ...

Generic tree implementation in Java

Is anyone aware of a generic tree (nodes may have multiple children) implementation for Java? It should come from a well trusted source and must be fully tested. It just doesn't seem right implementing it myself. Almost reminds me of my university years when we were supposed to write all our collections ourselves. EDIT: Found this pro...

Django: how to retrieve an object selected by the ``object_detail`` generic view ?

Hi (sorry for my ugly english) I wonder if this is possible to retrieve an object which was selected with the object_detail generic view. For example : from django.views.generic.list_detail import object_detail def my_view(request, slug) response = object_detail(request, MyModel.objects.all(), slug=slug, slug_fie...

How do I set arbitrary number of properties on generic object?

I want to be able to call a method that creates an object and sets properties of the object based on the parameters passed into the method. The number of parameters is arbitrary, but the catch is I don't want to use strings. I want to use the actual properties sort of like you do in lambda expressions. I want to be able to call the me...

How to mock a generic repository using NUnit.Mocks ?

I'm working on a generic repository and I would like to test it using a NUnit.Mocks . According to Mike Hadlow in his article you can do it using Rhino mocks like this: User[] users = new User[] { }; ... Expect.Call(userRepository.GetAll()).Return(users); So I thought maybe I could write the same thing in NUnit.Mocks like this : data...

With C# 3.0, how to write Interface based code with generic collection?

I want to write code that is decouple and clean, and I know that by programming to an interface instead of the implementation, my code will be more flexible and extensible. So, instead of writing methods like: bool IsProductAvailable(ProductTypeA product); I write methods like: bool IsProductAvailable(IProduct product); As lon...

Eclipse complains about name clash if an interface with a method having a generic argument is implemented.

There are already some discussions here on stackoverflow about Java generics, but I am too stupid to solve this specific question. I have defined an interface in a project, and its implementation in another one. They are in different packages. Instead of implementing the method, the compiler complains in some workspaces: Name clash: The...

deserializing generic dictionary using json.net

I have a class looking like this: class MyClass { public int Id; public Dictionary<int, MyClass[]> ChildValues; } when I try to deserialize this class using Json.NET: MyClass x = return JsonConvert.DeserializeObject<MyClass>(s); I receive the error Expected a JsonObjectContract or JsonDictionaryContract for type 'System.Co...

Generic Database setup script

We are using SQL and have a script file to generate the Database and tables. I am trying to write a generic script which will execute on all dev/prod machines The file name which i am giving is FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL.3\MSSQL\DATA\DBname.mdf' It works on my machine but not on all the dev machine since al...

What is the best-maintained generic functions implementation for Python?

A generic function is dispatched based on the type of all its arguments. The programmer defines several implementations of a function. The correct one is chosen at call time based on the types of its arguments. This is useful for object adaptation among other things. Python has a few generic functions including len(). These packages ten...

F#: Implementing the same interface at different generic instantiations

In C#, I can implement a generic interface twice on one class, using two different type-parameters: interface IFoo<T> { void Foo(T x); } class Bar : IFoo<int>, IFoo<float> { public void Foo(int x) { } public void Foo(float y) { } } I would like to do the same thing in F#: type IFoo<'a> = abstract member Foo : 'a -> unit typ...