Commits

Anonymous committed 3abca2e

Added support for TimeSpan

  • Participants
  • Parent commits 6e2f075

Comments (0)

Files changed (6)

File MongoDB.Emitter.Test/ISimpleDocument.cs

         bool? TheBool { get; set; }
         byte[] TheByteArray { get; set; }
         Guid TheGuid { get; set; }
+        TimeSpan TheTimeSpan { get; set; }
 
         ArrayWrapper<string> TheArray { get; set; }
 

File MongoDB.Emitter.Test/MongoDB.Emitter.Test.csproj

       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\MongoDB.Driver.dll</HintPath>
     </Reference>
-    <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+    <Reference Include="nunit.framework, Version=2.5.3.9345, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
     <Reference Include="System" />
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />

File MongoDB.Emitter.Test/SimpleDocument_Sample.cs

         }
 
         #endregion
+
+        #region ISimpleDocument Members
+
+
+        public TimeSpan TheTimeSpan
+        {
+            get
+            {
+                throw new Exception("The method or operation is not implemented.");
+            }
+            set
+            {
+                throw new Exception("The method or operation is not implemented.");
+            }
+        }
+
+        #endregion
     }
 }

File MongoDB.Emitter.Test/TestSanity.cs

             simpleDocument.NamedSimpleDocuments["nsd"].L = 234;
             Assert.AreEqual(234, simpleDocument.NamedSimpleDocuments["nsd"].L);
 
+            simpleDocument.TheTimeSpan = TimeSpan.FromSeconds(3.145169);
+            Assert.AreEqual(TimeSpan.FromSeconds(3.145169), simpleDocument.TheTimeSpan);
         }
 
         [Test]
             simpleDocument.NamedSimpleDocuments["nsd"] = WrapperFactory.New<IAnotherSimpleDocument>();
             simpleDocument.NamedSimpleDocuments["nsd"].L = 234;
 
+            simpleDocument.TheTimeSpan = TimeSpan.FromSeconds(3.145169);
+
             Collection.Insert(simpleDocument.Document);
 
             Document spec = new Document();
 
             Assert.AreEqual(1, simpleDocument.ManySimpleDocuments[0].L);
             Assert.AreEqual(234, simpleDocument.NamedSimpleDocuments["nsd"].L);
+
+            Assert.AreEqual(TimeSpan.FromSeconds(3.145169), simpleDocument.TheTimeSpan);
         }
 
         /* Used to experiment with persisting arrays

File MongoDB.Emitter/WrapperFactory_DefaultConversionDelegates.cs

                     return from.Value;
                 });
 
+            RegisterConversionDelegates<TimeSpan>(
+                delegate(object me, object to)
+                {
+                    return TimeSpan.FromMilliseconds(Convert.ToDouble(to));
+                },
+                delegate(object me, TimeSpan from)
+                {
+                    return from.TotalMilliseconds;
+                });
+
+            RegisterConversionDelegates<TimeSpan?>(
+                delegate(object me, object to)
+                {
+                    if (null == to)
+                        return null;
+
+                    return TimeSpan.FromMilliseconds(Convert.ToDouble(to));
+                },
+                delegate(object me, TimeSpan? from)
+                {
+                    if (null == from)
+                        return null;
+
+                    return from.Value.TotalMilliseconds;
+                });
+
             RegisterConversionDelegates<string>(
                 delegate(object me, object to)
                 {
 byte[]
 Guid / Guid?  (Saved as a UUID)
 Document
-object
+object
+TimeSpan / TimeSpan?  (Note, stored internally as milliseconds)