|
Hi experts,
imagine a system of connected objects like this one:
public class ClassA
{
private bool _reversed = false;
}
public class ClassB
{
private ClassA _objectA1 = new ClassA();
private ClassA _objectA2 = new ClassA();
private ClassB _previous = null;
private ClassB _next = null;
}
public class ClassBContainer:ICollection<ClassB>
{
private List<ClassB> _innerList = new List<ClassB>();
}
public class Form1:Form
{
private ClassBContainer _devices = new ClassBContainer();
private void BtSave_Click(object sender, EventArgs e)
{
}
private void BtLoad_Click(object sender, EventArgs e)
{
}
} What is best practice to serialize/deserialize such an ICollection?
1. I thought of XMLSerializer. Problem here is non-public data. I would have to create public properties for all private data. That seems like rendering the 'private' keyword useless.
I would also have to hide those public properties from other parts of the code.
What happens to two instances of ClassB pointing at each other in their _previous and _next properties, respectively? Will that create an infinite loop during serialization?
XMLSerializer handles Lists nicely and keeps type information in the serialized form.
2. I thought of BinaryFormatter/SoapFormatter. This resulted in an exception saying that some GUI objects were not marked [Serializable] (The GUI seems connected to business objects through some events it has to react on.)
I could control the behaviour by implementing ISerializable:
GetObjectData(SerializationInfo info, StreamingContext context); and
Constructor(SerializationInfo info, StreamingContext context); for every class involved. How is that done for Lists?
At least the objects pointing at each other seem no problem for SoapFormatter. They are aliased as "ref-3" (number changes for each object) and references use that alias.
Again, is there a best practice approach to serializing object systems like the one mentioned above?
Ciao,
luker
|
|
|
|
|
lukeer wrote: What is best practice to serialize/deserialize such an ICollection?
To use one[^] of the optimized[^] versions on CodeProject[^], as they are faster then the native serializers.
lukeer wrote: 1. I thought of XMLSerializer. Problem here is non-public data. I would have to create public properties for all private data. That seems like rendering the 'private' keyword useless.
From MSDN[^];
XML serialization does not convert methods, indexers, private fields, or read-only
properties (except read-only collections). To serialize all an object's fields and
properties, both public and private, use the BinaryFormatter instead of XML serialization.
lukeer wrote: How is that done for Lists?
Not sure about XML serialization, but should work if you serialize a generic list with ISerializable objects.
lukeer wrote: Again, is there a best practice approach to serializing object systems like the one mentioned above?
Some people prefer XML-serialization because it allows them to manually edit the file. You could also write a small utility to edit binary-serialized objects, if that's a requirement.
I are Troll
|
|
|
|
|
What I need to do is copy some db objects (sp's and udf's mainly) from a db to the same db but into a different schema. I can create a new udf and set it equal to the old udf but if I try to change the schema value I get an error saying that you can't change the schema value on an object that exists. Also, tried to use Memberwise.Clone and that didn't work. Is Microsoft.SqlServer.Management the correct class to use to do this? Is there a easier way? Am I just thick this morning? Any help would be appreciated. Thanks
|
|
|
|
|
giantWoodenBadger wrote: I can create a new udf and set it equal to the old udf but if I try to change the schema value I get an error saying that you can't change the schema value on an object that exists.
Create the schema first, then the objects that go in that schema.
giantWoodenBadger wrote: Is Microsoft.SqlServer.Management the correct class to use to do this?
SMO is a way to do it, exporting the SP's as text, and recreating them in a new schema. As an alternative, I'd go for TSql-scripts using the SP_HELPTEXT[^] procedure.
I are Troll
|
|
|
|
|
|
Look spammer... STOP posting this crap NOW.
|
|
|
|
|
Hi, i need to know the exact meaning of Mock Vrsion. I want to send mock version of the email notification to outlook(eamil).
|
|
|
|
|
|
A mock object is generally used to represent an object that you cannot actually create during unit testing of your program using a unit testing tool. Another link worth looking at here[^]
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
You need to ask the person who is telling you to do this. It makes no sense. With typical Mock objects they are what you use to make sure you can test your software without affecting (or requiring) anything outside of your software (like the database or in your case Outlook). So you would never really send anything to Outlook with a mock object.
Mock objects are like pretend objects. A Mock e-mail class would pretend to be just like a normal e-mail class. It would have a send method that returns the correct value, but doesn't send anything. It would also give you the correct errors if you set the an address to something invalid. For each test, you tell it what to "expect" and what to do in response.
Here is a good article. Understanding Mock Objects[^]
|
|
|
|
|
Sir,
I want to know that can there be an RSS reader as an application of WPF technology?
Waiting for your reply.
Thanks
|
|
|
|
|
Yes you can.
See here[^] or here[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I don't know if any exist, but I would imagine there will be - a search will probably yeild some results.
If not, write your own - it's definitely possible
|
|
|
|
|
Indeed there can, and it's incredibly trivial.
|
|
|
|
|
Sir,
I had tried many codes from web but no one actually did what was intended to do.
I am new to programming and want to creat a web-based RSS Feed reader using C# in visual studio 2010.
Please help me.
Regards.
|
|
|
|
|
I have a winform app that writes a word document template to a database. I'd like to read this back in and insert text at cartain points in the document.
I've been reading the web and it looks like using bookmarks is the way to go. I'm stuck on setting bookmarks, however. My code is below:
object oNull = System.Reflection.Missing.Value;
Word.Range start = para.Range;
object oRng = start;
string newText = "Bookmark1";
Word_doc.Bookmarks.Add(newText, ref oRng);
when I run it the traceback shows:
"...Bad bookmark name."
This is at the line: "Word_doc.Bookmarks.Add(newText, ref oRng);"
2 questions then are:
1) How do I properly set a bookmark in a word doc using interop (automation)?
2) Is there another/better way to be able to insert a table at a certing location in a word doc?
Thanks in advance.
Jboyd
|
|
|
|
|
If you create Word application object, uou can use
Selection.Range
to tell the application: "use current selection" or you should create range object in context:
Sub cxzcxz()
Dim doc As Word.Document
Dim rng As Word.range
Set doc = Documents(1)
Set rng = doc.Paragraphs(1).range
End Sub
How to create bookmark using VBA (Word application)?
Sub test()
Dim oBkm As Word.Bookmark
Set oBkm = AddBookmark("Bookmark1", Selection.Range)
MsgBox oBkm.Name, vbInformation, "Message"
End Sub
Function AddBookmark(ByVal sName As String, ByRef oRange As Word.Range) As Word.Bookmark
Set AddBookmark = oRange.Bookmarks.Add(sName, oRange)
End Function
sorry, for my language
I'm still learning
|
|
|
|
|
Hello everybody. I'm asking for help in learning how to use this new MS product. As a developer of mainly LOB apps, I'm always interested in new ways to avoid the boilerplate code that's common when dealing with data layers. Except that after a few days dealing with EF4 I'm not finding any improvement, it seems to stomp on my feet on every basic real world requirement.
I read about model-first design and I found it a step in the right direction. So I built a simple model:
Customer <-> Order <-> Item
Built the associations and generated the MSSQL database. Nice!
Oops, it creates all fields as varchars. Right, I didn't tell him that the field OrderDate is a Date, so I change that and regenerate the script. Mmm? Drop table? I have to generate the ALTERs by hand?
Google and find the (beta) tools[^] to update my database automatically. This works, though I have to admit I only tried simple changes.
Fire up some tutorials. Learn about the different related windows in VS2010. Next lesson: entity splitting. I follow the tutorials and try to create a separate CustomerAddress entity, which I later merge into Customer. Seems to work, save and generate the DB scripts: the CustomerAddress entity is gone from the DB and the fields are merged into Customer, even without using the ALTER script power pack. WTF?
Ok, maybe entity splitting isn't so useful in real life, I can live with two separate entities and manual joins. Let's get back to studying the model. I see that by default it generates properties for the entity keys. I don't need them, recreate the entities to delete them (I didn't find any other obvious way). Regenerate the DB.
I notice that the FK columns are generated with a standard name: <ENTITYNAME>_<KEYNAME>, in my case the ugly Customer_CustomerId. I decide to change it into my familiar id_customer, and fail to find a suitable command. The properties window shows the name as readonly, the Mapping Details window doesn't let me specify another name, F2 does not do anything. It's readonly. So I take an axe and drill down into the edmx XML. Find/Replace seems to work, the model now seems ready to kick off a simple application and test queries. I only need to generate the DB... and it reverts my manual changes! Fields name are back to Customer_CustomerId! WTH!?
There must be some missing piece in my head. Am I doing something wrong? Is my VS installation borked? Does it work for you? Anybody took something in production using EF? How do you maintain an app without any machine help? Does it save even a minute over hand-crafted ADO.net data layers?
Thanks
Luca
The Price of Freedom is Eternal Vigilance. -- Wing Commander IV
En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur.
(But the best thing God has created, is a New Day.)
-- Sigur Ròs - Viðrar vel til loftárása
modified on Monday, October 18, 2010 6:56 PM
|
|
|
|
|
I have a TCPListener object. TcpClient connects with it. Client sends data to it. It read data from networkstream by using GetStream() method of tcpclient. If I will call GetStream() method 2 times with same object then will it return same stream or different stream? Should I use ref keyword if I want to pass this networkstream or tcpclient?
My actual problem is that I am able to read from client but I am not able to send data to client.
modified on Saturday, October 16, 2010 3:35 AM
|
|
|
|
|
It will always return same Stream; I just completed my testing.
And my problem is also solved now.
|
|
|
|
|
Hi guys, in my project i use typed date set. I store customer image in SQL and I use Grid View to show database informations.But the problem is, size of the grid view row.I want to change the size to view images . Is any one know how to do it?????????
|
|
|
|
|
Change the row height as shown here[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I have Gridview with Label controls. When I click on linkbutton on top of the grid new row with Textbox control to be added to the Gridview. How can I get this.
|
|
|
|
|
Have you tried to find about something what you want in web?
Just type search keyword "asp .net gridview add new row" in google, you will get satisfaction that you done without anybodys' help.
|
|
|
|
|
If I search with the keyword "asp .net gridview add new row" in google, Controls which we design in the Gridview get added but I want to add text box for New row and Labels for existing data. Hope nobody post here with out browsing in the web. Mind your language.
|
|
|
|