473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

VB.NET -. C# signatures different for XML Attributes

I notice when moving from VB.NET -> C# that the overloads are different
for

<XMLRoot(....) >
[XMLRoot(....) ]

<XMLElement(....) >
[XMLElement( ....) ]

but in notice the following seems to compile in C#
[XmlRoot(ElementName="message", Namespace="http://myurl")]

even though this is option is not shown Intellisense.

i imagine this related to C# not supporting optional parameters.

But is it ok to proceed as above?

Dickster

Nov 12 '05 #1
2 2805
also tell me this:

Why to i have to capatalise the first letter in ElementName & Type when
the documentation says:
XmlElementAttribute(String elementName,System.Type type)

This doesnt compile
[XmlElementAttribute(elementName="dickster",type =
typeof(dickstersClass))]

But this does compile
[XmlElementAttribute(ElementName="dickster",Type =
typeof(dickstersClass))]

Nov 12 '05 #2
"dickster" <gd***@kerrhenderson.com> wrote in message news:11*********************@o13g2000cwo.googlegro ups.com...
Why to i have to capatalise the first letter in ElementName & Type when : : This doesnt compile
[XmlElementAttribute(elementName="dickster",type =
typeof(dickstersClass))]

But this does compile
[XmlElementAttribute(ElementName="dickster",Type =
typeof(dickstersClass))]


There is a fundamental difference between [XmlElement( "Joe")] and
[XmlElement( ElementName = "Joe")].

The first case is creating the XmlElementAttribute 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 XmlElementAttribute 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 XmlElementAttribute, 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 (GetCustomAttributes( ) at run-time,
anyone?)
Derek Harmon
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Adie | last post by:
Hi, I wonder if anyone might lend me a brain. I have a stock database to build that covers over 1000 products, which might be said to exist in around 50 product families. Obviously, just to be...
16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
4
by: Burghew | last post by:
Hi all, I am trying to design a database in access 2002. I have multiple category of items such as computers which may include laptop, server, pc...all of these items have different attributes,...
2
by: Burghew | last post by:
Hi all, Kindly help me out on this one. I am having a computer shop and we have many IT related equipments nearly 30 categories which comprises of Servers, Laptops, PC's, Printers, routers,...
6
by: Matt Frame | last post by:
I have a client that has asked us to get a digital signature certificate and start digitally signing all files we pass between each other. I have heard of the subject and know about the certs but...
1
by: karflips33 | last post by:
Is it possible to automate the signing of Word 2003 docs with Digital Signatures? My problem with the code approach using ActiveDocument.Signatures.Add
4
by: jianyi | last post by:
Hi, I am working on an xml project, and I am trying to understand something. if the author needs to sign one xml file, then his manager will counter-sign, and a third witness will sign, can...
6
by: tshad | last post by:
Is there a way to set one item in a dropdown list to a different color? I have a case where I might have 15 items and one is a default and would like to set the default as green where all the...
13
by: anil.rita | last post by:
When the user chooses an AV file to play, based upon the type of file, I want to use the default installed media player to play it. I am wondering if this is a good way - any alternatives,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.