Hello,
I'm currently playing around with the XmlSerializer to replace my old
handmade Xml parsing code, but am having a few small issues with
default values and derived classes.
Say we have classes A, B and C:
abstract class A
{
protected int a_value = 1;
[XmlAttribute("v alue"), DefaultValue(1)]
public int AValue
{
get { return a_value; }
set { a_value = value; }
}
}
class B : A
{
....
}
class C : A
{
....
}
Now, I want class B and C to have different default values, more
precisely, I want B to have 1 as default value and C to have
Int32.MaxValue. But I can't figure out how to actually make this work.
I tried making the property in A abstract and provide the
implementation in B and C with different default values, but it still
used the default value from A. I tried removing the default value from
A, which gave the result of having no default value, everything was
printed, always.
I then tried to remove the XmlAttribute attribute from A and only have
it and the default value in B and C, but it gave me the following
exception:
System.InvalidO perationExcepti on: There was an error reflecting
property 'AValue'. ---> System.InvalidO perationExcepti on: Member
B.AValue' hides inherited member 'A.AValue', but has different custom
attributes.
Anyone have any ideas for this? :-)
Thanks,
- Rasmus. 2 4156
Rasmus,
Did you resolve this issue? I just encountered the same problem and
have been searching for a solution, but yours is the only posting I've
found related to the XmlSerializer and default values in derived
classes.
An interesting side note is that the PropertyGrid control recognizes
that the value assigned to the derived class is the default value
specified for the overridden property.
Thanks!
Amy
Rasmus Kromann-Larsen wrote: Hello,
I'm currently playing around with the XmlSerializer to replace my old handmade Xml parsing code, but am having a few small issues with default values and derived classes.
Say we have classes A, B and C:
abstract class A { protected int a_value = 1;
[XmlAttribute("v alue"), DefaultValue(1)] public int AValue { get { return a_value; } set { a_value = value; } } }
class B : A { ... }
class C : A { ... }
Now, I want class B and C to have different default values, more precisely, I want B to have 1 as default value and C to have Int32.MaxValue. But I can't figure out how to actually make this work. I tried making the property in A abstract and provide the implementation in B and C with different default values, but it still used the default value from A. I tried removing the default value from A, which gave the result of having no default value, everything was printed, always.
I then tried to remove the XmlAttribute attribute from A and only have it and the default value in B and C, but it gave me the following exception:
System.InvalidO perationExcepti on: There was an error reflecting property 'AValue'. ---> System.InvalidO perationExcepti on: Member B.AValue' hides inherited member 'A.AValue', but has different custom attributes.
Anyone have any ideas for this? :-)
Thanks, - Rasmus.
No,
unfortunatly I havn't had a chance to work on that project since then,
so I havn't resolved my error yet. :-)
- Rasmus. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Maurice Mertens |
last post by:
Hi,
I have an Access database in which I defined default values for certain
columns. On my windows forms I've got controls bound to the dataset, The
problem is that when I add a new row to the dataset my controls don't have
the defaultvalue entered in the database.
Is it possible to retrieve the defaultvalue for the column from the
database?
|
by: SJD |
last post by:
I've just read Christoph Schittko's article on XmlSerializer:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp
. . . and very informative it is too.
I, too, am getting nasty FileNotFound exceptions. I've read, and
digested the article, and I think I've found a bug -- it's difficult to
track, though it does happen often.
|
by: Mark |
last post by:
How do I write the following code to set the default value?
Me!xNum.DefaultValue =
Me!XCurrency.DefaultValue =
Me!XDate.DefaultValue =
Me!XString.DefaultValue =
Can I just put all the lines of code in the Form's AfterUpdate event?
Thanks!
|
by: tony |
last post by:
Hello!!
I have some demo programs written in C# and they have this construction
"" see below.
I haven't seen this before so what does it mean ?
public bool ShowDropDownButtons
{
get { return showDropDownButtons; }
|
by: SteveT |
last post by:
I have a boolean property that I want to serialize to disk using XmlSerializer.
I noticed that if the property includes the attribute "DefaultValue(true)"
or "DefaultValue(false)" that the property will not serialilze to an XML
file. If the attribute is removed the serialization occurs just fine.
Is there a way around this bug? This behavior seems to work with any type
of property.
--
| |
by: Peter Hartlén |
last post by:
Hi!
What's the correct syntax for the default value design time attribute, using
classdiagram view and Custom Attributes dialog.
For a boolean:
DefaultValue(true)
DefaultValue("true")
DefaultValue("bool","true")
|
by: kumar.senthil |
last post by:
Hi,
I'm using XmlSerializer to create an object from the XML string. I
would like to know whether I can get a null value for an empty XML
element.
Actually the XmlSerializer assigns "" (empty string) for a string
if the corresponding element is missing in the XML.
Input XML:
<DemoClass><A>some value</A><B></B><DemoClass>
|
by: Phil Galey |
last post by:
I'm using XMLSerializer to serialize hierarchical Class-based objects and
their content to XML. There are a number of fields (i.e. properties) that
are optional, meaning that if no data id written to that property of the
object, then no entry is to appear in the XML, as the destination system
already knows the default values for those fields.
The issue I'm having is that although this is easy to do with String
properties by setting them...
|
by: dmonder |
last post by:
I am using the XMLSerializer to map the XML below to an object as
follows:
Config config
XmlSerializer xmls = new XmlSerializer( typeof( Config ) );
try {
TextReader tr = new StreamReader( "config.xml" );
config = (Config)xmls.Deserialize( tr );
tr.Close();
} catch (System.IO.FileNotFoundException) {
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |