|
Hello there,
Would you please explain , how the below method (that is bold) works ?
public class RelayCommand : ICommand
{
readonly Action<object> _execute;
readonly Predicate<object> _canExecute;
public RelayCommand(Action<object> execute)
: this(execute, null)
{
}
public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
[DebuggerStepThrough]
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
_execute(parameter);
}
}
I mean , what's the meaning of : this(execute, null) ?
|
|
|
|
|
It calls the constructor below it: it's like base(whatever).
<mod>The point is to avoid duplicating whatever functionality is in the two-parameter method.
|
|
|
|
|
Thanks,
What's the name of these methods ?
Is there a specific name for these methods ?
|
|
|
|
|
It works on constructors only, i.e. methods that:
- have no return type;
- have a name identical to the class name;
- get invoked using the new keyword.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
modified on Friday, February 5, 2010 4:29 PM
|
|
|
|
|
Got it
|
|
|
|
|
So, this(execute, null) means something like base(execute, null)
|
|
|
|
|
No, they are different.
use base to refer to the base class, the class from which the current class derives.
this refers to some other constructor of the current class; the normal use is:
- one implements the "full" constructor, the one taking most parameters;
- then one refers all other constructors to the first one, by providing default parameters for the missing ones. See your own example.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
modified on Friday, February 5, 2010 4:28 PM
|
|
|
|
|
very good,
Thanks dude
|
|
|
|
|
this(execute, null) passes the call through to the second constructor - setting the predicate to null. As you can't call a constructor by name, you need to do this to actually call the second constructor. As you know, in a method, you can do the following:
public void DoThis(int index)
{
DoThis(index, null);
}
public void DoThis(int index, string message)
{
} While it would be nice to do this with a constructor, you can't:
public MyClass()
{
MyClass(null);
}
public MyClass(string message)
{
} In order to get the same effect, you modify the constructor definition instead.
public MyClass() : this(null)
{
}
public MyClass(string message)
{
} Now, this differs from calling base which invokes a method on the parent class, rather than this class. What you can't do, is combine this and base in a constructor - it's one or the other.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
excellent, I've got it.
|
|
|
|
|
Hey,
I'm looking for an easy way to add automatic updating to one of my apps. I'm pretty lazy when it comes to deployment though, and am looking for something that can automatically detect if there are newer files in some remote SVN dir, and replace the files of the local old version of the app with these.
Does anyone know of an update platform/library/whatev that does such a thing, or comes close?
Cheers!
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
|
Hi,
I have a WCF service listening on a dynamic allocated port in windows Service Registry. How can i find the listening address of this service from another c# application? Or at least the port of this service?
Thanks, Adriana
|
|
|
|
|
Have the server expose a method on a fixed port number that does not move, telling each client that asks what port the service is currently listening on. There is no "automatic" method of doing this.
|
|
|
|
|
i want build a software in c# that i can control pc using voice commands.... how i will start.... give starting source code....
|
|
|
|
|
Basudevkuet wrote: i want build a software in c# that i can control pc using voice commands.... how i will start.... give starting source code....
I want a million dollars ... give money.
If Barbie is so popular, why do you have to buy her friends?
Eagles may soar, but weasels don't get sucked into jet engines.
If at first you don't succeed, destroy all evidence that you tried.
|
|
|
|
|
|
Basudevkuet wrote: Is it fun???????
Did you see a smiley in his answer? No. So he is deadly serious.
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
I assume you called your form Form1.
|
|
|
|
|
This is a complicated task, as you were told yesterday.
Microsoft provided a Speech API (recognition and text-to-speech) built in to Vista and Windows 7
See
http://en.wikipedia.org/wiki/Microsoft_Speech_API[^]
You should re-use this
If you want to implement your own, good luck, but given you have asked for the source code directly, the probability of you achieving this yourself is hovering around zero.
Cpianism: I have a negative number in my Rep so please fix it.
Chris Maunder: That isn't a bug.
|
|
|
|
|
it is possible to control the operating system by voice command.... because one of our senior brother has already done it... but now he is out of network.... if you know please give idea about the process...
|
|
|
|
|
Obvious, since you've seen it done already, it is possible.
It requires writing a lot of code for each of those things you want it to do.
|
|
|
|
|
Basudevkuet wrote: it is possible to control the operating system by voice command
Correct, for example the API that Microsoft provides with Vista / Windows 7 that I suggested does this, it is available for you to use in your code.
Basudevkuet wrote: because one of our senior brother has already done it
Perhaps heHe almost definately used an API.
Now I realise this is a hard concept to grasp, buy as a developer, I assume you'll understand the following:
Possible != Easy.
Practical voice commanding certainly falls under the "fantastically hard" category, which is why people use the 3rd party APIs (like the Microsoft one I suggested). It is also why none of the APIs work perfectly.
Basudevkuet wrote: if you know please give idea about the process
The process is as follows:
- Look at the wikipedia entry on my original post
- Google for SAPI 5.3
- Research and use SAPI to provide the functrionality you want
- If you then have specific problems, come back here and post a question following the guidelines
If you make a decent stab at steps 1-3, you are unlikely to get flamed here at step 4.
Cpianism: I have a negative number in my Rep so please fix it.
Chris Maunder: That isn't a bug.
|
|
|
|
|
Basudevkuet wrote:
how i will start.... give starting source code
using System;
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|