Ejemplo n.º 1
0
        private static void DeserializeCompileAndLoad <T>(string file, Action <T> doAsserts)
        {
            var result = Deserialize(file, doAsserts);

            var xnbStream = new MemoryStream();

#if XNA
            // In MS XNA the ContentCompiler is completely internal, so we need
            // to use just a little reflection to get access to what we need.
            const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
            var ctor          = typeof(ContentCompiler).GetConstructors(flags)[0];
            var compiler      = (ContentCompiler)ctor.Invoke(null);
            var compileMethod = typeof(ContentCompiler).GetMethod("Compile", flags);
            compileMethod.Invoke(compiler, new object[] { xnbStream, result, TargetPlatform.Windows, GraphicsProfile.Reach,
                                                          false, Directory.GetCurrentDirectory(), "referenceRelocationPath" });
#else
            var compiler = new ContentCompiler();
            compiler.Compile(xnbStream, result, TargetPlatform.Windows, GraphicsProfile.Reach,
                             false, "rootDirectory", "referenceRelocationPath");
#endif

            var content = new TestContentManager(xnbStream);
            var loaded  = content.Load <T>("Whatever");

            doAsserts(loaded);
        }
Ejemplo n.º 2
0
 void CompileAndLoadAssets <T>(T data, Action <T> validation)
 {
     foreach (var platform in Platforms)
     {
         foreach (var gfxProfile in GraphicsProfiles)
         {
             foreach (var compress in CompressContents)
             {
                 using (var xnbStream = new MemoryStream())
                 {
                     Compiler.Compile(xnbStream, data, platform, gfxProfile, compress, "", "");
                     using (var content = new TestContentManager(xnbStream))
                     {
                         var result = content.Load <T>("foo");
                         validation(result);
                     }
                 }
             }
         }
     }
 }