|
Hello,
I have a problem when trying to serialize the components(the components are diffrent and they are represented by an interface from that they are derived) of a list using XmlSerializer in C#. The exception message thrown when this line is executed
"XmlSerializer ser = new XmlSerializer(typeof(ISchedule))"
is "Cannot serialize interface BL.ISchedule".
I want to know if is this thing possible and should I avoid the encountered problem.
Thak you!
Lukas
|
|
|
|
|
Hi!
I don't think this is possible.
Think about it: An interface cannot be instantiated. So the XmlSerializer could somehow serialize the public members that are part of the interface, but it doesn't make much sense because there's no way back. If you only have the information concerning the interface, you cannot create an object from this.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi!
I have thought at what you told me before but I want to serialize some classes that are represented by that interface not the interface. I have this some instances of these classes in a list of interface type elements and I don't know how to serialize every element in list without taking in account its particular type only the type it is derived from. Is this thing possible?
Thank you!
Regards,
Lukas
|
|
|
|
|
When serializing, there is always one root object (which is associated with the root node in the xml). I'm assuming you have an object (say MainClass) that has a collection of sub-objects (say in a property called Items). The Items is a collection of objects that implement an interface (say IMyInterface). Is this correct?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi, Tom!
All what you have supposed is true. Help me,please, if you know the solution for this problem.
Thanks,
Lukas
|
|
|
|
|
If you have a set number of classes, then you can specify these classes that can appear in the Items collection, like so:
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
public class MainClass {
private List<IMyInterface> items = new List<IMyInterface>();
[XmlArrayItem(typeof(MySubClass1))]
[XmlArrayItem(typeof(MySubClass2))]
[XmlArrayItem(typeof(MySubClass3))]
public List<IMyInterface> Items {
get {
return this.items;
}
set {
this.items = value;
}
}
}
If you have a variable number of items, then instead of using XmlArrayItemAttribute, you can specify the class types using this[^] XmlSerializer constructor. Keep in mind that if you use this constructor, that a new assembly (.dll) is created, saved to disk, and loaded into your application's memory every time you call it (see this[^] for more info).
In either case, you will need to know all the class types that will be in the Items property.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi, Tom!
Thanks a lot!
Lukas
|
|
|
|
|
While using this tutorial, ia have problem in the following code
if (Application.OpenForms.Count > 1)
as error occur that 'System.Windows.Forms.Application' does not contain a definition for 'OpenForms'
Can You please solve my problem
Mandeep
Email: cheers_man2003@yahoo.co.in
|
|
|
|
|
Well - it would seem to me that you have three problems:
1. The error tells you that Application doesn't have a definition for OpenForms.
2. I have no idea where this tutorial is.
3. Questions like this should be asked of the author.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete is correct. But, I can tell you that it sounds like you've stumbled acrossed code written for the .NET Framework 2.0 and above, and you're using .NET 1.1 or below. The Application.OpenForms property didn't show up until .NET 2.0.
|
|
|
|
|
hi
Thanks for reply.
I am using .NET 2003 version. if that event is not available in this version , then please solve my problem by giving me other alternative that I can use in its place.
Mandeep
Email: cheers_man2003@yahoo.co.in
|
|
|
|
|
That's not an event. It's a property that exposes a collection.
There is no equivilent in .NET 1.x. Since all you did was say that this particular line gave you a problem, I can't give you an alternative to anything. You haven't described what the goal of using this code it.
If what you're looking for is something that shows you how to up a Splash screen, then all you need to do is Google for "VB.NET .NET 1.1 Splash Screen".
|
|
|
|
|
Forgive the 'generic' formatting, I don't seem to be able to post 'proper' generic code here.
I have a simple class (see below). I need to have a way to have a SINGLE collection of 'GenericDataElement' objects.
Is this possible? Some of the items may be GenericDataElement<<string>> , while others may be GenericDataElement<<int>>.
public class GenericDataElement<<T>> <br />
{<br />
private string name;<br />
private T value;<br />
<br />
<br />
public string Name<br />
{<br />
get { return name; }<br />
}<br />
<br />
public T Value<br />
{<br />
get { return value; }<br />
}<br />
<br />
public GenericDataElement(string name, T value)<br />
{<br />
this.name = name;<br />
this.value = value;<br />
}<br />
<br />
}
|
|
|
|
|
It isn't possible to have a strongly typed generic list that allows 2 different type parameters, but you can do something like that:
public class GenericDataElement
{
}
public class GenericDataElement<T> : GenericDataElement
{
public GenericDataElement(string name, T value)
{
this.name = name;
this.value = value;
}
private string name;
public string Name
{
get { return name; }
}
private T value;
public T Value
{
get { return value; }
}
}
public class Test
{
List<GenericDataElement> list = new List<GenericDataElement>();
public void TestIt()
{
list.Add(new GenericDataElement<string>("string", "value"));
list.Add(new GenericDataElement<int>("int", 1));
foreach (GenericDataElement gde in list)
{
if (gde is GenericDataElement<int>)
Console.WriteLine("int");
else
Console.WriteLine("string");
}
}
}
But you will have an untyped collection, of course.
-^-^-^-^-^-
no risk no funk ................... please vote ------>
|
|
|
|
|
Hy,
I have the following code put in the protected override OnKeyDown to a RichTextBox:
switch (e.KeyCode)
{
case Keys.Tab:
case Keys.Enter:
{
autocomplete(_defaultColor);
e.Handled = true;
break;
}
}
and the autocomplete method:
private void autocomplete(Color defaultColor)
{
for (int i = 0; i < 1; i++)
{
SendKeys.SendWait("{BACKSPACE}");
}
SendKeys.SendWait("public");
}
1.Run the application and press "p" then press ENTER.
2.Run the application and press "p" then press TAB.
In both cases the effect is different but is the same code for both cases.
Can somebody give me an explication?
-- modified at 8:58 Tuesday 9th October, 2007
|
|
|
|
|
Hi,
unless you set KeyEventArgs.SuppressKeyPress true, there will be a KeyPress event,
which will act differently for ENTER and TAB.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hello Luc,
Luc Pattyn wrote: set KeyEventArgs.SuppressKeyPress true
very interesting!
Do you also know a .Net 1.1 solution for that problem?
All the best,
Martin
|
|
|
|
|
Hi Martin,
sorry I don't know a replacement for KeyEventArgs.SuppressKeyPress other than adding
specific code in one or both event handlers.
I stopped using .NET 1.x completely.
Greetings,
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hello Luc,
But isn't there allways the problem, that the "Tab" leeds to loosing the Focus of the Control?
Luc Pattyn wrote: I stopped using .NET 1.x completely.
Oh no!
The last one (apart from me) left the ship!
All the best,
Martin
|
|
|
|
|
Martin# wrote: But isn't there allways the problem, that the "Tab" leeds to loosing the Focus of the Control?
There was and is a solution to these by using one of Control.IsInputChar
and Control.ProcessCmdKey
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Excellent!
All the best,
Martin
|
|
|
|
|
According to Microsoft compressed folders in windows uses the following .dlls
1) Dunzip32.dll: Responsible for decompressing files stored in a compressed folder or file when they are copied, extracted, or executed.
2) Dzip32.dll: Responsible for compressing files when they are put into a compressed folder or file.
I need these dlls for a Console project that directly uses them to compress and decompress .zip files.
But when i try to add any of the above dll's as a reference to my project in Visual Studio 2005 i get the ERROR: Reference could not be added. Please make sure that the file is accessible and that it is a valid assembly or COM object.
Can anybody help me ???
================================
Thanks();
|
|
|
|
|
You cannot add them as references because they are written in unmanaged code, so you need to import the methods from those libraries using the DllImport attribute.
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Thanks a lot.
But I think by using System.IO.Compression the same functionality of Dunzip32.dll can be achieved.
================================
Wirth's law: Software gets slower faster than hardware gets faster.
|
|
|
|
|
JSSUML wrote: Can anybody help me ???
Instead of trying to use these DLLs directly. Why not have a look in the System.IO.Compression[^] namespace for managed classes that do the same work.
|
|
|
|