Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET what is the goal to cast an object to... object?

I was reading the source code of MvvmLight, and I've seen this function in ViewModelBase.cs:

protected virtual void RaisePropertyChanged(string propertyName)
{
    PropertyChangedEventHandler changedEventHandler = this.PropertyChanged;
    if (changedEventHandler == null)
        return;
    changedEventHandler((object) this, new PropertyChangedEventArgs(propertyName));
}

I don't see why there is a cast here, but because this function is critical in MvvmLight, I'm guessing there is an advantage of doing so...

like image 252
Elias Platek Avatar asked Feb 20 '23 23:02

Elias Platek


1 Answers

If you're looking at the code through Reflector you'll always see strange stuff like this because Visual Studio lets you take short-cuts that the compiler works out for you, like passing a type as object without casting it to object.

But to answer your question, the eventhandler requires an object, so it passes this as (object)

like image 198
Chris Gessler Avatar answered Mar 06 '23 03:03

Chris Gessler