I may retreat, or really very close. Anyway, I'm SOL now. :)
I want to be able to use the extension method to set properties in a class, but this class may (or may not) be updated in a thread other than the UI, and inferred from the class that forces updates to the UI (which implements INotifyPropertyChanged, etc.). d.).
I have a class defining something like this:
public class ClassToUpdate : UIObservableItem
{
private readonly Dispatcher mDispatcher = Dispatcher.CurrentDispatcher;
private Boolean mPropertyToUpdate = false;
public ClassToUpdate() : base()
{
}
public Dispatcher Dispatcher
{
get { return mDispatcher; }
}
public Boolean PropertyToUpdate
{
get { return mPropertyToUpdate; }
set { SetValue("PropertyToUpdate", ref mPropertyToUpdate, value; }
}
}
I have an extension method class defining something like this:
static class ExtensionMethods
{
public static IEnumerable<T> SetMyProperty<T>(this IEnumerable<T> sourceList,
Boolean newValue)
{
ClassToUpdate firstClass = sourceList.FirstOrDefault() as ClassToUpdate;
if (firstClass.Dispatcher.Thread.ManagedThreadId !=
System.Threading.Thread.CurrentThread.ManagedThreadId)
{
}
else
{
foreach (var classToUpdate in sourceList)
{
(classToUpdate as ClassToUpdate ).PropertyToUpdate = newValue;
yield return classToUpdate;
}
}
}
}
Obviously, I'm looking for “What's happening here” in the extension method.
Thanks, WTS
source
share