Search Results

Search found 12934 results on 518 pages for 'magic methods'.

Page 9/518 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • System.Reflection - Global methods aren't available for reflection

    - by mrjoltcola
    I have an issue with a semantic gap between the CLR and System.Reflection. System.Reflection does not (AFAIK) support reflecting on global methods in an assembly. At the assembly level, I must start with the root types. My compiler can produce assemblies with global methods, and my standard bootstrap lib is a dll that includes some global methods. My compiler uses System.Reflection to import assembly metadata at compile time. It seems if I depend on System.Reflection, global methods are not a possibility. The cleanest solution is to convert all of my standard methods to class static methods, but the point is, my language allows global methods, and the CLR supports it, but System.Reflection leaves a gap. ildasm shows the global methods just fine, but I assume it does not use System.Reflection itself and goes right to the metadata and bytecode. Besides System.Reflection, is anyone aware of any other 3rd party reflection or disassembly libs that I could make use of (assuming I will eventually release my compiler as free, BSD licensed open source).

    Read the article

  • Successful SQL Injection despite PHP Magic Quotes

    - by Crimson
    I have always read that Magic Quotes do not stop SQL Injections at all but I am not able to understand why not! As an example, let's say we have the following query: SELECT * FROM tablename WHERE email='$x'; Now, if the user input makes $x=' OR 1=1 --, the query would be: SELECT * FROM tablename WHERE email='\' OR 1=1 --'; The backslash will be added by Magic Quotes with no damage done whatsoever! Is there a way that I am not seeing where the user can bypass the Magic Quote insertions here?

    Read the article

  • When should a method of a class return the same instance after modifying itself?

    - by modiX
    I have a class that has three methods A(), B() and C(). Those methods modify the own instance. While the methods have to return an instance when the instance is a separate copy (just as Clone()), I got a free choice to return void or the same instance (return this;) when modifying the same instance in the method and not returning any other value. When deciding for returning the same modified instance, I can do neat method chains like obj.A().B().C();. Would this be the only reason for doing so? Is it even okay to modify the own instance and return it, too? Or should it only return a copy and leave the original object as before? Because when returning the same modified instance the user would maybe admit the returned value is a copy, otherwise it would not be returned? If it's okay, what's the best way to clarify such things on the method?

    Read the article

  • Why is it impossible to declare extension methods in a generic static class?

    - by Hun1Ahpu
    I'd like to create a lot of extension methods for some generic class, e.g. for public class SimpleLinkedList<T> where T:IComparable And I've started creating methods like this: public static class LinkedListExtensions { public static T[] ToArray<T>(this SimpleLinkedList<T> simpleLinkedList) where T:IComparable { //// code } } But when I tried to make LinkedListExtensions class generic like this: public static class LinkedListExtensions<T> where T:IComparable { public static T[] ToArray(this SimpleLinkedList<T> simpleLinkedList) { ////code } } I get "Extension methods can only be declared in non-generic, non-nested static class". And I'm trying to guess where this restriction came from and have no ideas.

    Read the article

  • How do I make PHP's Magic __set work like a natural variable?

    - by Navarr
    Basically, what I want to do is create a class called Variables that uses sessions to store everything in it, allowing me to quickly get and store data that needs to be used throughout the entire site without working directly with sessions. Right now, my code looks like this: <?php class Variables { public function __construct() { if(session_id() === "") { session_start(); } } public function __set($name,$value) { $_SESSION["Variables"][$name] = $value; } public function __get($name) { return $_SESSION["Variables"][$name]; } public function __isset($name) { return isset($_SESSION["Variables"][$name]); } } However, when I try to use it like a natural variable, for example... $tpl = new Variables; $tpl->test[2] = Moo; echo($tpl->test[2]); I end up getting "o" instead of "Moo" as it sets test to be "Moo," completely ignoring the array. I know I can work around it by doing $tpl->test = array("Test","Test","Moo"); echo($tpl->test[2]); but I would like to be able to use it as if it was a natural variable. Is this possible?

    Read the article

  • Simple way to reorder methods of a Java class in IntelliJ?

    - by Péter Török
    Is there a simpler way of reordering methods within a class source file in IntelliJ than cutting and pasting the code manually? Nowadays I often need this while refactoring legacy code, e.g. to move related methods close to each other in the source code. In Eclipse AFAIK there is a view similar to the Structure view of IntelliJ, where I can drag and drop methods around. However, this does not work in IntelliJ and I couldn't find any hints from its help either. I am using IntelliJ 9.0.2 to be specific.

    Read the article

  • Background & Research Methods section (Writing an Article)

    - by sterz
    It is my first time writing an article on a software project. I am supposed to use ACM UbiComp paper format. I already have a structure that I should follow and there is a Background & Research Methods section after Abstract, Introduction, Related Work sections. I have browser through several articles, but some of them either dont have it, have only background section or have only research methods section. I am having hard time to find an article that has this section and moreover what I must write on here. My project is about Bluetooth location tracking and I do have the implementation and evaluation, so it is not something theoretical.

    Read the article

  • Use Extension Methods to find first and last day of the month

    - by Tim Hibbard
    A lot of reports work on data from last month.  It is a nice touch to have these dates pre-populated for your users.  Using extension methods, the code can look cleaner too. Extension Methods: public static class DateHelper { public static DateTime FirstOfTheMonth(this DateTime dt) { return new DateTime(dt.Year, dt.Month, 1); }   public static DateTime LastOfTheMonth(this DateTime dt) { return dt.FirstOfTheMonth().AddMonths(1).AddDays(-1); } } Consuming Code: void Prepopulate() { startDateBox.CurrentlySelectedDate = DateTime.Now.AddMonths(-1).FirstOfTheMonth(); endDateBox.CurrentlySelectedDate = DateTime.Now.AddMonths(-1).LastOfTheMonth(); }

    Read the article

  • Advantages to Multiple Methods over Switch

    - by tandu
    I received a code review from a senior developer today asking "By the way, what is your objection to dispatching functions by way of a switch statement?" I have read in many places about how pumping an argument through switch to call methods is bad OOP, not as extensible, etc. However, I can't really come up with a definitive answer for him. I would like to settle this for myself once and for all. Here are our competing code suggestions (php used as an example, but can apply more universally): class Switch { public function go($arg) { switch ($arg) { case "one": echo "one\n"; break; case "two": echo "two\n"; break; case "three": echo "three\n"; break; default: throw new Exception("Unknown call: $arg"); break; } } } class Oop { public function go_one() { echo "one\n"; } public function go_two() { echo "two\n"; } public function go_three() { echo "three\n"; } public function __call($_, $__) { throw new Exception("Unknown call $_ with arguments: " . print_r($__, true)); } } Part of his argument was "It (switch method) has a much cleaner way of handling default cases than what you have in the generic __call() magic method." I disagree about the cleanliness and in fact prefer call, but I would like to hear what others have to say. Arguments I can come up with in support of Oop scheme: A bit cleaner in terms of the code you have to write (less, easier to read, less keywords to consider) Not all actions delegated to a single method. Not much difference in execution here, but at least the text is more compartmentalized. In the same vein, another method can be added anywhere in the class instead of a specific spot. Methods are namespaced, which is nice. Does not apply here, but consider a case where Switch::go() operated on a member rather than a parameter. You would have to change the member first, then call the method. For Oop you can call the methods independently at any time. Arguments I can come up with in support of Switch scheme: For the sake of argument, cleaner method of dealing with a default (unknown) request Seems less magical, which might make unfamiliar developers feel more comfortable Anyone have anything to add for either side? I'd like to have a good answer for him.

    Read the article

  • How to design 2D collision callback methods?

    - by Ahmed Fakhry
    In a 2D game where you have a lot of possible combination of collision between objects, such as: object A vs object B = object B vs A; object A vs object C = object C vs A; object A vs object D = object D vs A; and so on ... Do we need to create callback methods for all single type of collision? and do we need to create the same method twice? Like, say a bullet hits a wall, now I need a method to penetrate the wall for the wall, and a method to destroy the bullet for the bullet!! At the same time, a bullet can hit many objects in the game, and hence, more different callback methods!!! Is there a design pattern for that?

    Read the article

  • Using extension methods to decrease the surface area of a C# interface

    - by brian_ritchie
    An interface defines a contract to be implemented by one or more classes.  One of the keys to a well-designed interface is defining a very specific range of functionality. The profile of the interface should be limited to a single purpose & should have the minimum methods required to implement this functionality.  Keeping the interface tight will keep those implementing the interface from getting lazy & not implementing it properly.  I've seen too many overly broad interfaces that aren't fully implemented by developers.  Instead, they just throw a NotImplementedException for the method they didn't implement. One way to help with this issue, is by using extension methods to move overloaded method definitions outside of the interface. Consider the following example: .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: Consolas, "Courier New", Courier, Monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } 1: public interface IFileTransfer 2: { 3: void SendFile(Stream stream, Uri destination); 4: } 5:   6: public static class IFileTransferExtension 7: { 8: public static void SendFile(this IFileTransfer transfer, 9: string Filename, Uri destination) 10: { 11: using (var fs = File.OpenRead(Filename)) 12: { 13: transfer.SendFile(fs, destination); 14: } 15: } 16: } 17:   18: public static class TestIFileTransfer 19: { 20: static void Main() 21: { 22: IFileTransfer transfer = new FTPFileTransfer("user", "pass"); 23: transfer.SendFile(filename, new Uri("ftp://ftp.test.com")); 24: } 25: } In this example, you may have a number of overloads that uses different mechanisms for specifying the source file. The great part is, you don't need to implement these methods on each of your derived classes.  This gives you a better interface and better code reuse.

    Read the article

  • Identifying methods with a specified Id in D [migrated]

    - by Ekyo777
    I want to have specific methods with a specific pattern recognized at compile time and registered along with a specified id trough mixins in a parent class. ex.: take a method 'X' from a class with a predetermined id:5, what I want is that, in a mixin in a parent class, method X will be registered as a delegate with its id to be called later on by its id. What would be the best way to specify the Id considering I want the id to be of type int and only the specified methods to be registered? should I (if it is even possible) do it with a custom annotation pretty much like the @property but with an argument, like: @autoregister(id) void method(...) if it is possible to do it this way, an example or a link to the documentation on how to do it would be nice since I didn't find it in the documentation.

    Read the article

  • using static methods and classes

    - by vedant1811
    I know that static methods/variables are associated with the class and not the objects of the class and are useful in situations when we need to keep count of, say the number of objects of the class that were created. Non-static members on the other hand may need to work on the specific object (i.e. to use the variables initialized by the constructor) My question what should we do when we need neither of the functionalities? Say I just need a utility function that accepts value(s) and returns a value besed solely on the values passed. I want to know whether such methods should be static or not. How is programming efficiency affected and which is a better coding practice/convention and why. PS: I don't want to spark off a debate, I just want a subjective answer and/or references.

    Read the article

  • rpmbuild on Cent OS 6: "cpio: bad magic"

    - by djhaskin987
    When I try to run this command : rpmbuild -bb SPECS/software.spec I get an error when the WAR file (as in tomcat java web archive file) is being added to the rpm: error: create archive failed on file /<filepath>/<filename>.war: cpio: Bad magic This didn't use to happen. The only things that have changed since this worked was an upgrade. Further, no problems are happening like it on my CentOS 5 box. I compile and build the exact same code set on both machines, but CentOS 6 won't create an rpm. How do I troubleshoot this? I have already googled it and received few (if any) useful links. This appears nowhere in the user guide for RPM as far as I can see, and Maximum RPM has no section on this.

    Read the article

  • Drag lock crisis with Windows 7 and Apple Magic Trackpad

    - by rockinthesixstring
    This is driving me insane and I've scowered the web for two days trying to fix this. I just picked up an Apple Magic Trackpad to be used exclusively on a Windows 7 PC (not apple with bootcamp). I found a nice driver that got it working right away, but when I'm moving the cursor around the screen, often it will begin "highlighting" text, or picking up and dragging things I don't want it to. I looked in the "regedit" where people are saying there is binary that can be changed, however the driver I installed doesn't use the binary being suggested. Can anyone suggest a better driver for my situation or a way to disable the drag lock that is driving me so nuts? I don't mind not being able to lift my finger when dragging, it's a far better compromise than having the insane feature.

    Read the article

  • Anonymous methods/functions: a fundamental feature or a violation of OO principles?

    - by RD1
    Is the recent movement towards anonymous methods/functions by mainstream languages like perl and C# something important, or a weird feature that violates OO principles? Are recent libraries like the most recent version of Intel's Thread Building Blocks and Microsofts PPL and Linq that depend on such things a good thing, or not? Are languages that currently reject anonymous methods/functions, like Java, making wise choices in sticking with a purely OO model, or are they falling behind by lacking a fundamental programming feature?

    Read the article

  • How to extend methods to a class not to its instances.

    - by Fraga
    Hi. Extending methods to any instance is really easy: public static string LeaveJustNumbers(this string text) { return Regex.Replace(text, @"[\D]", ""); } ... string JustNumbers = "A5gfb343j4".LeaveJustNumber(); But what if i want to extend methods to a sealed class like string, to work like: string.Format("Hi:{0}","Fraga"); Is there any way to do it?

    Read the article

  • Will methods like POST and GET formally evolve someday?

    - by Jorge
    The question may sound a bit naive or stupid, but i was wondering...will POST and GET evolve someday? What other methods exist besides those two? I was wondering specifically about server-pushes... why can't exist a method specifically for that? I don't even know if there's already something similar, and if there is, i apologize for my ignorance. The web is evolving, that's evident...will methods formally evolve too?

    Read the article

  • Extension Methods - IsNull and IsNotNull, good or bad use?

    - by Jaimal Chohan
    I like readability. So, I came up with an extension mothod a few minutes ago for the (x =! null) type syntax, called IsNotNull. Inversly, I also created a IsNull extension method, thus if(x == null) becomes if(x.IsNull()) and if(x != null) becomes if(x.IsNotNull()) However, I'm worried I might be abusing extension methods. Do you think that this is bad use of Extenion methods?

    Read the article

  • How do you manage the namespaces of your extension methods?

    - by Robert Harvey
    Do you use a global, catchall namespace for all of your extension methods, or do you put the extension methods in the same namespace as the class(es) they extend? Or do you use some other method, like an application or library-specific namespace? EDIT: I ask because I have a need to extend System.Security.Principal.IIdentity, and putting the extension method in the System.Security.Principal namespace seems to make sense, but I've never seen it done this way.

    Read the article

  • Python: When passing variables between methods, is it necessary to assign it a new name?

    - by Anthony
    I'm thinking that the answer is probably 'no' if the program is small and there are a lot of methods, but what about in a larger program? If I am going to be using one variable in multiple methods throughout the program, is it smarter to: Come up with a different phrasing for each method (to eliminate naming conflicts). Use the same name for each method (to eliminate confusion) Just use a global variable (to eliminate both) This is more of a stylistic question than anything else. What naming convention do YOU use when passing variables?

    Read the article

  • Given a PHP class would be the best and simplest way to override one or two of its methods with one

    - by racl101
    Here's the objective. I have a PHP class and there are one or two of its methods that I would like to override with my own. As I understand OOP (in PHP and in general) I could write a child class that extends it and overrides the functionality of the methods in question. However, I was wondering if this is the best way of achieving this task and if this is a proper use for child classes or if there is something better in PHP for what I'm trying to do.

    Read the article

  • How do I get the Apple Wireless Keyboard Working in 10.10?

    - by Jamie
    So I've gone and bought a Magic Mouse and Apple Wireless Non-Numeric Keyboard. The magic mouse worked out-of-the-box almost perfectly, except for the forward/back gesture which still isn't functioning, whereas the keyboard didn't. It has constant trouble with the bluetooth connection. Only the 7, 8 and 9 buttons and volume media keys correspond correctly with the output. Pressing every single key on keyboard has this output: 789/=456*123-0.+ When I use Blueman the keyboard can be setup and shows up in "Devices" but I get a warning when I click "Setup"; "Device added successfully, but failed to connect" (although removing the keyboard and setting it up as a new device doesn't incur this error). Using gnome-bluetooth I have encountered no error messages but it connects properly less often than Blueman and I can still only type the aforementioned output. What am I not doing? Where is this going wrong? EDIT: I have read this http://ubuntuforums.org/showthread.php?t=224673 inside out several times to no avail. It seems these commands don't work for me with the apple peripherals sudo hidd --search hcitool scan Fortunately I have the luxury of a 1TB hard drive, near limitless patience and no job. I have installed a fresh Ubuntu 10.10 64bit (albeit smaller than mine) and after updating and restarting for the first time, I set up my devices in exactly the same way as I have learnt on my original install I succeeded once again with the mouse and, to my joy, with the keyboard also. Though I could not seem to find Alt+F2 and had to reconfigure that and several other keyboard shortcuts, the keyboard is working and in a spectacular fashion. Still, this leaves me with the issue of my original install. I returned to it with some new found knowledge but failed again. Perhaps I have a missing dependancy? I did uninstall bluetooth after the initial set up and reinstalled it recently for the pupose of these peripherals. Maybe it's because I'm running 64bit? This is still not solved, but easily avoided by not changing too much from the original install. Just hide stuff or turn it off, don't uninstall too much.

    Read the article

  • Is this a File Header / Magic Number?

    - by Hammer Bro.
    I've got 120,000 files (way more, actually; this is just an arbitrary subset) of an unknown type. Linux file does not identify them (not that they're necessarily Linux files), nor do any other methods I've tried. There are only two hints about them that I currently have. One is that I suspect some compression is employed -- I have metadata that claims the file sizes are always some amount larger than what I observe. The other is that in 100,000 of these files, the first 16 bytes are always: ff ee ee dd 00 00 00 00 01 00 00 00 00 00 00 00 That really looks like a file header/magic number to me, but I just can't place it. Does anyone know what kind of files this would indicate? Alternatively, can anyone convince me that these suspiciously common bytes certainly do not indicate a specific file type? UPDATE I don't know the exact reverse-engineering details, but most of the files in our case are zips after the first 29(? or so) bytes are ignored. So in practice the problem is solved (we know how to process the files) but in theory the question is still unanswered -- I don't know which application routinely prepends about 29 bytes to its zips. [I'm not sure if I should leave the question open or not at this point.]

    Read the article

  • Windows 7 - "Magic" frequent folder

    - by TheAdamGaskins
    Every week, I export an mp3 file from audacity into a folder with that day's date (e.g. this past sunday I exported the file to a folder named 20130609). Then I close everything and that's it for a while. Then, I come back a few hours later to upload the file to ftp. I usually have some folders open, so to open a new one, I right click on the folder icon on the taskbar... to open a new folder window and browse to this folder I just created, right? Well I look up a little bit and: So I click it and upload the file, and it actually saves me 30 seconds, which is really awesome... but what in the world? It happens every single week without fail. I create the folder inside the audacity export window. The folder stays on the frequent list until I create a new folder the following week. This was definitely not an advertised feature of Windows 7, and it's extremely handy... but it really just seems like magic to me. How does it work?

    Read the article

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