Xamarin Public Jenkins (auto-signing) 95fdb59ea6 Imported Upstream version 6.6.0.89
Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
2019-09-24 08:53:40 +00:00

31 lines
1.2 KiB
C#

using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Rocks;
using Mono.Documentation;
using Mono.Documentation.Updater.Frameworks;
namespace mdoc.Test
{
public abstract class CecilBaseTest
{
protected TypeDefinition GetTypeDef<T> ()
{
var type = typeof(T);
var path = type.Module.Assembly.Location;
var assemblyResolver = new MDocResolver();
var dependencyPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "..", "..", "..", "..", "external", "Windows");
assemblyResolver.AddSearchDirectory(dependencyPath);
var cachedResolver = new CachedResolver(assemblyResolver);
if (!System.IO.Directory.Exists(dependencyPath))
throw new System.Exception($"The path '{dependencyPath}' doesn't seem to exist ... did project files get moved around?");
var resolver = new MDocMetadataResolver(cachedResolver);
var assembly = AssemblyDefinition.ReadAssembly(path, new ReaderParameters { AssemblyResolver = cachedResolver, MetadataResolver = resolver });
var typeref = assembly.MainModule.GetAllTypes ().FirstOrDefault (t => t.Name == type.Name);
return typeref;
}
}
}