generic

c# getting current index of generic list

Hi, How can i get index of generic list from form page? For example; aspx.cs List<string> names = new List<string>(); names.Add("a"); names.Add("b"); names.Add("c"); repeaterNames.datasource = names; repeaterNames.DataBind(); aspx <form> <repeater> <itemtemplate> **<%# Eval(?)%>** </itemtemplate> </repeater> </form> ...

Dynamic casting in Java

Before I get chided for not doing my homework, I've been unable to find any clues on the multitude of questions on Java generics and dynamic casting. The type Scalar is defined as follows: public class Scalar <T extends Number> { public final String name; T value; ... public T getValue() { return value; } public v...

Generic table editor

Hello, I have about 40 tables and users should edit data in this tables in browser. I believe than it's possible to create one page with dropdown, user select table name in this dropdown and get a grid with "Edit" button. Does anybody know if such possible? Is it ready projects on Codeplex for such task? Thanks, asp.net developer ...

C# generic string parse to any object

I am storing object values in strings e.g., string[] values = new string[] { "213.4", "10", "hello", "MyValue"}; is there any way to generically initialize the appropriate object types? e.g., something like double foo1 = AwesomeFunction(values[0]); int foo2 = AwesomeFunction(values[1]); string foo3 = AwesomeFunction(values[2]); MyEnu...

Django Order By Generic Foreign Key

Hey, this is a quick one. I have two models, Post and Term and I'd like to be able to tag and categorize (taxonomy) posts as well as other (future) models. My Post model has the following fields: title, content, published (date) and my Term is declared like this: class Term(models.Model): taxonomy = models.CharField(max_length=255) ...

C#: Generic members in non-generic types?

I have a custom control which contains a list of objects. The control is instantiated by the visual designer and then configured in code. The control is a grid which displays a list of entities. I have an initialise method like this. public void Initialise(ISession session, Type type, ICollection<IPersistentObject> objs) IPersisten...

wcf generic datacontract does not get serialized

I am having the following data structure: [DataContract] public class OperationResult<T> { public OperationResult() { } [DataMember] public Int32 OpResult { get;set; } [DataMember] public IList<T> OperationResults { get;set; } public static OperationResult<T> Success(IList<T>...

Implement generic swap macro in C

Possible Duplicate: is there an equivalent of std::swap() in c Hi folks, I was attempting a problem to write a generic swap macro in C and my macro looks like this: #define swap(x,y) { x = x + y; y = x - y; x = x - y; } It works fine for integers and floats but I am unsure if there is any catch in it. What if by generic ma...

Problem with Extension Methods and Generic Constraints

I have a base interface and several inherited interfaces. There are extension methods for the base interface that modify the object and return a new instance of the base class (IChildA.Touch() => IBase, IBase.Touch() => IBase). For one inheritance path (IChildB and descendants) i want to implement extension methods that return an objec...

Java - Class to represent weight and measures

Hey, Is there an existing Java library to represent common weights and measures? I would like something which allows you to create objects which represent weight and distances in different units and let you compare them. It wouldn't be too hard to implement myself, but in this case I don't want to re-invent the wheel, since this wheel i...

Sort generic list based upon a different list.

What would be the fastest way to sort a list that contains a list of objects, based upon another list? An example follows: Say I have multiple lists of employees. Each individual list has a common property value, say "Department". So I have a list of employees, in one list they all have the department string value of "Sales". In ano...

Why does dynamic type work where casting does not?

My guess until now was that a dynamic type just "switches off" type checking during compilation and does something similar to a type cast when a message is invoked on a dynamic instance. Obviously something else is going on. The attached NUnit test case shows my problem: Using a dynamic type I can use a method only available in the conc...

VB.NET Extension on Nullable(Of T) object, gives type error

The code I want to work: <Extension()> Public Function NValue(Of T)(ByVal value As Nullable(Of T), ByVal DefaultValue As T) As T Return If(value.HasValue, value.Value, DefaultValue) End Function So basically what I want it to do, is to give along a default value to a nullable object, and depending on if it's null or not, it will g...