"dickster" <gd***@kerrhend erson.com> wrote in message news:11******** *************@o 13g2000cwo.goog legroups.com...
Why to i have to capatalise the first letter in ElementName & Type when
: : This doesnt compile
[XmlElementAttri bute(elementNam e="dickster",ty pe =
typeof(dickster sClass))]
But this does compile
[XmlElementAttri bute(ElementNam e="dickster",Ty pe =
typeof(dickster sClass))]
There is a fundamental difference between [XmlElement( "Joe")] and
[XmlElement( ElementName = "Joe")].
The first case is creating the XmlElementAttri bute by calling the constructor
that takes a single string argument. As you've mentioned, the name of that
parameter is elementName, but it doesn't really -- the fact is it's a constructor
that takes one string and that's all the runtime cares about. The sequence of
arguments matters, because it must match the formal parameters list of the
constructor.
The second case creates the XmlElementAttri bute by calling the default
constructor which takes no arguments. After it constructs the XmlElement-
Attribute, it then goes through and sets properties on it. The property name
is ElementName, proper case and case sensitive.
[XmlElement( ElementName = "Joe", Type = typeof( Restauranteur))], and
[XmlElement( Type = typeof( Restauranteur), ElementName = "Joe")]
are the same except for the order in which the properties get assigned. Thus,
it's not a magical way of passing parameters to a constructor where the run-
time magically figures out what you meant to do, but a standard feature that
is applicable by necessity.
Think of the requirements for XmlElementAttri bute, and runtime attributes in
general, if there needed to be overloaded constructors for every possible
combination of properties developers might want to set? Without them, it
would be terribly inconvenient to set some of the less-frequently used
properties like IsNullable and Form (GetCustomAttri butes( ) at run-time,
anyone?)
Derek Harmon