Search Results

Search found 6357 results on 255 pages for 'generic relations'.

Page 75/255 | < Previous Page | 71 72 73 74 75 76 77 78 79 80 81 82  | Next Page >

  • PHP Type Hinting: array supported, object NOT?

    - by Marius Burz
    Am I missing something or there really is no support for generic object type hinting in PHP 5.x? I find it really strange that hinting arrays is supported while hinting objects is not, at least not out of the box. I'd like to have something like this: function foo(object $o) Just as we have: function foo(array $o) Example of possible use: methods of an objects collection class. Workaround: using an interface "Object" implemented by all classes or extending all classes from a generic class "Object" and writing something like this: function foo(Object $o) Well, that just ain't cute. Edit: somebody suggested in a deleted post using stdClass. It doesn't work: Catchable fatal error: Argument 1 passed to c::add() must be an instance of stdClass, instance of b given

    Read the article

  • In .NET which loop runs faster for or foreach

    - by Binoj Antony
    In c#/VB.NET/.NET which loop runs faster for or foreach? Ever since I read that for loop works faster than foreach a long time ago I assumed it stood true for all collections, generic collection all arrays etc. I scoured google and found few articles but most of them are inconclusive (read comments on the articles) and open ended. What would be ideal is to have each scenarios listed and the best solution for the same e.g: (just example of how it should be) for iterating an array of 1000+ strings - for is better than foreach for iterating over IList (non generic) strings - foreach is better than for Few references found on the web for the same: Original grand old article by Emmanuel Schanzer CodeProject FOREACH Vs. FOR Blog - To foreach or not to foreach that is the question asp.net forum - NET 1.1 C# for vs foreach [Edit] Apart from the readability aspect of it I am really interested in facts and figures, there are applications where the last mile of performance optimization squeezed do matter.

    Read the article

  • How to make a file with .pt extension, with xml syntax highlighting and vim's plugin snipmate load p

    - by Somebody still uses you MS-DOS
    I have the following in my .vimrc: au BufNewFile,BufRead *.pt set filetype=xml This is needed because although I'm editing a file with *.pt extension, it's indeed a valid xml file: setting the filetype like this I can have syntax highlighting. I'm using vim's snipmate plugin, and tried to create pt.snippets to specific needs since these files are Zope Page Templates (ZPT with TAL). Now, I have a problem: I don't want to create these snippets in xml.snippets, since they aren't really generic xml snippets, but my *.pt files are set to xml, so when I define my pt snippets they aren't loaded unless I run :set filetype=pt on my pt file on vim - but then I lose syntax highlighting. I would like to be able to have a pt file, with xml syntax highlighting, to be able to load a pt.snippets file from snipmate. How can I do it? (I would like to avoid putting my snippets in a generic snippet file, I would like it to be present only in pt.snippets to be easier to maintain.)

    Read the article

  • How to avoid Eclipse warnings when using legacy code without generics?

    - by Paul Crowley
    I'm using JSON.simple to generate JSON output from Java. But every time I call jsonobj.put("this", "that"), I see a warning in Eclipse: Type safety: The method put(Object, Object) belongs to the raw type HashMap. References to generic type HashMap should be parameterized The clean fix would be if JSONObject were genericized, but since it isn't, I can't add any generic type parameters to fix this. I'd like to switch off as few warnings as possible, so adding "@SuppressWarnings("unchecked")" to lots of methods is unappealing, but do I have any other option besides putting up with the warnings?

    Read the article

  • Django: request object to template context transparancy

    - by anars
    Hi! I want to include an initialized data structure in my request object, making it accessible in the context object from my templates. What I'm doing right now is passing it manually and tiresome within all my views: render_to_response(...., ( {'menu': RequestContext(request)})) The request object contains the key,value pair which is injected using a custom context processor. While this works, I had hoped there was a more generic way of passing selected parts of the request object to the template context. I've tried passing it by generic views, but as it turns out the request object isn't instantiated when parsing the urlpatterns list.

    Read the article

  • GoogleMaps API v3 - Need help with two "click" event scenarios. Need similar functionality to v2 AP

    - by Nathan Raley
    In version 2 of the API the map click event returned an Overlay, LatLng, Overlaylatlng. I used this to create a generic map event that would either retrieve the coordinates of the Map click event, or return the coordinates of a Marker or other type of Overlay. Now that API v3 doesn't return the Overlay or Overlaylatlng during the map click event, how can I go about creating a generic "click" event for the map that works if the user clicks on a marker or overlay? I really don't want to create a click event for each marker I have on my page as I am creating anywhere from a handful to a couple thousand markers. Also, I had to create a custom ImageMapType in order to display the StreetViewOverlay like we could do in v2 of the API because I couldn't find anywhere that told me how to add the StreetViewOverlay without the pegman icon. How can I go about retrieving the LatLng coordinates of a click on this overlay type as well?

    Read the article

  • No-argument method on window.external is invoked when checking with typeof

    - by janko
    Hi, I am trying to display an HTML page with embedded JavaScript code inside a System.Windows.Forms.WebBrowser control. The JavaScript code is expected to interact with the embedding environment through the window.external object. Before invoking a method on window.external, JavaScript is supposed to check for the existance of the method. If it is not there, the code should invoke a generic fallback method. // basic idea if (typeof(window.external.MyMethod) != 'undefined') { window.external.MyMethod(args); } else { window.external.Generic("MyMethod", args); } However, checking for a no-argument method with typeof seems to invoke the method already. That is, if MyMethod accepts any positive number of arguments, the code above will work perfectly; but, if MyMethod is a no-argument method, then the expression typeof(window.external.MyMethod) will not check for its type but invoke it, too. Is there any work-around to this behavior? Can I somehow escape the expression window.external.MyMethod to prevent the method call from occurring?

    Read the article

  • Locked visible cells Excel problem

    - by graham.reeds
    I have a problem with an Excel Template in Excel 2007. I need to remove a row from a summary report but the developer who created this report has somehow managed to set it so that only certain number of rows & columns are visible (in case you are interested it is A1:G30) - no headers, no grid, just blue nothingness. Deleting the offending line just peels back the white-ness. I want to change the resolution of the visible grid to A1:G29. I would ask on google but I haven't the foggiest what the tool would be called to do this (if I did I probably wouldn't be asking). Giving generic terms gives very generic results. I've been through every ribbon and came up blank. Help me out my misery - please!

    Read the article

  • Generics vs Object performance

    - by Risho
    I'm doing practice problems from MCTS Exam 70-536 Microsft .Net Framework Application Dev Foundation, and one of the problems is to create two classes, one generic, one object type that both perform the same thing; in which a loop uses the class and iterated over thousand times. And using the timer, time the performance of both. There was another post at C# generics question that seeks the same questoion but nonone replied. Basically if in my code I run the generic class first it takes loger to process. If I run the object class first than the object class takes longer to process. The whole idea was to prove that generics perform faster. I used the original users code to save me some time. I didn't particularly see anything wrong with the code and was puzzled by the outcome. Can some one explain why the unusual results? Thanks, Risho Here is the code: class Program { class Object_Sample { public Object_Sample() { Console.WriteLine("Object_Sample Class"); } public long getTicks() { return DateTime.Now.Ticks; } public void display(Object a) { Console.WriteLine("{0}", a); } } class Generics_Samle<T> { public Generics_Samle() { Console.WriteLine("Generics_Sample Class"); } public long getTicks() { return DateTime.Now.Ticks; } public void display(T a) { Console.WriteLine("{0}", a); } } static void Main(string[] args) { long ticks_initial, ticks_final, diff_generics, diff_object; Object_Sample OS = new Object_Sample(); Generics_Samle<int> GS = new Generics_Samle<int>(); //Generic Sample ticks_initial = 0; ticks_final = 0; ticks_initial = GS.getTicks(); for (int i = 0; i < 50000; i++) { GS.display(i); } ticks_final = GS.getTicks(); diff_generics = ticks_final - ticks_initial; //Object Sample ticks_initial = 0; ticks_final = 0; ticks_initial = OS.getTicks(); for (int j = 0; j < 50000; j++) { OS.display(j); } ticks_final = OS.getTicks(); diff_object = ticks_final - ticks_initial; Console.WriteLine("\nPerformance of Generics {0}", diff_generics); Console.WriteLine("Performance of Object {0}", diff_object); Console.ReadKey(); } }

    Read the article

  • The type{0} does not support direct content - WPF / XAML

    - by Levo
    Hi there: I defined in my code two classes: a "Person" class with public "Age" and "Name" property, and a "People" class that inherits from Generic.List(of T). The code for People class is as followed: Public Class People Inherits Collections.Generic.List(Of Person) ... End Class What I want to achieve is to directly initialize the People class, and add individual Person to it in XAML, i.e.: <local:People x:Key="Familty"> <local:Person Age="11" Name="John" /> <local:Person Age="12" Name="John2" /> ... </local:People> But I keep getting an error in XAML saying: The type 'People' does not support direct content. Any idea as for how to solve this problem? Thank you very much!

    Read the article

  • Java 7 API design best practice - return Array or return Collection

    - by Shengjie
    I know this question has be asked before generic comes out. Array does win out a bit given Array enforces the return type, it's more type-safe. But now, with latest JDK 7, every time when I design this type of APIs: public String[] getElements(String type) vs public List<String> getElements(String type) I am always struggling to think of some good reasons to return A Collection over An Array or another way around. What's the best practice when it comes to the case of choosing String[] or List as the API's return type? Or it's courses for horses. I don't have a special case in my mind, I am more looking for a generic pros/cons comparison.

    Read the article

  • What is the fastest way to get the persisted object after calling Hibernate's saveOrUpdate?

    - by Dave
    I'm using Hibernate 3.2.1.ga, hibernate annotations 3.2.1.ga, and hibernate-jpa-2.0-api. I can't upgrade at this time as I'm working with legacy code. I have this generic method for saving or updating objects ... protected void saveOrUpdate(Object obj) { final Session session = sessionFactory.getCurrentSession(); session.saveOrUpdate(obj); } You can assume that every argument, "obj," will have a member field that is marked with the "@Id" annotation. I would like to change the return type to return an Object that represents the persisted object in the database (meaning if "obj" didn't contain an id before, what is returned is the database object with a populated id. What is the fastest way to do this given my versioning and generic constraints?

    Read the article

  • Unable to type cast <AnonymousType#1> to <WindowsFormsApplication1.Attributes> [ C#3.0 ]

    - by Newbie
    I have List<Attributes> la = new List<Attributes>(); la = (from t in result let t1 = t.AttributeCollection from t2 in t1 where t2.AttributeCode.Equals(attributeType) let t3 = t2.TimeSeriesData from k in t3.ToList() where k.Key.Equals(startDate) && k.Key.Equals(endDate) select new { AttributeCode = attributeType, TimeSeriesData = fn(k.Key, k.Value.ToString()) }).ToList<Attributes>(); I am getting the error: 'System.Collections.Generic.IEnumerable<AnonymousType#1>' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments I understood tye error meaning but how to type cast it. I have used var and then iterating over it got the result. But without that any other way by which I can do it? Using C# 3.0 Thanks

    Read the article

  • How to implement a C# interface in F#?

    - by Anton Andreev
    I would like to implement the following C# interface in F#: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Mono.Addins; [TypeExtensionPoint] public interface ISparqlCommand { string Name { get; } object Run(Dictionary<string, string> NamespacesDictionary, org.openrdf.repository.Repository repository, params object[] argsRest); } This is what I have tried, but it gives me: "Incomplete structured construct at or before this point in expression" #light module Module1 open System open System.Collections.Generic; type MyClass() = interface ISparqlCommand with member this.Name = "Finding the path between two tops in the Graph" member this.Run(NamespacesDictionary, repository, argsRest) = new System.Object What am I doing wrong? Maybe indentation is wrong?

    Read the article

  • What's wrong with consuming ConfiguredTaskAwaitable from PortableClassLibrary's class under Debugger from MSTest Runner or Console App?

    - by Stas Shusha
    *Its only Debug-time error, but a very weird one. Problem: While running with Debugger attached and calling a method, exposed in separate Portable library, returning ConfiguredTaskAwaitable, we get InvalidProgramException. Repro: Having 2 projects: PortableClassLibrary (supporting .Net 4.5; Windows Store; Windows Phone 8) with 1 class: public class Weird { public static ConfiguredTaskAwaitable GetConfiguredTaskAwaitable() { return new ConfiguredTaskAwaitable(); } } ConsoleApplication with code: static void Main(string[] args) { Weird.GetConfiguredTaskAwaitable(); } Notes: replacing ConfiguredTaskAwaitable with ConfiguredTaskAwaitable<T> (a generic version) fixes this strange issue consuming this method form WP8 or Win8 app under Debugger works fine. Currently it causes problems cause I cant run my Unit Tests under Debugger. I'm forced to change my "ObjectUnderTest" implementation to return generic ConfiguredTaskAwaitable<T>, which is fine for the real project, but still is only a workaround. The Question is: does anybody knows the reason of this error? It definitely related to Portable Class Library magic.

    Read the article

  • How do I map nested generics in NHibernate

    - by Gluip
    In NHibernate you can map generics like this <class name="Units.Parameter`1[System.Int32], Units" table="parameter_int" > </class> But how can I map a class like this? Set<T> where T is a Parameter<int> like this Set<Parameter<int>> My mapping hbm.xml looking like this fails <class name="Set`1[[Units.Parameter`1[System.Int32], Units]],Units" table="settable"/> I simplified my mappings a little to get my point accross very clearly. Basically I want NHibernate to map generic class which has has generic type parameter. Want I understand from googling around is that NHibernate is not able to parse the name to the correct type in TypeNameParser.Parse() which result in the following error when adding the mapping to the configuration System.ArgumentException: Exception of type 'System.ArgumentException' was thrown. Parameter name: typeName@31 Anybody found a way around this limitation?

    Read the article

  • Collections in C#

    - by Oghenero
    am converting a vb.net component to c#, i get this error Using the generic type 'System.Collections.ObjectModel.Collection<T>' requires '1' type arguments This is what i did in VB.NET i had this Private _bufferCol As Collection i did this in c# private Collection _bufferCol = new Collection(); My declaration is using Microsoft.VisualBasi; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Collections.ObjectModel; Can any body help me please.

    Read the article

  • java overloaded method

    - by Sean Nguyen
    Hi, I have an abstract template method: class abstract MyTemplate { public void something(Object obj) { doSomething(obj) } protected void doSomething(Object obj); } class MyImpl extends MyTemplate { protected void doSomething(Object obj) { System.out.println("i am dealing with generic object"); } protected void doSomething(String str) { System.out.println("I am dealing with string"); } } public static void main(String[] args) { MyImpl impl = new MyImpl(); impl.something("abc"); // --> this return "i am dealing with generic object" } How can I print "I am dealing with string" w/o using instanceof in doSomething(Object obj)? Thanks,

    Read the article

  • boost variant static_visitor problem picking correct function

    - by Steve
    I'm sure I'm having a problem with template resolution here, but I'm not sure why I'm having the problem. I have a static visitor I'm passing to boost variant where i've had to do template specialization for certain cases. The case for everything except for MyClass should throw in the static_visitor below. Unfortunately, when the visitor is applied to pull a MyClass out, it selects the most generic case rather than the exact match. I would type each case explicitly, but that will be rather long. So, why is the compiler resolving the most generic case over the exact match, and is there anyway to fix it template<> class CastVisitor<MyClass>:public boost::static_visitor<MyClass> { public: template<typename U> MyClass operator()(const U & i) const { throw std::exception("Unable to cast"); } MyClass operator()(const MyClass& i) { return i; } };

    Read the article

  • In ASP.NET MVC, how does response.redirect work?

    - by Swoop
    I have used response.redirect in classic ASP and ASP.NET webforms. However, with MVC 2.0, I am running into something peculiar. I have a private method in a controller class that is used by multiple controller methods to help load and validate some information. This private method is setup to redirect if a problem is discovered to a generic error message page. The big problem I am noticing is that the calling controller class and page view attempt to complete rendering and loading before the redirect actually takes place. This is annoying in development because the View throws exceptions that I need to ignore before my generic error page finally loads. As mentioned above, I am used to the older model of response.redirect which prevented subsequent code on a page from being executed as the new page would then load. Any help or advice on redirects in MVC would be greatly appreciated.

    Read the article

  • What are the requirements of a collection type when model binding?

    - by Richard Ev
    I have been reviewing model binding with collections, specifically going through this article http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx However, the model I would like to use in my code does not implement collections using generic lists. Instead it uses its own collection classes, which inherit from a custom generic collection base class, the declaration of which is public abstract class CollectionBase<T> : IEnumerable<T> The collections in my POSTed action method are all non-null, but contain no elements. Can anyone advise?

    Read the article

  • Sort objects and polymorphism

    - by ritmbo
    Suppose I have a class A. And B and C are child of A. Class A has a generic algorithm for sorting arrays of type A, so that I could use it for B and C without writing again the algorithm for each. In the algorithm, sometimes I have to swap. The problem is that I can only see the objects as type A, and if I do: A aux = array[i] array[i] = array[j] array[j] = aux I think I have a problem. Because array[i], maybe its of type B, and aux is of type A, so I think I'm losing information. I'm sure u understand this situation... how can I sort a generic array of objects using a father method algorithm?

    Read the article

  • int i vs int index etc. Which one is better?

    - by Earlz
    Coming from a C background I've always used int i for generic loop variables. Of course in big nested loops or other complex things I may use a descriptive name but which one had you rather see? int i; for(i=0;i<Controls.Count;i++){ DoStuff(Controls[i]); } or int index; for(index=0;index<Controls.Count;index++){ DoStuff(Controls[index]); } In the current project I am working on there are both of these styles and index being replaced by ndx. Which one is better? Is the i variable too generic? Also what about the other C style names? i, j, k Should all of these be replaced by actual descriptive variables?

    Read the article

< Previous Page | 71 72 73 74 75 76 77 78 79 80 81 82  | Next Page >