Search Results

Search found 11306 results on 453 pages for 'methods'.

Page 18/453 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • .Net 4.0, New methods in existing classes

    - by Yogesh
    Is there a blog or MSDN article, which lists all the new methods which are added in .Net 4.0 in existing classes? I could not find any. Two which I found on blogs till now: String.IsNullOrWhiteSpace Enum.HasFlag Are there more such methods added which anybody found? If yes, please share.

    Read the article

  • Refactor the following two C++ methods to move out duplicate code

    - by ossandcad
    I have the following two methods that (as you can see) are similar in most of its statements except for one (see below for details) unsigned int CSWX::getLineParameters(const SURFACE & surface, vector<double> & params) { VARIANT varParams; surface->getPlaneParams(varParams); // this is the line of code that is different SafeDoubleArray sdParams(varParams); for( int i = 0 ; i < sdParams.getSize() ; ++i ) { params.push_back(sdParams[i]); } if( params.size() > 0 ) return 0; return 1; } unsigned int CSWX::getPlaneParameters(const CURVE & curve, vector<double> & params) { VARIANT varParams; curve->get_LineParams(varParams); // this is the line of code that is different SafeDoubleArray sdParams(varParams); for( int i = 0 ; i < sdParams.getSize() ; ++i ) { params.push_back(sdParams[i]); } if( params.size() > 0 ) return 0; return 1; } Is there any technique that I can use to move the common lines of code of the two methods out to a separate method, that could be called from the two variations - OR - possibly combine the two methods to a single method? The following are the restrictions: The classes SURFACE and CURVE are from 3rd party libraries and hence unmodifiable. (If it helps they are both derived from IDispatch) There are even more similar classes (e.g. FACE) that could fit into this "template" (not C++ template, just the flow of lines of code) I know the following could (possibly?) be implemented as solutions but am really hoping there is a better solution: I could add a 3rd parameter to the 2 methods - e.g. an enum - that identifies the 1st parameter (e.g. enum::input_type_surface, enum::input_type_curve) I could pass in an IDispatch and try dynamic_cast< and test which cast is NON_NULL and do an if-else to call the right method (e.g. getPlaneParams() vs. get_LineParams()) The following is not a restriction but would be a requirement because of my teammates resistance: Not implement a new class that inherits from SURFACE/CURVE etc. (They would much prefer to solve it using the enum solution I stated above)

    Read the article

  • Putting methods in separate files

    - by Garry
    I have a class (MyClass) with a lot of methods. Consequently, the .m file has become quite difficult to read. I'm relatively new to Objective-C (having come from REALbasic) and I was wondering if it's possible to put some of the methods in MyClass into different files and then include them in the class. How would I go about this in Xcode?

    Read the article

  • File corruption after copying files in Windows 7 64 bit using two methods

    - by DustByte
    I have 5000 pictures and other files in a directory taking up 35 GB. I want to duplicate this directory. Method 1: I do a simple copy and paste of the directory in explorer. I have the habit of checking the checksums after copying important files. In this case I noticed that around 2000 files failed the MD5 test. At a closer inspection of a randomly chosen JPEG with different checksums it turns out that some XMP metadata had changed. In particular, the tag <MicrosoftPhoto:DateAcquired> had changed the date from 2009 to today (possibly around the time I was copying the files). I have no idea what triggered this XMP data to be changed and exactly when it was changed and why for these particular files, but at least it seems to explain the checksum discrepancy. Method 2: As I want the exact files to be duplicated, I tried the program FreeFileSync to mirror the directory, hoping no XMP metadata would mysteriously change. A checksum test in addition to a thorough file comparison test in FreeFileSync lead to two similar but yet different results: 31 files fail the checksum test, 23 files fail the file comparison test. The smaller set is not entirely contained in the bigger set, although many files occur in both. What is alarming here is that not only JPEGs are flagged as altered but also som AVIs, MPGs and a large 7-zip file. Closer inspection of a JPEG indicates that it is indeed corrupt: the bottom half of the picture is simply plain gray. Due to the size of the 7-zip file, I have not been able to pin down the discrepancy. Note, in both methods, every file has its correct file size after being copied. Question: Any thoughts on what is possibly going on here? I have never had this problem before, and I am now terrified that files get corrupted after simple actions like copy/paste and file sync. Even if I manage to successfully copy the files somehow, I would still like an explanation to this.

    Read the article

  • Selectively intercepting methods using autofac and dynamicproxy2

    - by Mark Simpson
    I'm currently doing a bit of experimenting using Autofac-1.4.5.676, autofac contrib and castle DynamicProxy2. The goal is to create a coarse-grained profiler that can intercept calls to specific methods of a particular interface. The problem: I have everything working perfectly apart from the selective part. I gather that I need to marry up my interceptor with an IProxyGenerationHook implementation, but I can't figure out how to do this. My code looks something like this: The interface that is to be intercepted & profiled (note that I only care about profiling the Update() method) public interface ISomeSystemToMonitor { void Update(); // this is the one I want to profile void SomeOtherMethodWeDontCareAboutProfiling(); } Now, when I register my systems with the container, I do the following: // Register interceptor gubbins builder.RegisterModule(new FlexibleInterceptionModule()); builder.Register<PerformanceInterceptor>(); // Register systems (just one in this example) builder.Register<AudioSystem>() .As<ISomeSystemToMonitor>) .InterceptedBy(typeof(PerformanceInterceptor)); All ISomeSystemToMonitor instances pulled out of the container are intercepted and profiled as desired, other than the fact that it will intercept all of its methods, not just the Update method. Now, how can I extend this to exclude all methods other than Update()? As I said, I don't understand how I'm meant to say "for the ProfileInterceptor, use this implementation of IProxyHookGenerator". All help appreciated, cheers! Also, please note that I can't upgrade to autofac2.x right now; I'm stuck with 1.

    Read the article

  • Nested factory methods in Objective-C

    - by StephenT
    What's the best way to handle memory management with nested factory methods, such as in the following example? @implementation MyClass + (MyClass *) SpecialCase1 { return [MyClass myClassWithArg:1]; } + (MyClass *) SpecialCase2 { return [MyClass myClassWithArg:2]; } + (MyClass *) myClassWithArg:(int)arg { MyClass *instance = [[[MyClass alloc] initWithArg:arg] autorelease]; return instance; } - (id) initWithArg:(int)arg { self = [super init]; if (nil != self) { self.arg = arg; } return self; } @end The problem here (I think) is that the autorelease pool is flushed before the SpecialCaseN methods return to their callers. Hence, the ultimate caller of SpecialCaseN can't rely on the result having been retained. (I get "[MyClass copyWithZone:]: unrecognized selector sent to instance 0x100110250" on trying to assign the result of [MyClass SpecialCase1] to a property on another object.) The reason for wanting the SpecialCaseN factory methods is that in my actual project, there are multiple parameters required to initialize the instance and I have a pre-defined list of "model" instances that I'd like to be able to create easily. I'm sure there's a better approach than this.

    Read the article

  • Alternatives to static methods on interfaces for enforcing consistency

    - by jayshao
    In Java, I'd like to be able to define marker interfaces, that forced implementations to provide static methods. For example, for simple text-serialization/deserialization I'd like to be able to define an interface that looked something like this: public interface TextTransformable<T>{ public static T fromText(String text); public String toText(); Since interfaces in Java can't contain static methods though (as noted in a number of other posts/threads: here, here, and here this code doesn't work. What I'm looking for however is some reasonable paradigm to express the same intent, namely symmetric methods, one of which is static, and enforced by the compiler. Right now the best we can come up with is some kind of static factory object or generic factory, neither of which is really satisfactory. Note: in our case our primary use-case is we have many, many "value-object" types - enums, or other objects that have a limited number of values, typically carry no state beyond their value, and which we parse/de-parse thousands of time a second, so actually do care about reusing instances (like Float, Integer, etc.) and its impact on memory consumption/g.c. Any thoughts?

    Read the article

  • Multiple leaf methods problem in composite pattern

    - by Ondrej Slinták
    At work, we are developing an PHP application that would be later re-programmed into Java. With some basic knowledge of Java, we are trying to design everything to be easily re-written, without any headaches. Interesting problem came out when we tried to implement composite pattern with huge number of methods in leafs. What are we trying to achieve (not using interfaces, it's just an example): class Composite { ... } class LeafOne { public function Foo( ); public function Moo( ); } class LeafTwo { public function Bar( ); public function Baz( ); } $c = new Composite( Array( new LeafOne( ), new LeafTwo( ) ) ); // will call method Foo in all classes in composite that contain this method $c->Foo( ); It seems like pretty much classic Composite pattern, but problem is that we will have quite many leaf classes and each of them might have ~5 methods (of which few might be different than others). One of our solutions, which seems to be the best one so far and might actually work, is using __call magic method to call methods in leafs. Unfortunately, we don't know if there is an equivalent of it in Java. So the actual question is: Is there a better solution for this, using code that would be eventually easily re-coded into Java? Or do you recommend any other solution? Perhaps there's some different, better pattern I could use here. In case there's something unclear, just ask and I'll edit this post.

    Read the article

  • Repository Pattern Standardization of methods

    - by Nix
    All I am trying to find out the correct definition of the repository pattern. My original understanding was this (extremely dubmed down) Separate your Business Objects from your Data Objects Standardize access methods in data access layer. I have really seen 2 different implementations. Implementation 1 : public Interface IRepository<T>{ List<T> GetAll(); void Create(T p); void Update(T p); } public interface IProductRepository: IRepository<Product> { //Extension methods if needed List<Product> GetProductsByCustomerID(); } Implementation 2 : public interface IProductRepository { List<Product> GetAllProducts(); void CreateProduct(Product p); void UpdateProduct(Product p); List<Product> GetProductsByCustomerID(); } Notice the first is generic Get/Update/GetAll, etc, the second is more of what I would define "DAO" like. Both share an extraction from your data entities. Which I like, but i can do the same with a simple DAO. However the second piece standardize access operations I see value in, if you implement this enterprise wide people would easily know the set of access methods for your repository. Am I wrong to assume that the standardization of access to data is an integral piece of this pattern ? Rhino has a good article on implementation 1, and of course MS has a vague definition and an example of implementation 2 is here.

    Read the article

  • Using delegate Types vs methods

    - by Grant Sutcliffe
    I see increasing use of the delegate types offered in the System namespace (Action; Predicate etc). As these are delegates, my understanding is that they should be used where we have traditionally used delegates in the past (asynchronous calls; starting threads, event handling etc). Is it just preference or is it considered practice to use these delegate types in scenarios such as the below; rather than using calls to methods we have declared (or anonymous methods): public void MyMethod { Action<string> action = delegate(string userName { try { XmlDocument profile = DataHelper.GetProfile(userName); UpdateMember(profile); } catch (Exception exception) { if (_log.IsErrorEnabled) _log.ErrorFormat(exception.Message); throw (exception); } }; GetUsers().ForEach(action); } At first, I found the code less intuitive to follow than using declared or anonymous methods. I am starting to code this way, and wonder what the view are in this regard. The example above is all within a method. Is this delegate overuse.

    Read the article

  • interface variables are final and static by default and methods are public and abstract

    - by sap
    The question is why it's been decided to have variable as final and static and methods as public and abstract by default. Is there any particular reason for making them implicit,variable as final and static and methods as public and abstract. Why they are not allowing static method but allowing static variable? We have interface to have feature of multiple inheritance in Java and to avoid diamond problem. But how it solves diamond problem,since it does not allow static methods. In the following program, both interfaces have method with the same name..but while implementing only one we implement...is this how diamond problem is solved? interface testInt{ int m = 0; void testMethod(); } interface testInt1{ int m = 10; void testMethod(); } public class interfaceCheck implements testInt, testInt1{ public void testMethod(){ System . out . println ( "m is"+ testInt.m ); System . out . println ( "Hi World!" ); } }

    Read the article

  • Unit test approach for generic classes/methods

    - by Greg
    Hi, What's the recommended way to cover off unit testing of generic classes/methods? For example (referring to my example code below). Would it be a case of have 2 or 3 times the tests to cover testing the methods with a few different types of TKey, TNode classes? Or is just one class enough? public class TopologyBase<TKey, TNode, TRelationship> where TNode : NodeBase<TKey>, new() where TRelationship : RelationshipBase<TKey>, new() { // Properties public Dictionary<TKey, NodeBase<TKey>> Nodes { get; private set; } public List<RelationshipBase<TKey>> Relationships { get; private set; } // Constructors protected TopologyBase() { Nodes = new Dictionary<TKey, NodeBase<TKey>>(); Relationships = new List<RelationshipBase<TKey>>(); } // Methods public TNode CreateNode(TKey key) { var node = new TNode {Key = key}; Nodes.Add(node.Key, node); return node; } public void CreateRelationship(NodeBase<TKey> parent, NodeBase<TKey> child) { . . .

    Read the article

  • is 'protected' ever reasonable outside of virtual methods and destructors?

    - by notallama
    so, suppose you have some fields and methods marked protected (non-virtual). presumably, you did this because you didn't mark them public because you don't want some nincompoop to accidentally call them in the wrong order or pass in invalid parameters, or you don't want people to rely on behaviour that you're going to change later. so, why is it okay for that nincompoop to use those fields and methods from a subclass? as far as i can tell, they can still screw up in the same ways, and the same compatibility issues still exist if you change the implementation. the cases for protected i can think of are: non-virtual destructors, so you can't break things by deleting the base class. virtual methods, so you can override 'private' methods called by the base class. constructors in c++. in java/c# marking the class as abstract will do basically the same. any other use cases?

    Read the article

  • Could a singleton type replace static methods and classes?

    - by MKO
    In C# Static methods has long served a purpose allowing us to call them without instantiating classes. Only in later year have we became more aware of the problems of using static methods and classes. They can’t use interfaces They can’t use inheritance They are hard to test because you can’t make mocks and stubs Is there a better way ? Obviously we need to be able to access library methods without instantiated classes all the time otherwise our code would become pretty cluttered One possibly solution is to use a new keyword for an old concept: the singleton. Singleton’s are global instances of a class, since they are instances we can use them as we would normal classes. In order to make their use nice and practical we'd need some syntactic sugar however Say that the Math class would be of type singleton instead of an actual class. The actual class containing all the default methods for the Math singleton is DefaultMath, which implements the interface IMath. The singleton would be declared as singleton Math : IMath { public Math { this = new DefaultMath(); } } If we wanted to substitute our own class for all math operations we could make a new class MyMath that inherits DefaultMath, or we could just inherit from the interface IMath and create a whole new Class. To make our class the active Math class, you'd do a simple assignment Math = new MyMath(); and voilá! the next time we call Math.Floor it will call your method. Note that for a normal singleton we'd have to write something like Math.Instance.Floor but the compiler eliminates the need for the Instance property Another idea would be to be able to define a singletons as Lazy so they get instantiated only when they're first called, like lazy singleton Math : IMath What do you think, would it have been a better solution that static methods and classes? Is there any problems with this approach?

    Read the article

  • Designing interfaces: predict methods needed, discipline yourself and deal with code that comes to m

    - by fireeyedboy
    Was: Design by contract: predict methods needed, discipline yourself and deal with code that comes to mind I like the idea of designing by contract a lot (at least, as far as I understand the principal). I believe it means you define intefaces first before you start implementing actual code, right? However, from my limited experience (3 OOP years now) I usually can't resist the urge to start coding pretty early, for several reasons: because my limited experience has shown me I am unable to predict what methods I will be needing in the interface, so I might as well start coding right away. or because I am simply too impatient to write out the whole interfaces first. or when I do try it, I still wind up implementing bits of code already, because I fear I might forget this or that imporant bit of code, that springs to mind when I am designing the interfaces. As you see, especially with the last two points, this leads to a very disorderly way of doing things. Tasks get mixed up. I should draw a clear line between designing interfaces and actual coding. If you, unlike me, are a good/disciplined planner, as intended above, how do you: ...know the majority of methods you will be needing up front so well? Especially if it's components that implement stuff you are not familiar with yet. ...resist the urge to start coding right away? ...deal with code that comes to mind when you are designing the interfaces? UPDATE: Thank you for the answers so far. Valuable insights! And... I stand corrected; it seems I misinterpreted the idea of Design By Contract. For clarity, what I actually meant was: "coming up with interface methods before implementing the actual components". An additional thing that came up in my mind is related to point 1): b) How do you know the majority of components you will be needing. How do you flesh out these things before you start actually coding? For arguments sake, let's say I'm a novice with the MVC pattern, and I wanted to implement such a component/architecture. A naive approach would be to think of: a front controller some abstract action controller some abstract view ... and be done with it, so to speak. But, being more familiar with the MVC pattern, I know now that it makes sense to also have: a request object a router a dispatcher a response object view helpers etc.. etc.. If you map this idea to some completely new component you want to develop, with which you have no experience yet; how do you come up with these sort of additional components without actually coding the thing, and stuble upon the ideas that way? How would you know up front how fine grained some components should be? Is this a matter of disciplining yourself to think it out thoroughly? Or is it a matter of being good at thinking in abstractions?

    Read the article

  • iPhone SDK: selectRowAtIndexPath with delegate methods

    - by norskben
    Hi SO I am using selectRowAtIndexPath to select a tableview in the same ViewController class, but this does not run the delegate methods, eg: tableView:didSelectRowAtIndexPath I would like these delegate methods to also be called. Is there another API call I can be using? Thanks From the apple docs: selectRowAtIndexPath:animated:scrollPosition: Selects a row in the receiver identified by index path, optionally scrolling the row to a location in the receiver. - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition Calling this method does not cause the delegate to receive a tableView:willSelectRowAtIndexPath: or tableView:didSelectRowAtIndexPath: message, nor will it send UITableViewSelectionDidChangeNotification notifications to observers.

    Read the article

  • NSFetchedResultsController - Delegate methods crashing under iPhone OS 3.0, but NOT UNDER 3.1

    - by Scott Langendyk
    Hey guys, so I've got my NSFetchedResultsController working fine under the 3.1 SDK, however I start getting some weird errors, specifically in the delegate methods when I try it under 3.0. I've determined that this is related to the NSFetchedResultsControllerDelegate methods. This is what I have set up. The inEditingMode stuff has to do with the way I've implemented adding another static section to the table. - (void)controllerWillChangeContent:(NSFetchedResultsController*)controller { [self.tableView beginUpdates]; } - (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type{ NSIndexSet *sectionSet = [NSIndexSet indexSetWithIndex:sectionIndex]; if(self.inEditingMode){ sectionSet = [NSIndexSet indexSetWithIndex:sectionIndex + 1]; } switch (type) { case NSFetchedResultsChangeInsert: [self.tableView insertSections:sectionSet withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [self.tableView deleteSections:sectionSet withRowAnimation:UITableViewRowAnimationFade]; break; default: [self.tableView reloadData]; break; } } - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath{ NSIndexPath *relativeIndexPath = indexPath; NSIndexPath *relativeNewIndexPath = newIndexPath; if(self.inEditingMode){ relativeIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section + 1]; relativeNewIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row inSection:newIndexPath.section + 1]; } switch(type) { case NSFetchedResultsChangeInsert: [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:relativeNewIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:relativeIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; default: [self.tableView reloadData]; break; } } -(void)controllerDidChangeContent:(NSFetchedResultsController *)controller{ [self.tableView endUpdates]; } When I add an entity to the managed object context, I get the following error: Serious application error. Exception was caught during Core Data change processing: *** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1) with userInfo (null) I put a breakpoint on objc_exception_throw, and the crash seems to be occuring inside of controllerDidChangeContent. If I comment out all of the self.tableView methods, and put a single [self.tableView reloadData] inside of controllerDidChangeContent, everything works as expected. Anybody have any idea as to why this is happening?

    Read the article

  • MVC - Calling Controller Methods

    - by JT703
    Hello, My application is following the MVC design pattern. The problem I keep running into is needing to call methods inside a Controller class from outside that Controller class (ex. A View class wants to call a Controller method, or a Manager class wants to call a Controller method). Is calling Controller methods in this way allowed in MVC? If it's allowed, what's the proper way to do it? According to the version of MVC that I am following (there seems to be so many different versions out there), the View knows of the Model, and the Controller knows of the View. Doing it this way, I can't access the controller. Here's the best site I've found and the one describing the version of MVC I'm following: http://leepoint.net/notes-java/GUI/structure/40mvc.html. The Main Program code block really shows how this works. Thanks for any answers.

    Read the article

  • jQuery plug-in with additional methods.

    - by Kieron
    I've a jQuery plug-in that operates on some ULs, adding and removing classes etc. During the life-cycle of the page, I'll need to add/ remove some classes in code, and as my plug-in needs to perform some additional operations when this happens I came up with the following: // This is the initialiser method... $.fn.objectBuilder = function (options) {...}; // These are the two new methods I need. $.fn.objectBuilder.setSelected(element) {...}; $.fn.objectBuilder.removeSelected() {...}; I'd then like to call them like this: $("#ob1").objectbuilder.removeSelected(); Any thoughts? Thanks, Kieron edit I suppose what I'm asking is, whats the best way of adding additional methods to a jQuery plug-in where it'll have access to the root object, in this case #obj when the method is called.

    Read the article

  • UIViewController not oreintating. Methods not called

    - by capple
    Greetings, This question does seem to be an ongoing saga in the world of iphone SDK... so heres my contribution... Had two separate projects from the same template... one semi-works, the other not at all... Please let me explain my steps... used this basic GL ES template //iphonedevelopment.blogspot.com/2008/12/opengl-project-template-for-xcode.html had to sort out some of the 'Release' configuration but otherwises has eveything I need to add orientation to a GL ES project. One my first project, did my stuff, then added these methods.... -(BOOL)shouldAutoRotateToInterfaceOrientation ..... -(void)willRotateToInterfaceOrientation .... -(void)didRotateFromInterfaceOrientation .... -(void)willAnimateRotationToInterfaceOrientation .... And understand what they do (or are trying to do in my case), the (BOOL)should... gets called once when the view controller is created, and returns 'YES'. But after that none of the other methods are called! So I started from scratch with a blank template (GL ES one from above)...and added minimum to support auto rotation. But this time none of the methods get called! So I investigated .... //developer.apple.com/iphone/library/qa/qa2010/qa1688.html as it said, I added the GLViewController.view first, then added the GLview as subviews of the application delegate. Nothing! Then found this //www.iphonedevsdk.com/forum/iphone-sdk-development/44993-how-determine-ipad-launch-orientation.html which states to enable orientation notifications [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; and then subsequently disable them in the view controller... makes sense...did it, nothing... I think the notifications might be on by default though, since I didn't need to enable them in the first project, yet it still try to verify a orientation (i.e (BOOL)shouldAutoRotate... )... If any one could help me out it would be greatly appreciated as this issue is driving me insane. Thanks in advance. The code can be found here ... http://rapidshare.com/files/392053688/autoRotation.zip N.B These projects avoid nib/xib resources, would like to keep it that way if possible. P.S iPad device not out where I am so I cannot test on a device yet. Would be nice for it to work on the simulator.

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >