473,396 Members | 1,834 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,396 software developers and data experts.

Problem to serialize a property that return an interface


A class has a private field of type IWizard (An interface) and a public
property to access it.
When I try to serialize the Geometry class in XML, i have an error but it
works in Binary

Can you help me

[Serializable]
public class Geometry
{
....
private IWizard _wizard;
public IWizard Wizard
{
get { return _wizard ;}
set { _wizard = value;}
}
}

Nov 11 '05 #1
1 5385
The XmlSerializer has to have an instantiated object during serialization.
For an interface, however, it would not know what type to instantiate.
Working around this limitation, you can use an abstract base class to
express the semantics of your interface. For example:

public abstract class IWizard
{
public abstract int x
{
get;
set;
}
}
[Serializable]
public class Geometry
{
private IWizard _wizard;
public IWizard Wizard
{
get { return _wizard ;}
set { _wizard = value;}
}
}

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #2

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

Similar topics

0
by: Rhy Mednick | last post by:
I have a series of simple controls that I created to make some aspects of Tablet PC programming a little easier. The "Tablet PC" aspects of the controls are irrelevant to the problem I'm having,...
3
by: Julia | last post by:
Hi, I have an two classes derived from ICommand interface for example SubscribeCommand,and RetryCommand i want to do the following ICommand command1=new SubscribeCommand() ICommand...
1
by: nate axtell | last post by:
I have a custom class with a Private DataTable member and a Public Property that returns this DataTable in its Get call. Is the DataTable that is returned from the Property's Get a reference to...
2
by: ABC | last post by:
Which function or property return the current page URL?
5
by: Sam | last post by:
Hi All I have couple of question regarding property of a class and structures. **** ---- Here is my class and structure ---- ***** 1. Public Structure MyPoint 2. Dim p As Point 3. ...
0
by: haynes george | last post by:
hi .. I was reading the tutorial "Extending and Embedding the python interpreter" available with python .. http://www.python.org/doc/2.2.3/ext/ext.html As per given in the tutorial i...
7
by: none | last post by:
I'm trying to implement a simple repeateable property mechansism so I don't have to write accessors for every single instance variable I have. ------------ classMyObject: def __init__ (self):...
6
by: David Hearn | last post by:
I have a property in a user control that I am setting: Private strPageName as String Public Property PageName() as String Get Return strPageName End Get Set(byVal Value as String)...
2
by: Cristiano de Pádua Milagres Oliveira | last post by:
What do I to declare the header of a Property in an Interface, and should this property return a generic Enum? Example: public interface IMetric { Enum Unit { get;} } public class...
3
by: Joe | last post by:
Hi I have a propertygrid that I allow the user to pick a system.color and I want to save to a file to load later onto the propertygrid. String and bool values work but I am unable to save...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
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...
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
agi2029
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,...

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.