generic

How to dynamically cast an object of type string to an object of type T

I have this XML document <AdditionalParameters> <PublishToPdf Type ="System.Boolean">False</PublishToPdf> </AdditionalParameters> in my code and I'm trying to build an array of arguments containing the <PublishToPdf> node. object test = (object) ((typeof(publishNode.Attributes["Type"].value)) publishNode.InnerText); This breaks at ...

Django: disallow can_delete on GenericStackedInline

Hello, I've built this model which contains a generic foreign key: class MyModel(models.Model): content_type = models.ForeignKey(ContentType, verbose_name=_('content type')) object_id = models.PositiveIntegerField(_('object id')) content_object = generic.GenericForeignKey('content_type', 'object_id') Next I've made a gene...

Int cast error in generic extension

I modified the extension method Thorarin gave in response to this question to work on an int instead of a string: public static TEnum ToEnum<TEnum>(this int intEnumValue, TEnum defaultValue) { if (!Enum.IsDefined(typeof(TEnum), intEnumValue)) return defaultValue; return (TEnum)intEnumValue; } The compiler gives the err...

Converting non-generic List type to Generic List type in Java 1.5

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...

question deleted

question deleted ...

Calling a generic method from IronRuby

Hi How can I call a generic method (.NET 3.5 SP1) from IronRuby v0.9? Trying to do something as obj.method(:method_name).of(String).call seems not to work as "of" is an unknown method. Thanks a lot ...

how to point to back of generic list c#

Is there a way to point to the last item added to a generic list in c# ? Like the back() for a vector in c++ ...

Can I filter on request.user when using Django generic views?

I want to do something like this (from my urls.py), but I don't know if it's possible to get the user making the request: url(r'^jobs/(page(?P<page>[0-9]+)/)?$', object_list, {'queryset': Job.objects.filter(user=request.user), 'template_name': 'shootmpi/molecule_list.html'}, name='user_jobs'), ...

Crafting a Comparator object for sorting generic List<? extends T> using Collections.sort()

I am trying to implement a generic sort utility method for a List of objects of any class that implements MyInterface. Per Java API (http://java.sun.com/javase/6/docs/api/java/util/Collections.html), Collections.sort() method signature is: public static <T> void sort(List<T> list, Comparator<? super T> c) I am not sure if List with a ...

How to set bindings for generic properties of custom activity in workflow foundation

I have a custom class called "Parameter" and a custom activity with generic collection property called "Parameters", and I want to set bindings for one of Parameters in the generic list of Parameters Property,I've tried with activitybind, but it is not working, is there any way to do it with workflow foundation? please see codes below: ...

Interfaced function returning type of implementing class

Hi all, I am looking to implement an interface which has a function which will return the type of the base class without using a generic interface. Is this possible? class MyClass : MyInterface<MyClass> // Would rather use one below class MyClass : MyInterface // Functions already know to use MyClass ...

Doubt with List<Generic> Explicit Cast

I don't understand why in some cases I can make an explicit cast and in other cases I can not. Thanks to all! //DAreaLabel extends Message //This Code Works List<Message> list1 = (List<Message>) Arrays.asList((Message[]) getPageRecords(getClasspath(), methodName, object)); DAreaLabel areaLabel = (DAreaLabel) ((List<M...

C++: iterating over a list of a generic type

Yet again I find myself struggling with the C++ syntax. I'm trying to iterate over a list of generic objects. That is I have objects of a class Event<Q>, crammed into a std::list<Event<Q> >. So I'm trying to get an iterator over the list and intuitively thought that std::list<Event<Q> >::iterator it; for (it = events.begin(); it != ev...

Multithreaded Syncronised List<T>

I have a requirement whereby I needed to store a simple cache of a list of items. I was using List< T > for this purpose, but we have now changed the design to accomodate multiple threads. The architecture of the system is driven by events, therefore it's quite likely that a read and write operation could collide. Since the vast majorit...

Generic Http Module

The problem I am trying to make a generic http module in asp.net C# for handling roles defined by an enum which i want to be able to change by a generic parameter. This will make it possible to use the generic module with any kind of enum defined for each project. The module hooks into the Authenticate event of the FormsAuthenticationM...

.NET: Scalability of generic Dictionary

I'm using a Dictionary<> to store a bazillion items. Is it safe to assume that as long as the server's memory has enough space to accommodate these bazillion items that I'll get near O(1) retrieval of items from it? What should I know about using a generic Dictionary as huge cache when performance is important? EDIT: I shouldn't rely on...

.NET Reflection: Detecting IEnumerable<T>

I'm trying to detect if a particular instance of a Type object is a generic "IEnumerable"... The best I can come up with is: // theType might be typeof(IEnumerable<string>) for example... or it might not bool isGenericEnumerable = theType.GetGenericTypeDefinition() == typeof(IEnumerable<object>).GetGenericTypeDefinition() if(isGenericE...

.NET reflection: determining whether an array of T would be convertible to some other type

Note, this question is a bit subtle so read it carefully: I'm not just trying to find out whether some artibitrary type implements IEnumerable: Here's a function I've written with an initial implementation: // is "toType" some sort of sequence that would be satisfied // by an array of type T? If so, what is the type of T? /...

C# compiler + generic code with boxing + constraints

Let's examine the MSIL code generated for the following generic method: public static U BoxValue<T, U>(T value) where T : struct, U where U : class { return value; } Look: .method public hidebysig static !!U BoxValue<valuetype .ctor ([mscorlib]System.ValueType, !!U) T,class U>(!!T 'value') cil managed { .maxstack 8 IL_00...

How to use rewriterule to redirect to a php file in the same folder?

I would like to take requests for /somefolder/style.css and handle them with /somefolder/program.php So, I put the following in my .htaccess file: rewriteengine on rewriterule ^style.css$ program.php?css=1 [R=302,L] The result is that instead of redirecting to /somefolder/program.php, the server tries to redirect to: /var/www/html...