Bring the ReflectionImporter to NET_CORE
This commit is contained in:
Родитель
c08c1878f6
Коммит
56511b52da
|
@ -689,7 +689,7 @@ namespace Mono.Cecil.Cil {
|
|||
|
||||
var suffix = GetSymbolNamespace (kind);
|
||||
|
||||
var cecil_name = typeof (SymbolProvider).GetAssembly ().GetName ();
|
||||
var cecil_name = typeof (SymbolProvider).Assembly ().GetName ();
|
||||
|
||||
var name = new SR.AssemblyName {
|
||||
Name = cecil_name.Name + "." + suffix,
|
||||
|
@ -740,7 +740,7 @@ namespace Mono.Cecil.Cil {
|
|||
static string GetSymbolTypeName (SymbolKind kind, string name)
|
||||
{
|
||||
var ns = GetSymbolNamespace (kind);
|
||||
return typeof (SymbolProvider).GetAssembly ().GetName ().Name + "." + ns + "." + kind + name;
|
||||
return typeof (SymbolProvider).Assembly ().GetName ().Name + "." + ns + "." + kind + name;
|
||||
}
|
||||
|
||||
static string GetSymbolNamespace (SymbolKind kind)
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Mono.Cecil {
|
|||
MethodReference ImportReference (MethodReference method, IGenericParameterProvider context);
|
||||
}
|
||||
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
|
||||
public interface IReflectionImporterProvider {
|
||||
IReflectionImporter GetReflectionImporter (ModuleDefinition module);
|
||||
|
@ -126,7 +126,7 @@ namespace Mono.Cecil {
|
|||
}
|
||||
}
|
||||
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
|
||||
public class ReflectionImporter : IReflectionImporter {
|
||||
|
||||
|
@ -159,7 +159,9 @@ namespace Mono.Cecil {
|
|||
{ typeof (float), ElementType.R4 },
|
||||
{ typeof (double), ElementType.R8 },
|
||||
{ typeof (string), ElementType.String },
|
||||
#if !NET_CORE
|
||||
{ typeof (TypedReference), ElementType.TypedByRef },
|
||||
#endif
|
||||
{ typeof (IntPtr), ElementType.I },
|
||||
{ typeof (UIntPtr), ElementType.U },
|
||||
{ typeof (object), ElementType.Object },
|
||||
|
@ -179,8 +181,8 @@ namespace Mono.Cecil {
|
|||
string.Empty,
|
||||
type.Name,
|
||||
module,
|
||||
ImportScope (type.Assembly),
|
||||
type.IsValueType);
|
||||
ImportScope (type.Assembly ()),
|
||||
type.IsValueType ());
|
||||
|
||||
reference.etype = ImportElementType (type);
|
||||
|
||||
|
@ -189,7 +191,7 @@ namespace Mono.Cecil {
|
|||
else
|
||||
reference.Namespace = type.Namespace ?? string.Empty;
|
||||
|
||||
if (type.IsGenericType)
|
||||
if (type.IsGenericType ())
|
||||
ImportGenericParameters (reference, type.GetGenericArguments ());
|
||||
|
||||
return reference;
|
||||
|
@ -197,7 +199,7 @@ namespace Mono.Cecil {
|
|||
|
||||
static bool ImportOpenGenericType (Type type, ImportGenericKind import_kind)
|
||||
{
|
||||
return type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open;
|
||||
return type.IsGenericType () && type.IsGenericTypeDefinition () && import_kind == ImportGenericKind.Open;
|
||||
}
|
||||
|
||||
static bool ImportOpenGenericMethod (SR.MethodBase method, ImportGenericKind import_kind)
|
||||
|
@ -221,7 +223,7 @@ namespace Mono.Cecil {
|
|||
if (type.IsArray)
|
||||
return new ArrayType (ImportType (type.GetElementType (), context), type.GetArrayRank ());
|
||||
|
||||
if (type.IsGenericType)
|
||||
if (type.IsGenericType ())
|
||||
return ImportGenericInstance (type, context);
|
||||
|
||||
if (type.IsGenericParameter)
|
||||
|
@ -235,8 +237,8 @@ namespace Mono.Cecil {
|
|||
if (context.IsEmpty)
|
||||
throw new InvalidOperationException ();
|
||||
|
||||
if (type.DeclaringMethod != null)
|
||||
return context.MethodParameter (NormalizeMethodName (type.DeclaringMethod), type.GenericParameterPosition);
|
||||
if (type.DeclaringMethod () != null)
|
||||
return context.MethodParameter (NormalizeMethodName (type.DeclaringMethod ()), type.GenericParameterPosition);
|
||||
|
||||
if (type.DeclaringType != null)
|
||||
return context.TypeParameter (NormalizeTypeFullName (type.DeclaringType), type.GenericParameterPosition);
|
||||
|
@ -284,7 +286,7 @@ namespace Mono.Cecil {
|
|||
|
||||
static bool IsGenericInstance (Type type)
|
||||
{
|
||||
return type.IsGenericType && !type.IsGenericTypeDefinition;
|
||||
return type.IsGenericType () && !type.IsGenericTypeDefinition ();
|
||||
}
|
||||
|
||||
static ElementType ImportElementType (Type type)
|
||||
|
@ -306,9 +308,11 @@ namespace Mono.Cecil {
|
|||
return scope;
|
||||
|
||||
scope = new AssemblyNameReference (name.Name, name.Version) {
|
||||
Culture = name.CultureInfo.Name,
|
||||
PublicKeyToken = name.GetPublicKeyToken (),
|
||||
#if !NET_CORE
|
||||
Culture = name.CultureInfo.Name,
|
||||
HashAlgorithm = (AssemblyHashAlgorithm) name.HashAlgorithm,
|
||||
#endif
|
||||
};
|
||||
|
||||
module.AssemblyReferences.Add (scope);
|
||||
|
@ -354,7 +358,20 @@ namespace Mono.Cecil {
|
|||
|
||||
static SR.FieldInfo ResolveFieldDefinition (SR.FieldInfo field)
|
||||
{
|
||||
#if NET_CORE
|
||||
throw new NotImplementedException ();
|
||||
#else
|
||||
return field.Module.ResolveField (field.MetadataToken);
|
||||
#endif
|
||||
}
|
||||
|
||||
static SR.MethodBase ResolveMethodDefinition (SR.MethodBase method)
|
||||
{
|
||||
#if NET_CORE
|
||||
throw new NotImplementedException ();
|
||||
#else
|
||||
return method.Module.ResolveMethod (method.MetadataToken);
|
||||
#endif
|
||||
}
|
||||
|
||||
MethodReference ImportMethod (SR.MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
|
||||
|
@ -365,7 +382,7 @@ namespace Mono.Cecil {
|
|||
var declaring_type = ImportType (method.DeclaringType, context);
|
||||
|
||||
if (IsGenericInstance (method.DeclaringType))
|
||||
method = method.Module.ResolveMethod (method.MetadataToken);
|
||||
method = ResolveMethodDefinition (method);
|
||||
|
||||
var reference = new MethodReference {
|
||||
Name = method.Name,
|
||||
|
|
|
@ -33,13 +33,15 @@ namespace Mono.Cecil {
|
|||
internal IMetadataResolver metadata_resolver;
|
||||
#if !READ_ONLY
|
||||
internal IMetadataImporterProvider metadata_importer_provider;
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
internal IReflectionImporterProvider reflection_importer_provider;
|
||||
#endif
|
||||
#endif
|
||||
Stream symbol_stream;
|
||||
ISymbolReaderProvider symbol_reader_provider;
|
||||
#if !PCL
|
||||
bool read_symbols;
|
||||
#endif
|
||||
bool projections;
|
||||
bool in_memory;
|
||||
bool read_write;
|
||||
|
@ -70,7 +72,7 @@ namespace Mono.Cecil {
|
|||
set { metadata_importer_provider = value; }
|
||||
}
|
||||
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
public IReflectionImporterProvider ReflectionImporterProvider {
|
||||
get { return reflection_importer_provider; }
|
||||
set { reflection_importer_provider = value; }
|
||||
|
@ -128,7 +130,7 @@ namespace Mono.Cecil {
|
|||
IMetadataResolver metadata_resolver;
|
||||
#if !READ_ONLY
|
||||
IMetadataImporterProvider metadata_importer_provider;
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
IReflectionImporterProvider reflection_importer_provider;
|
||||
#endif
|
||||
#endif
|
||||
|
@ -169,7 +171,7 @@ namespace Mono.Cecil {
|
|||
set { metadata_importer_provider = value; }
|
||||
}
|
||||
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
public IReflectionImporterProvider ReflectionImporterProvider {
|
||||
get { return reflection_importer_provider; }
|
||||
set { reflection_importer_provider = value; }
|
||||
|
@ -189,7 +191,7 @@ namespace Mono.Cecil {
|
|||
#if !PCL && !NET_CORE
|
||||
return typeof (object).Assembly.ImageRuntimeVersion.ParseRuntime ();
|
||||
#else
|
||||
var corlib_name = AssemblyNameReference.Parse (typeof (object).GetAssembly ().FullName);
|
||||
var corlib_name = AssemblyNameReference.Parse (typeof (object).Assembly ().FullName);
|
||||
var corlib_version = corlib_name.Version;
|
||||
|
||||
switch (corlib_version.Major) {
|
||||
|
@ -281,7 +283,7 @@ namespace Mono.Cecil {
|
|||
MethodDefinition entry_point;
|
||||
|
||||
#if !READ_ONLY
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
internal IReflectionImporter reflection_importer;
|
||||
#endif
|
||||
internal IMetadataImporter metadata_importer;
|
||||
|
@ -382,7 +384,7 @@ namespace Mono.Cecil {
|
|||
}
|
||||
|
||||
#if !READ_ONLY
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
internal IReflectionImporter ReflectionImporter {
|
||||
get {
|
||||
if (reflection_importer == null)
|
||||
|
@ -764,12 +766,7 @@ namespace Mono.Cecil {
|
|||
throw new ArgumentException ();
|
||||
}
|
||||
|
||||
static ImportGenericContext GenericContextFor (IGenericParameterProvider context)
|
||||
{
|
||||
return context != null ? new ImportGenericContext (context) : default (ImportGenericContext);
|
||||
}
|
||||
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
|
||||
[Obsolete ("Use ImportReference", error: false)]
|
||||
public TypeReference Import (Type type)
|
||||
|
@ -1041,7 +1038,7 @@ namespace Mono.Cecil {
|
|||
#if !READ_ONLY
|
||||
if (parameters.MetadataImporterProvider != null)
|
||||
module.metadata_importer = parameters.MetadataImporterProvider.GetMetadataImporter (module);
|
||||
#if !PCL && !NET_CORE
|
||||
#if !PCL
|
||||
if (parameters.ReflectionImporterProvider != null)
|
||||
module.reflection_importer = parameters.ReflectionImporterProvider.GetReflectionImporter (module);
|
||||
#endif
|
||||
|
|
47
Mono/Type.cs
47
Mono/Type.cs
|
@ -79,12 +79,57 @@ namespace Mono {
|
|||
#endif
|
||||
}
|
||||
|
||||
public static Assembly GetAssembly (this Type type)
|
||||
public static Assembly Assembly (this Type type)
|
||||
{
|
||||
#if NET_CORE
|
||||
return type.GetTypeInfo ().Assembly;
|
||||
#else
|
||||
return type.Assembly;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static MethodBase DeclaringMethod (this Type type)
|
||||
{
|
||||
#if NET_CORE
|
||||
return type.GetTypeInfo ().DeclaringMethod;
|
||||
#else
|
||||
return type.DeclaringMethod;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static Type [] GetGenericArguments (this Type type)
|
||||
{
|
||||
#if NET_CORE
|
||||
return type.GetTypeInfo ().GenericTypeArguments;
|
||||
#else
|
||||
return type.GetGenericArguments ();
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool IsGenericType (this Type type)
|
||||
{
|
||||
#if NET_CORE
|
||||
return type.GetTypeInfo ().IsGenericType;
|
||||
#else
|
||||
return type.IsGenericType;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool IsGenericTypeDefinition (this Type type)
|
||||
{
|
||||
#if NET_CORE
|
||||
return type.GetTypeInfo ().IsGenericTypeDefinition;
|
||||
#else
|
||||
return type.IsGenericTypeDefinition;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool IsValueType (this Type type)
|
||||
{
|
||||
#if NET_CORE
|
||||
return type.GetTypeInfo ().IsValueType;
|
||||
#else
|
||||
return type.IsValueType;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче