2004-04-30 Ben Maurer <bmaurer@users.sourceforge.net>
[mono.git] / mcs / class / corlib / System.IO / FileSystemInfo.cs
index 80a54a593fc3f4f46d1c28547190400a920a9928..052019c96a7b890b7d83253cb35483abce12c822 100644 (file)
 //------------------------------------------------------------------------------
 
 using System;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
 
 namespace System.IO {
        
        [Serializable]
-       public abstract class FileSystemInfo : MarshalByRefObject {
+       public abstract class FileSystemInfo : MarshalByRefObject, ISerializable {
+               #region Implementation of ISerializable
+
+               [ComVisible(false)]
+               public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
+               {
+                       info.AddValue ("OriginalPath", OriginalPath, typeof(string));
+                       info.AddValue ("FullPath", FullPath, typeof(string));
+               }
+
+               #endregion Implementation of ISerializable
+
                // public properties
 
                public abstract bool Exists { get; }
@@ -47,6 +60,7 @@ namespace System.IO {
                                                               value,
                                                               out error))
                                        throw MonoIO.GetException (error);
+                               Refresh (true);
                        }
                }
 
@@ -64,9 +78,11 @@ namespace System.IO {
                                if (!MonoIO.SetFileTime (FullName, filetime,
                                                         -1, -1, out error))
                                        throw MonoIO.GetException (error);
+                               Refresh (true);
                        }
                }
 
+               [ComVisible(false)]
                public DateTime CreationTimeUtc {
                        get {
                                return CreationTime.ToUniversalTime ();
@@ -92,9 +108,11 @@ namespace System.IO {
                                                         filetime, -1,
                                                         out error))
                                        throw MonoIO.GetException (error);
+                               Refresh (true);
                        }
                }
 
+               [ComVisible(false)]
                public DateTime LastAccessTimeUtc {
                        get {
                                Refresh (false);
@@ -120,9 +138,11 @@ namespace System.IO {
                                if (!MonoIO.SetFileTime (FullName, -1, -1,
                                                         filetime, out error))
                                        throw MonoIO.GetException (error);
+                               Refresh (true);
                        }
                }
 
+               [ComVisible(false)]
                public DateTime LastWriteTimeUtc {
                        get {
                                Refresh (false);
@@ -151,6 +171,17 @@ namespace System.IO {
                        this.FullPath = null;
                }
 
+               protected FileSystemInfo (SerializationInfo info, StreamingContext context)
+               {
+                       if (info == null)
+                       {
+                               throw new ArgumentNullException("info");
+                       }
+
+                       FullPath = info.GetString("FullPath");
+                       OriginalPath = info.GetString("OriginalPath");
+               }
+
                protected string FullPath;
                protected string OriginalPath;
 
@@ -165,6 +196,12 @@ namespace System.IO {
                        
                        MonoIO.GetFileStat (FullName, out stat, out error);
                        valid = true;
+                       
+                       InternalRefresh ();
+               }
+               
+               internal virtual void InternalRefresh ()
+               {
                }
 
                internal void CheckPath (string path)