methods

php class call external class

I have a php page that calls and runs a method called pagestart() in a class called construct. Later in that same page I call a different method in a different class. If that different method errors for any reason I would like to have it call the error() function in the construct class. My question is is there a way to call the error() ...

Calling a method when thread terminates

I have a form that starts a thread. Now I want the form to auto-close when this thread terminates. The only solution I found so far is adding a timer to the form and check if thread is alive on every tick. But I want to know if there is a better way to do that? Currently my code looks more less like this partial class SyncForm : Form ...

Intercept slice operations in Python

I want to imitate a normal python list, except whenever elements are added or removed via slicing, I want to 'save' the list. Is this possible? This was my attempt but it will never print 'saving'. class InterceptedList(list): def addSave(func): def newfunc(self, *args): func(self, *args) print 'savi...

c# count number of objects of class type within class method

How can I count the number of objects of a class type within a method of that class? For that matter, how to do it outside of a class without adding the objects to a list? I should have thought of that! Thanks! I'm gonna leave it unanswered for a little while to see if there is a better way, because I agree. I'm just sortv wrapping my h...

c# call object by unique property

I have a class Referrals. When you create an object in the class, it checks that the input strings are unique (and therefore never allows duplicate objects). But when I find that input string str1 is equal to that of a previously created object, instead of creating a new object or just returning false, i want to change a property of the ...

C# and method hiding

Per MSDN, the "new" keyword when used for method hiding only suppresses a warning. http://msdn.microsoft.com/en-us/library/435f1dw2.aspx Do I really need this "new" keyword to perform method hiding? If I have a child class that has the same method name but doesn't explicitly state that it is overriding, isn't that the same thing ess...

How long should functions/methods should be in average?

Hi there... We've all read excessively long methods or functions, where your eyes end up bleeding when you reach the return statement. We've also seen those one-liner functions that seem pointless... I just wanted to ask: which do you think is the best average length for a function/method? Having into account that every language has it...

Adding 'new' in front of the return type of C# method definition?

So I recently ran into this C# statement at work: public new string SomeFunction(int i) { return base.SomeFunction(i); } I searched the web but I think I can find a better answer here. Now, I'm guessing that all this does is return a new string with the same value as the string returned by the call to base.SomeFunction(i)... ...

"Overloads" keyword in VB.NET

Do you really need this keyword to overload methods? What is the difference between using the overloads keyword vs. just having different method signatures? ...

Preferred way to "move" an object between lists

I have two separate lists of entities: class EntityCollection : IList<Entity> { //... } EntityCollection Foo; EntityCollection Bar; I want to implement an operation to move an object Qux that is on list Foo to Bar. What's the best way to implement it? As a MoveTo instance method on EntityCollection: public void MoveTo(EntityCo...

PHP Method Chains - Reflecting?

Is it possible to reflect upon a chain of method calls to determine at what point you are in the chain of calls? At the very least, is it possible to discern whether a method is the last call in the chain? $instance->method1()->method2()->method3()->method4() Is it possible to do the same using properties that return instances of obje...

iPhone - Custom Class Won't Access Method

I'm trying my hand at some iPhone programming and I've run across something that may be fairly obvious to veterans but I'm not exactly sure why it's happening. I have two UIViewController classes, and I want to access a method from the other class. I have two NSObject classes associated with both of them in IB (with the Class file as U...

Any way to access array directly after method call?

Is there any way to do this in one line? $arr = $foo->getBarArray(); return $arr[0]; This throws an error: return $foo->getBarArray()[0]; ...

Javascript question: Problem with calling an objects methods

Say I have an object called FieldEdit. I define the function constructor for this object, instantiate it via. var obj = new FieldEdit(), and define its methods by FieldEdit.prototype.<method name> = function() { ... }. Under what situations would calling this object's methods within the objects' other methods (via. this.<method name>()...

Generic method in Java, determine type

I would like to be able to detirmine the return type of my method call at runtime, but I can not seem to be able to get the Type of T. public <T> T getT() { Object t = null; Class<?> c = t.getClass(); System.out.println(c.getName()); return (T) t; } Is there any way to determine the Type of T at runtime in Java? ...

Invoke method in another class

I have two view controllers (viewControllerA and viewControllerB) with their own views. When the user touches a button in the view of viewControllerA, I am able to load the view of the viewControllerB. However, I don't know how to invoke a method in viewControllerB's class! ...

How do I find all the methods that have specific parameters with reflection?

I need to find all the methods in a class that accept a set of parameters in a specific order, some of them are generics (Collection). The example on the Sun web site only works with non generic classes: http://java.sun.com/docs/books/tutorial/reflect/member/methodInvocation.html cheers in advance ...

Count the number of times a method is called in Cocoa-Touch?

I have a small app that uses cocos2d to run through four "levels" of a game in which each level is exactly the same thing. After the fourth level is run, I want to display an end game scene. The only way I have been able to handle this is by making four methods, one for each level. Gross. I have run into this situation several times ...

What is the difference between Methods and Attributes in Ruby?

Can you give me an example? ...

Generate List of methods of a class with method types

I want to generate a list of all methods in a class or in a directory of classes. I also need their return types. Outputting it to a textfile will do...Does anyone know of a tool, lug-in for VS or something which will do the task? Im using C# codes by the way and Visual Studio 2008 as IDE ...