Brad Wilson's "Reflection Demystified" includes a sample of getting the
default c'tor:
ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes);
Keep in mind, in order to compare an object to it's "default" it's more
involved than simply getting the default/parameter-less constructor.
Object.Equals is defined as comparing references, not the "value" of an
instance. Just because a type might override Object.Equals, doesn't mean
it's doing anything more than a reference comparison (there's no need to
override Object.Equals if you're not; but that's beside the point).
If the type doesn't override Object.Equals you could try seeing if it
implements various equality/comparison interfaces: IEquatable, IComparable.
If a type is considered "sortable" it would implement IComparable; but that
type may not have a concept of "equality", just less-than or greater-than.
So, you can't fully rely on IComparable for testing equality (i.e. I no way
to tell if an implementation if IComparable is used only for sorting or
sorting AND equality). Start with IEquatable, falling back to IComparable,
if needed.
This, of course, presupposes the type a) has a concept of equality, and b)
has a concept of a "default" value. A class that initializes with the
current date/time, for example, will not have a default value. Or, a class
that defaults to other information unique to an invocation won't have a
default value consistent between invocations (e.g. really important across
remoting boundaries).
--
Browse
http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#