<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.dotnetzone.gr:443/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>.NET Framework</title><link>https://www.dotnetzone.gr:443/cs/forums/14/ShowForum.aspx</link><description>Θέματα για threading, remoting, reflection, exception handling, security, regex κλπ.</description><dc:language>el</dc:language><generator>CommunityServer 2.1 SP3 (Build: 20423.1)</generator><item><title>Απ: XML [Serializable] και [NonSerialized] σε non-binary serialization</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/53099.aspx</link><pubDate>Tue, 18 Aug 2009 01:22:51 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:53099</guid><dc:creator>Τάσκος Γιώργος</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/53099.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=53099</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="http://www.dotnetzone.gr/cs/Themes/default/images/icon-quote.gif"&gt; &lt;strong&gt;nullvoid:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;Για δες το &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributes.xmlignore.aspx"&gt;XmlIgnore&lt;/a&gt;.&lt;br&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;+1&lt;/p&gt;
&lt;p&gt;Την [XmlIgnore] θέλεις γιατί αυτό το Attribute θα επηρεάσει το τι θα γραφεί στο XML αρχείο. Το βάζεις στο&lt;/p&gt;&lt;p&gt;public property φυσικά.&lt;br&gt;&lt;/p&gt;
&lt;p&gt;Το [NonSerialized] είναι για binary serialization....&lt;/p&gt;</description></item><item><title>Απ: XML [Serializable] και [NonSerialized] σε non-binary serialization</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/53087.aspx</link><pubDate>Mon, 17 Aug 2009 22:11:07 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:53087</guid><dc:creator>nullvoid</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/53087.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=53087</wfw:commentRss><description>Για δες το &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlattributes.xmlignore.aspx"&gt;XmlIgnore&lt;/a&gt;.&lt;br&gt;</description></item><item><title>XML [Serializable] και [NonSerialized] σε non-binary serialization</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/53082.aspx</link><pubDate>Mon, 17 Aug 2009 08:20:47 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:53082</guid><dc:creator>sakis_drm</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/53082.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=14&amp;PostID=53082</wfw:commentRss><description>Προσπάθω να αποθηκεύσω ένα αντικείμενο σε xml non-binary αρχείο, του οποίου η κλάση δεν έχει [Serializable] και παραδόξως αποθηκεύεται χωρίς να εμφανίσει exception! Το θέμα μου είναι ότι δεν μπορώ να χρησιμοποιήσω το [NonSerialized] για να κόψω κάποιο property από το να αποθηκευτεί στο xml. Γνωρίζει κανείς κάτι που μου διαφεύγει? Μήπως τα [Serializable] και [NonSerialized] δεν παίζουν σε non-binary serialization? Στο παρακάτω παράδειγμα είναι ενεργοποιημένο το Serializable.&lt;br&gt;&lt;br&gt;&lt;table border="0" cellpadding="0" cellspacing="0" width="100%"&gt;&lt;tr style="vertical-align:top;line-height:normal;"&gt;&lt;td style="width:40px;text-align:right;"&gt;&lt;pre style="margin:0px;padding:2px;font-family:courier new;font-size:11px;color:gray;"&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 &lt;/pre&gt;&lt;/td&gt;&lt;td&gt;&lt;pre style="margin:0px;padding:2px 2px 2px 8px;"&gt;&lt;span style="color:Black;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;&lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;using&lt;/span&gt; System;
&lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;using&lt;/span&gt; System.IO;
&lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;using&lt;/span&gt; System.Xml.Serialization;

&lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;namespace&lt;/span&gt; ConsoleApplication2
{
    &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;class&lt;/span&gt; Program
    {
        &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;void&lt;/span&gt; Main(&lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;string&lt;/span&gt;[] args)
        {
            ToSave to &lt;span style="color:Red;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;=&lt;/span&gt; &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;new&lt;/span&gt; ToSave();
            to.Str1 &lt;span style="color:Red;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;=&lt;/span&gt; &lt;span style="font-family:Courier New;font-size:11px;font-weight:normal;"&gt;"value1"&lt;/span&gt;;
            to.Str2 &lt;span style="color:Red;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;=&lt;/span&gt; &lt;span style="font-family:Courier New;font-size:11px;font-weight:normal;"&gt;"value2"&lt;/span&gt;;
            XmlSerializer s &lt;span style="color:Red;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;=&lt;/span&gt; &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;new&lt;/span&gt; XmlSerializer(&lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;typeof&lt;/span&gt;(ToSave));
            TextWriter w &lt;span style="color:Red;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;=&lt;/span&gt; &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;new&lt;/span&gt; StreamWriter(&lt;span style="font-family:Courier New;font-size:11px;font-weight:normal;"&gt;@"c:\test.xml"&lt;/span&gt;);
            s.Serialize(w, to);
            w.Close();
        }
    }
    
    [Serializable]
    &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;class&lt;/span&gt; ToSave
    {
        &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;private&lt;/span&gt; &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;string&lt;/span&gt; str1;
        &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;string&lt;/span&gt; Str1
        { get { &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;return&lt;/span&gt; str1; } set { str1 &lt;span style="color:Red;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;=&lt;/span&gt; value; } }

        [NonSerialized]
        &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;private&lt;/span&gt; &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;string&lt;/span&gt; str2;
        &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;string&lt;/span&gt; Str2
        { get { &lt;span style="color:Blue;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;return&lt;/span&gt; str2; } set { str2 &lt;span style="color:Red;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;=&lt;/span&gt; value; } }
    }
}&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;Αποτέλεσμα&lt;br&gt;&lt;pre&gt;&lt;span style="color:Black;background-color:Transparent;font-family:Courier New;font-size:11px;font-weight:normal;"&gt;&amp;lt;?xml version=&lt;span style="font-family:Courier New;font-size:11px;font-weight:normal;"&gt;"1.0"&lt;/span&gt; encoding=&lt;span style="font-family:Courier New;font-size:11px;font-weight:normal;"&gt;"utf-8"&lt;/span&gt;?&amp;gt;
&amp;lt;ToSave xmlns:xsi=&lt;span style="font-family:Courier New;font-size:11px;font-weight:normal;"&gt;"http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt; xmlns:xsd=&lt;span style="font-family:Courier New;font-size:11px;font-weight:normal;"&gt;"http://www.w3.org/2001/XMLSchema"&lt;/span&gt;&amp;gt;
  &amp;lt;Str1&amp;gt;value1&amp;lt;/Str1&amp;gt;
  &amp;lt;Str2&amp;gt;value2&amp;lt;/Str2&amp;gt;
&amp;lt;/ToSave&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;</description></item></channel></rss>