UndoableBase.CopyState() implementation

UndoableBase.CopyState() implementation

Old forum URL: forums.lhotka.net/forums/t/465.aspx


antoan posted on Monday, June 26, 2006

This method makes use of Type.IsAssignable() to check if a field is IUndoableObject :

if(typeof(Csla.Core.IUndoableObject).
IsAssignableFrom(field.FieldType))
{ // Call fields CopyState() method }

Would it not be simpler to use the 'is' operator like:

if( field is IUndoableObject) {...}

?

RockfordLhotka replied on Monday, June 26, 2006

It would seem so, except "field" is of type FieldInfo and so that would never return true. Unless I'm willing to always pay the price to call GetValue() to get the actual value, I can't check its type using the is operator. So instead I use this technique to do a type check using the type information itself rather than the instance of an object.

antoan replied on Tuesday, June 27, 2006

Thanks, I overlooked that.

A

Copyright (c) Marimer LLC