Search Results

Search found 5807 results on 233 pages for 'generic'.

Page 11/233 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Is it possible to define a generic lambda?

    - by Mike OBrien
    I have some logic in a method that operates on a specified type and I'd like to create a generic lambda that encapsulates the logic. This is the spirit of what I'm trying to do: public void DoSomething() { // ... Func<T> GetTypeName = () => T.GetType().Name; GetTypeName<string>(); GetTypeName<DateTime>(); GetTypeName<int>(); // ... } I know I can pass the type as a parameter or create a generic method but I'm interested if it can just be a generic lambda (So I'm not looking for alternatives). From what I can tell C# 3.0 doesn't support this. TIA, m

    Read the article

  • List of generic algorithms and data structures

    - by Jake Petroules
    As part of a library project, I want to include a plethora of generic algorithms and data structures. This includes algorithms for searching and sorting, data structures like linked lists and binary trees, path-finding algorithms like A*... the works. Basically, any generic algorithm or data structure you can think of that you think might be useful in such a library, please post or add it to the list. Thanks! (NOTE: Because there is no single right answer I've of course placed this in community wiki... and also, please don't suggest algorithms which are too specialized to be provided by a generic library) The List: Data structures AVL tree B-tree B*-tree B+-tree Binary tree Binary heap Binary search tree Linked lists Singly linked list Doubly linked list Stack Queue Sorting algorithms Binary tree sort Bubble sort Heapsort Insertion sort Merge sort Quicksort Selection sort Searching algorithms

    Read the article

  • Type patterns and generic classes in Haskell

    - by finnsson
    I'm trying to understand type patterns and generic classes in Haskell but can't seem to get it. Could someone explain it in laymen's terms? In [1] I've read that "To apply functions generically to all data types, we view data types in a uniform manner: except for basic predefined types such as Float, IO, and ?, every Haskell data type can be viewed as a labeled sum of possibly labeled products." and then Unit, :*: and :+: are mentioned. Are all data types in Haskell automatically versions of the above mentioned and if so how do I figure out how a specific data type is represented in terms of :*:, etc? The users guide for generic classes (ch. 7.16) at haskell.org doesn't mention the predefined types but shouldn't they be handled in every function if the type patterns should be exhaustive? [1] Comparing Approaches to Generic Programming in Haskell, Ralf Hinze, Johan Jeuring, and Andres Löh

    Read the article

  • Pass a captured named regular expression to URL dictionary in generic view

    - by Trent Jurewicz
    I am working with a generic view in Django. I want to capture a named group parameter in the URL and pass the value to the URL pattern dictionary. For example, in the URLConf below, I want to capture the parent_slug value in the URL and pass it to the queryset dictionary value like so: urlpatterns = patterns('django.views.generic.list_detail', (r'^(?P<parent_slugs>[-\w])$', 'object_list', {'queryset':Promotion.objects.filter(category=parent_slug)}, 'promo_promotion_list'), ) Is this possible to do in one URLConf entry, or would it be wiser if I create a custom view to capture the value and pass the queryset directly to the generic view from my overridden view?

    Read the article

  • How to invoke a method with a generic return type using reflection

    - by Andre Luus
    Hi there! I'm trying to invoke a method with reflection that has a generic return type, like this: public class SomeClass<T> { public List<T> GetStuff(); } I get an instance of SomeClass with a call to a Repository's GetClass<T> generic method. MethodInfo lGetSomeClassMethodInfo = typeof(IRepository) .GetMethod("GetClass") .MakeGenericMethod(typeof(SomeClass<>); object lSomeClassInstance = lGetSomeClassMethodInfo.Invoke( lRepositoryInstance, null); After that, I this is where I try to invoke the GetStuff method: typeof(SomeClass<>).GetMethod("GetStuff").Invoke(lSomeClassInstance, null) I get an exception about the fact that the method has generic arguments. However, I can't use MakeGenericMethod to resolve the return type. Also, if instead of typeof(SomeClass<>) I use lSomeClassInstance.GetType() (which should have resolved types) GetMethod("GetStuff") returns null! UPDATE I have found the solution and will post the answer shortly.

    Read the article

  • Dynamically find the parameter to be passed as <T> to a generic method

    - by Codex
    A generic method is defined as follows: private static T GetComparisonObject<T>(ComparisonAttribute attribute, object objectToParse) { // Perform a some action return (T)resultObject; } The method is invoked as follows: var srcObjectToCompare = GetComparisonObject<DynamicType>(attributeToCompare, srcObject); The type for which the method needs to be invoked is configured in the config file as: <add attributename ="Count" attributetype ="MemberInformation" attributeparam ="Count" type="System.Int32" comparertype="ditCreditEMGTestAutomationDifferenceEngine.Comparers.TypeComparer, ditCreditEMGTestAutomationDifferenceEngine.dll" /> The token that is passed in < for the generic methods has to be the type for which the method is being invoked. From the type key configuration in the XML, an instance of Type represnting the type can be created{i.e. Type.GetType("System.Int32")}, but how can the Type Definition be generated which can then be passed to the the Generic method? Hope am not missing something elementary here!! :-O Thanks in advance.

    Read the article

  • C# - Dictionary with generic array as value

    - by alhazen
    In my class, I want to use a dictionary with the following declaration: Dictionary<string, T[]> Since the operations of my class are exactly the same for all generic types, I do not wish to define my class as generic (which means I would have to create a separate instance of my class for each generic type I insert into the dictionary ?). One alternative I'm attempting is to use Dictionary<string, object> instead: public void Add<T>(string str, T value) { // Assuming key already exists var array = (T[]) dictionary[str]; array[0] = value; } However, when iterating over the dictionary, how do I cast the object value back to an array ? foreach(string strKey in dictionary.Keys) { var array = (T[]) dictionary[strKey]; // How to cast here ? //... array[0] = default(T); } Thanks.

    Read the article

  • Generic XML parser in Silverlight 3.0

    - by Ummar
    Hi I am developing an application in Silverlight 3.0, I want to make a generic parser of XML in it, as on every call to webservice I am receiving a different XML, I want to make it generic so that I receive an XML in native datastructure of C#? Please help me out? like I am getting XML like this one time <test> <node1></node1> <node2></node2> </test> and other time <mytest> <application name="XYZ">My Application</application> <application name="ABC">My Application</application> </mytest> I want the generic parser, e.g. it makes some tree structure of whole XML

    Read the article

  • Generic Post Script driver for Windows Vista x64?

    - by Rick
    I have an old HP parallel port printer that is not supported by Vista. No drivers I've found online work with it. As a last ditch effort, I was hoping to find some generic postscript drivers for Vista x64 in the hopes that the printer will accept those commands. Does anyone know where I could come by such drivers?

    Read the article

  • After installing Windows XP Service Pack 3 - Generic Host Process For Win32 Services problem starts

    - by Muhammad Kashif Nadeem
    After installing Service Pack 3 I am getting this error "Generic Host Process For Win32 Services Encountered A Problem and needs to close. When this message pops my computer just stuck and I can not even restart it normally. The only fix of this problem is to un-install service pack 3 and run fix from Microsoft which is available for Service Pack 2. Any help to fix this. Thanks.

    Read the article

  • After installing Windows XP Service Pack 3 - Generic Host Process For Win32 Services problem starts

    - by Muhammad Kashif Nadeem
    After installing Service Pack 3 I am getting this error "Generic Host Process For Win32 Services Encountered A Problem and needs to close. When this message pops my computer just stuck and I can not even restart it normally. The only fix of this problem is to un-install service pack 3 and run fix from Microsoft which is available for Service Pack 2. Any help to fix this. Thanks.

    Read the article

  • Generic sql query email alert program

    - by mellerbeck
    Has anyone ever ran across a program that in a generic manner will execute a sql query and then based on criteria email out alerts. Going to create such a framework but don't want to re create the wheel if I don't have to. It could be used to check various things like if things are setup correctly inside our ERP etc... Thanks for any thoughts. Michael

    Read the article

  • LINQ Generic Query with inherited base class?

    - by sah302
    I am trying to write some generic LINQ queries for my entities, but am having issue doing the more complex things. Right now I am using an EntityDao class that has all my generics and each of my object class Daos (such as Accomplishments Dao) inherit it, am example: using LCFVB.ObjectsNS; using LCFVB.EntityNS; namespace AccomplishmentNS { public class AccomplishmentDao : EntityDao<Accomplishment>{} } Now my entityDao has the following code: using LCFVB.ObjectsNS; using LCFVB.LinqDataContextNS; namespace EntityNS { public abstract class EntityDao<ImplementationType> where ImplementationType : Entity { public ImplementationType getOneByValueOfProperty(string getProperty, object getValue) { ImplementationType entity = null; if (getProperty != null && getValue != null) { //Nhibernate Example: //ImplementationType entity = default(ImplementationType); //entity = Me.session.CreateCriteria(Of ImplementationType)().Add(Expression.Eq(getProperty, getValue)).UniqueResult(Of InterfaceType)() LCFDataContext lcfdatacontext = new LCFDataContext(); //Generic LINQ Query Here lcfdatacontext.GetTable<ImplementationType>(); lcfdatacontext.SubmitChanges(); lcfdatacontext.Dispose(); } return entity; } public bool insertRow(ImplementationType entity) { if (entity != null) { //Nhibernate Example: //Me.session.Save(entity, entity.Id) //Me.session.Flush() LCFDataContext lcfdatacontext = new LCFDataContext(); //Generic LINQ Query Here lcfdatacontext.GetTable<ImplementationType>().InsertOnSubmit(entity); lcfdatacontext.SubmitChanges(); lcfdatacontext.Dispose(); return true; } else { return false; } } } }             I have gotten the insertRow function working, however I am not even sure how to go about doing getOnebyValueOfProperty, the closest thing I could find on this site was: http://stackoverflow.com/questions/2157560/generic-linq-to-sql-query How can I pass in the column name and the value I am checking against generically using my current set-up? It seems like from that link it's impossible since using a where predicate because entity class doesn't know what any of the properties are until I pass them in. Lastly, I need some way of setting a new object as the return type set to the implementation type, in nhibernate (what I am trying to convert from) it was simply this line that did it: ImplentationType entity = default(ImplentationType); However default is an nhibernate command, how would I do this for LINQ? EDIT: getOne doesn't seem to work even when just going off the base class (this is a partial class of the auto generated LINQ classes). I even removed the generics. I tried: namespace ObjectsNS { public partial class Accomplishment { public Accomplishment getOneByWhereClause(Expression<Action<Accomplishment, bool>> singleOrDefaultClause) { Accomplishment entity = new Accomplishment(); if (singleOrDefaultClause != null) { LCFDataContext lcfdatacontext = new LCFDataContext(); //Generic LINQ Query Here entity = lcfdatacontext.Accomplishments.SingleOrDefault(singleOrDefaultClause); lcfdatacontext.Dispose(); } return entity; } } } Get the following error: Error 1 Overload resolution failed because no accessible 'SingleOrDefault' can be called with these arguments: Extension method 'Public Function SingleOrDefault(predicate As System.Linq.Expressions.Expression(Of System.Func(Of Accomplishment, Boolean))) As Accomplishment' defined in 'System.Linq.Queryable': Value of type 'System.Action(Of System.Func(Of LCFVB.ObjectsNS.Accomplishment, Boolean))' cannot be converted to 'System.Linq.Expressions.Expression(Of System.Func(Of LCFVB.ObjectsNS.Accomplishment, Boolean))'. Extension method 'Public Function SingleOrDefault(predicate As System.Func(Of Accomplishment, Boolean)) As Accomplishment' defined in 'System.Linq.Enumerable': Value of type 'System.Action(Of System.Func(Of LCFVB.ObjectsNS.Accomplishment, Boolean))' cannot be converted to 'System.Func(Of LCFVB.ObjectsNS.Accomplishment, Boolean)'. 14 LCF Okay no problem I changed: public Accomplishment getOneByWhereClause(Expression<Action<Accomplishment, bool>> singleOrDefaultClause) to: public Accomplishment getOneByWhereClause(Expression<Func<Accomplishment, bool>> singleOrDefaultClause) Error goes away. Alright, but now when I try to call the method via: Accomplishment accomplishment = new Accomplishment(); var result = accomplishment.getOneByWhereClause(x=>x.Id = 4) It doesn't work it says x is not declared. I also tried getOne, and various other Expression =(

    Read the article

  • How can I download the source code for linux-image-3.2.0-24-generic?

    - by keepitsimpleengineer
    The directions at Ubuntu Wiki apt-get source linux-image-$(uname -r) and askubuntu question Where can I find the source code for the Ubuntu Kernel? don't work… sudouser@64bitws:~# uname -r 3.2.0-24-generic and sudouser@64bitws:~# apt-get source linux-image-3.2.0-24-generic Reading package lists... Done Building dependency tree Reading state information... Done Picking 'linux' as source package instead of 'linux-image-3.2.0-24-generic' E: Unable to find a source package for linux

    Read the article

  • How can I download the source code for linux-image-3.2.0-*-generic?

    - by keepitsimpleengineer
    The directions at Ubuntu Wiki apt-get source linux-image-$(uname -r) and askubuntu question Where can I find the source code for the Ubuntu Kernel? don't work… sudouser@64bitws:~# uname -r 3.2.0-24-generic and sudouser@64bitws:~# apt-get source linux-image-3.2.0-24-generic Reading package lists... Done Building dependency tree Reading state information... Done Picking 'linux' as source package instead of 'linux-image-3.2.0-24-generic' E: Unable to find a source package for linux

    Read the article

  • WPF add c# code to customcontrol

    - by 0xDEAD BEEF
    I want to create simple custom control (derived from control and with look defined in generics.xaml). I need to change size of elements defined in generic.xaml, when control is resized! It would be great to write some of that generic.xaml part in C#. Is that possible? Or is there a way to create MVVM like custom control? What i am willing to create is simple blinking led control (on,blinking, off).

    Read the article

  • No generic implementation of OrderedDictionary?

    - by AdaTheDev
    I'm using .NET 3.5. I think I know the answer to this, but am looking for confirmation so should be a quick one! There doesn't appear to be a generic implementation of OrderedDictionary (which is in System.Collections.Specialized namespace). Is there one that I'm missing? I've found implementations out there to provide the functionality, but wondered if/why there isn't a generic implementation out-of-the-box and if anyone knows whether it's something in .NET 4.0?

    Read the article

  • Ruby generic filesystem libraries

    - by webdestroya
    I am looking for a "Virtual File System" type library for ruby. I want to be able to have a completely generic file system that I can easily switch between using Local files and using S3 or using FTP or something like that. (Identical to VFS for Java) Has anybody used any type of generic file system for ruby (I just need it to support local files and Amazon S3) Any pointers would be much appreciated.

    Read the article

  • Generic relations missing with grappelli

    - by diegueus9
    I'm using the last svn revision of grappelli and rev 11840 of django (before multidatabases and stuff), and i'm trying to use generic relations in the admin, but doesn't work, The model: class AutorProyectoLey(DatedModel): tipo_autor = models.ForeignKey(ContentType) autor_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('tipo_autor', 'autor_id') proyecto_ley = models.ForeignKey(ProyectoLey) The admin: class AutorInline(GenericInlineModelAdmin): model = AutorProyectoLey allow_add = True ct_field = 'tipo_autor' ct_fk_field = 'autor_id' classes = ('collapse-open',) And i put this model of var inlines in another adminmodel, but the html render is : <!-- Inlines --> <!-- Submit-Row -->

    Read the article

  • Calling a generic function in VB.NET / C#

    - by Quandary
    Question: I want to call a generic function, defined as: Public Shared Function DeserializeFromXML(Of T)(Optional ByRef strFileNameAndPath As String = Nothing) As T Now when I call it, I wanted to do it with any of the variants below: Dim x As New XMLserialization.cConfiguration x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of x)() x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(GetType(x))() x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of GetType(x))() But it doesn't work. I find it very annoying and unreadable having to type x = XMLserialization.XMLserializeLDAPconfig.DeserializeFromXML(Of XMLserialization.cConfiguration)() Is there a way to call a generic function by getting the type from the instance ?

    Read the article

  • C# Generic Static Constructor

    - by Seattle Leonard
    Will a static constructor on a generic class be run for every type you pass into the generic parameter such as this: class SomeGenericClass<T> { static List<T> _someList; static SomeGenericClass() { _someList = new List<T>(); } } Are there any draw backs to using this approach?

    Read the article

  • Calling a static method on a generic type parameter

    - by Remi Despres-Smyth
    I was hoping to do something like this, but it appears to be illegal in C#: public Collection MethodThatFetchesSomething<T>() where T : SomeBaseClass { return T.StaticMethodOnSomeBaseClassThatReturnsCollection(); } I get a compile-time error: "'T' is a 'type parameter', which is not valid in the given context." Given a generic type parameter, how can I call a static method on the generic class? The static method has to be available, given the constraint.

    Read the article

  • Adding a generic image field onto a ModelForm in django

    - by Prairiedogg
    I have two models, Room and Image. Image is a generic model that can tack onto any other model. I want to give users a form to upload an image when they post information about a room. I've written code that works, but I'm afraid I've done it the hard way, and specifically in a way that violates DRY. Was hoping someone who's a little more familiar with django forms could point out where I've gone wrong. Update: I've tried to clarify why I chose this design in comments to the current answers. To summarize: I didn't simply put an ImageField on the Room model because I wanted more than one image associated with the Room model. I chose a generic Image model because I wanted to add images to several different models. The alternatives I considered were were multiple foreign keys on a single Image class, which seemed messy, or multiple Image classes, which I thought would clutter my schema. I didn't make this clear in my first post, so sorry about that. Seeing as none of the answers so far has addressed how to make this a little more DRY I did come up with my own solution which was to add the upload path as a class attribute on the image model and reference that every time it's needed. # Models class Image(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') image = models.ImageField(_('Image'), height_field='', width_field='', upload_to='uploads/images', max_length=200) class Room(models.Model): name = models.CharField(max_length=50) image_set = generic.GenericRelation('Image') # The form class AddRoomForm(forms.ModelForm): image_1 = forms.ImageField() class Meta: model = Room # The view def handle_uploaded_file(f): # DRY violation, I've already specified the upload path in the image model upload_suffix = join('uploads/images', f.name) upload_path = join(settings.MEDIA_ROOT, upload_suffix) destination = open(upload_path, 'wb+') for chunk in f.chunks(): destination.write(chunk) destination.close() return upload_suffix def add_room(request, apartment_id, form_class=AddRoomForm, template='apartments/add_room.html'): apartment = Apartment.objects.get(id=apartment_id) if request.method == 'POST': form = form_class(request.POST, request.FILES) if form.is_valid(): room = form.save() image_1 = form.cleaned_data['image_1'] # Instead of writing a special function to handle the image, # shouldn't I just be able to pass it straight into Image.objects.create # ...but it doesn't seem to work for some reason, wrong syntax perhaps? upload_path = handle_uploaded_file(image_1) image = Image.objects.create(content_object=room, image=upload_path) return HttpResponseRedirect(room.get_absolute_url()) else: form = form_class() context = {'form': form, } return direct_to_template(request, template, extra_context=context)

    Read the article

  • Auto convert java source to use generic rather than raw types

    - by Sam
    Is there a way/tool to auto convert Java source code from using raw types to using generic types? I have some legacy code with 677 references to raw types: ArrayList 47 Vector 420 Hashtable 61 Enumeration 64 Class 7 Iterator 78 TOTAL 677 Now I could manually look through the code to infer the generic types and replace, but that is going to take a long time.

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >