SerializeTypes() public method

public SerializeTypes ( IEnumerable types, TextWriter output ) : void
types IEnumerable
output System.IO.TextWriter
return void
Ejemplo n.º 1
0
 internal static void SaveTypesToCache(string cacheName, IList<Type> matchingTypes, IBuildManager buildManager, TypeCacheSerializer serializer) {
     try {
         Stream stream = buildManager.CreateCachedFile(cacheName);
         if (stream != null) {
             using (StreamWriter writer = new StreamWriter(stream)) {
                 serializer.SerializeTypes(matchingTypes, writer);
             }
         }
     }
     catch {
     }
 }
Ejemplo n.º 2
0
 internal static void SaveTypesToCache(string cacheName, IList <Type> matchingTypes, IBuildManager buildManager, TypeCacheSerializer serializer)
 {
     try {
         Stream stream = buildManager.CreateCachedFile(cacheName);
         if (stream != null)
         {
             using (StreamWriter writer = new StreamWriter(stream)) {
                 serializer.SerializeTypes(matchingTypes, writer);
             }
         }
     }
     catch {
     }
 }
        public void SerializeTypes() {
            // Arrange
            DateTime expectedDate = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc); // Jan 1, 2001 midnight UTC
            string expectedFormat = @"<?xml version=""1.0"" encoding=""utf-16""?>
<!--This file is automatically generated. Please do not modify the contents of this file.-->
<typeCache lastModified=""{0}"" mvcVersionId=""{1}"">
  <assembly name=""{2}"">
    <module versionId=""{3}"">
      <type>System.String</type>
      <type>System.Object</type>
    </module>
  </assembly>
</typeCache>";
            string expected = String.Format(expectedFormat,
                expectedDate /* lastModified */,
                GetMvidForType(typeof(TypeCacheSerializer)) /* mvcVersionId */,
                _mscorlibAsmFullName /* assembly.name */,
                GetMvidForType(typeof(object)) /* module.versionId */
                );

            Type[] typesToSerialize = new Type[]{
                typeof(string),
                typeof(object)
            };

            TypeCacheSerializer serializer = new TypeCacheSerializer();
            serializer.CurrentDateOverride = expectedDate;

            StringWriter output = new StringWriter();

            // Act
            serializer.SerializeTypes(typesToSerialize, output);
            string outputString = output.ToString();

            // Assert
            Assert.AreEqual(expected, outputString);
        }