Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@@ -111,7 +111,7 @@ namespace System.Reflection {
private string assemblyName;
protected
Assembly ()
Assembly ()
{
resolve_event_holder = new ResolveEventHolder ();
}
@@ -346,6 +346,7 @@ namespace System.Reflection {
}
}
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public virtual Stream GetManifestResourceStream (Type type, String name)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
@@ -467,13 +468,12 @@ namespace System.Reflection {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern Assembly GetEntryAssembly();
internal Assembly GetSatelliteAssembly (CultureInfo culture, Version version, bool throwOnError)
internal Assembly GetSatelliteAssembly (CultureInfo culture, Version version, bool throwOnError, ref StackCrawlMark stackMark)
{
if (culture == null)
throw new ArgumentNullException("culture");
Contract.EndContractBlock();
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
String name = GetSimpleName() + ".resources";
return InternalGetSatelliteAssembly(name, culture, version, true, ref stackMark);
}
@@ -496,7 +496,7 @@ namespace System.Reflection {
Assembly assembly;
try {
assembly = AppDomain.CurrentDomain.LoadSatellite (an, false);
assembly = AppDomain.CurrentDomain.LoadSatellite (an, false, ref stackMark);
if (assembly != null)
return (RuntimeAssembly)assembly;
} catch (FileNotFoundException) {
@@ -512,7 +512,7 @@ namespace System.Reflection {
string fullName = Path.Combine (location, Path.Combine (culture.Name, an.Name + ".dll"));
try {
return (RuntimeAssembly)LoadFrom (fullName);
return (RuntimeAssembly)LoadFrom (fullName, false, ref stackMark);
} catch {
if (!throwOnFileNotFound && !File.Exists (fullName))
return null;
@@ -529,20 +529,24 @@ namespace System.Reflection {
#endif
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static Assembly LoadFrom (String assemblyFile, bool refonly);
private extern static Assembly LoadFrom (String assemblyFile, bool refOnly, ref StackCrawlMark stackMark);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static Assembly LoadFile_internal (String assemblyFile);
private extern static Assembly LoadFile_internal (String assemblyFile, ref StackCrawlMark stackMark);
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public static Assembly LoadFrom (String assemblyFile)
{
return LoadFrom (assemblyFile, false);
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return LoadFrom (assemblyFile, false, ref stackMark);
}
[Obsolete]
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public static Assembly LoadFrom (String assemblyFile, Evidence securityEvidence)
{
Assembly a = LoadFrom (assemblyFile, false);
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
Assembly a = LoadFrom (assemblyFile, false, ref stackMark);
#if !MOBILE
if ((a != null) && (securityEvidence != null)) {
// merge evidence (i.e. replace defaults with provided evidences)
@@ -566,19 +570,23 @@ namespace System.Reflection {
throw new NotImplementedException ();
}
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public static Assembly UnsafeLoadFrom (String assemblyFile)
{
return LoadFrom (assemblyFile);
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return LoadFrom (assemblyFile, false, ref stackMark);
}
[Obsolete]
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public static Assembly LoadFile (String path, Evidence securityEvidence)
{
if (path == null)
throw new ArgumentNullException ("path");
if (path == String.Empty)
throw new ArgumentException ("Path can't be empty", "path");
Assembly a = LoadFile_internal (path);
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
Assembly a = LoadFile_internal (path, ref stackMark);
if (a != null && securityEvidence != null) {
throw new NotImplementedException ();
}
@@ -640,17 +648,21 @@ namespace System.Reflection {
return AppDomain.CurrentDomain.Load (rawAssembly, null, null, true);
}
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public static Assembly ReflectionOnlyLoad (string assemblyString)
{
return AppDomain.CurrentDomain.Load (assemblyString, null, true);
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return AppDomain.CurrentDomain.Load (assemblyString, null, true, ref stackMark);
}
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public static Assembly ReflectionOnlyLoadFrom (string assemblyFile)
{
if (assemblyFile == null)
throw new ArgumentNullException ("assemblyFile");
return LoadFrom (assemblyFile, true);
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return LoadFrom (assemblyFile, true, ref stackMark);
}
[Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")]

View File

@@ -34,15 +34,15 @@ using System.Globalization;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.IO;
using Mono;
using Mono.Security;
#if !MOBILE && !NETCORE
using Mono.Security.Cryptography;
#endif
namespace System.Reflection {
@@ -51,12 +51,14 @@ namespace System.Reflection {
// http://www.ietf.org/rfc/rfc2396.txt
[ComVisible (true)]
#if !NETCORE
[ComDefaultInterfaceAttribute (typeof (_AssemblyName))]
[Serializable]
[ClassInterfaceAttribute (ClassInterfaceType.None)]
#endif
[Serializable]
[StructLayout (LayoutKind.Sequential)]
#if MOBILE
public sealed class AssemblyName : ICloneable, ISerializable, IDeserializationCallback {
#if MOBILE || NETCORE
public sealed partial class AssemblyName : ICloneable, ISerializable, IDeserializationCallback {
#else
public sealed class AssemblyName : ICloneable, ISerializable, IDeserializationCallback, _AssemblyName {
#endif
@@ -110,7 +112,6 @@ namespace System.Reflection {
}
}
[MonoLimitation ("Not used, as the values are too limited; Mono supports more")]
public ProcessorArchitecture ProcessorArchitecture {
get {
return processor_architecture;
@@ -149,7 +150,12 @@ namespace System.Reflection {
get {
if (codebase == null)
return null;
return Uri.EscapeString (codebase, false, true, true);
#if NETCORE
throw new NotImplementedException ();
#else
return Mono.Security.Uri.EscapeString (codebase, false, true, true);
#endif
}
}
@@ -277,7 +283,7 @@ namespace System.Reflection {
switch (publicKey [0]) {
case 0x00: // public key inside a header
if (publicKey.Length > 12 && publicKey [12] == 0x06) {
#if MOBILE
#if MOBILE || NETCORE
return true;
#else
try {
@@ -290,7 +296,7 @@ namespace System.Reflection {
}
break;
case 0x06: // public key
#if MOBILE
#if MOBILE || NETCORE
return true;
#else
try {
@@ -363,7 +369,6 @@ namespace System.Reflection {
keyToken = publicKeyToken;
}
[SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
public void GetObjectData (SerializationInfo info, StreamingContext context)
{
if (info == null)
@@ -428,7 +433,7 @@ namespace System.Reflection {
return aname;
}
#if !MOBILE
#if !MOBILE && !NETCORE
void _AssemblyName.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException ();

View File

@@ -55,6 +55,7 @@ namespace System.Reflection {
{
}
// custom-attrs.c:create_custom_attr_data ()
internal CustomAttributeData (ConstructorInfo ctorInfo, Assembly assembly, IntPtr data, uint data_length)
{
this.ctorInfo = ctorInfo;
@@ -88,9 +89,9 @@ namespace System.Reflection {
ResolveArgumentsInternal (ctorInfo, lazyData.assembly, lazyData.data, lazyData.data_length, out ctor_args, out named_args);
this.ctorArgs = Array.AsReadOnly<CustomAttributeTypedArgument>
(ctor_args != null ? UnboxValues<CustomAttributeTypedArgument> (ctor_args) : EmptyArray<CustomAttributeTypedArgument>.Value);
(ctor_args != null ? UnboxValues<CustomAttributeTypedArgument> (ctor_args) : Array.Empty<CustomAttributeTypedArgument>());
this.namedArgs = Array.AsReadOnly<CustomAttributeNamedArgument>
(named_args != null ? UnboxValues<CustomAttributeNamedArgument> (named_args) : EmptyArray<CustomAttributeNamedArgument>.Value);
(named_args != null ? UnboxValues<CustomAttributeNamedArgument> (named_args) : Array.Empty<CustomAttributeNamedArgument>());
lazyData = null;
}

View File

@@ -39,16 +39,14 @@ namespace System.Reflection {
[DebuggerHidden]
[DebuggerStepThrough]
public
virtual
void AddEventHandler (object target, Delegate handler)
public virtual void AddEventHandler (object target, Delegate handler)
{
// this optimization cause problems with full AOT
// see bug https://bugzilla.xamarin.com/show_bug.cgi?id=3682
#if FULL_AOT_RUNTIME
MethodInfo add = GetAddMethod ();
if (add == null)
throw new InvalidOperationException ("Cannot add a handler to an event that doesn't have a visible add method");
throw new InvalidOperationException (SR.InvalidOperation_NoPublicAddMethod);
if (target == null && !add.IsStatic)
throw new TargetException ("Cannot add a handler to a non static event with a null target");
add.Invoke (target, new object [] {handler});
@@ -56,7 +54,8 @@ namespace System.Reflection {
if (cached_add_event == null) {
MethodInfo add = GetAddMethod ();
if (add == null)
throw new InvalidOperationException ("Cannot add a handler to an event that doesn't have a visible add method");
throw new InvalidOperationException (SR.InvalidOperation_NoPublicAddMethod);
if (add.DeclaringType.IsValueType) {
if (target == null && !add.IsStatic)
throw new TargetException ("Cannot add a handler to a non static event with a null target");
@@ -77,6 +76,7 @@ namespace System.Reflection {
// see bug https://bugzilla.xamarin.com/show_bug.cgi?id=3682
// do not revove the above delegate or it's field since it's required by the runtime!
#if !FULL_AOT_RUNTIME
delegate void AddEvent<T, D> (T _this, D dele);
delegate void StaticAddEvent<D> (D dele);
@@ -139,15 +139,8 @@ namespace System.Reflection {
}
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern EventInfo internal_from_handle_type (IntPtr event_handle, IntPtr type_handle);
internal static EventInfo GetEventFromHandle (Mono.RuntimeEventHandle handle)
{
if (handle.Value == IntPtr.Zero)
throw new ArgumentException ("The handle is invalid.");
return internal_from_handle_type (handle.Value, IntPtr.Zero);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern EventInfo internal_from_handle_type (IntPtr event_handle, IntPtr type_handle);
internal static EventInfo GetEventFromHandle (Mono.RuntimeEventHandle handle, RuntimeTypeHandle reflectedType)
{

View File

@@ -35,24 +35,29 @@ using System.Runtime.InteropServices;
namespace System.Reflection {
[ComVisible (true)]
[StructLayout (LayoutKind.Sequential)]
public
class MethodBody {
#pragma warning disable 649
#region Sync with reflection.h
ExceptionHandlingClause[] clauses;
LocalVariableInfo[] locals;
byte[] il;
bool init_locals;
int sig_token;
int max_stack;
#endregion
#pragma warning restore 649
protected
MethodBody () {
}
internal MethodBody (ExceptionHandlingClause[] clauses, LocalVariableInfo[] locals,
byte[] il, bool init_locals, int sig_token, int max_stack) {
this.clauses = clauses;
this.locals = locals;
this.il = il;
this.init_locals = init_locals;
this.sig_token = sig_token;
this.max_stack = max_stack;
}
public
virtual
IList<ExceptionHandlingClause> ExceptionHandlingClauses {

View File

@@ -43,107 +43,17 @@ namespace System.Reflection {
Other
};
[ComVisible (true)]
[ComDefaultInterfaceAttribute (typeof (_Module))]
[Serializable]
[ClassInterfaceAttribute (ClassInterfaceType.None)]
[StructLayout (LayoutKind.Sequential)]
#if MOBILE
public abstract class Module : ISerializable, ICustomAttributeProvider {
#else
public abstract class Module : ISerializable, ICustomAttributeProvider, _Module {
#endif
public static readonly TypeFilter FilterTypeName = new TypeFilter (filter_by_type_name);
public static readonly TypeFilter FilterTypeNameIgnoreCase = new TypeFilter (filter_by_type_name_ignore_case);
#pragma warning disable 649
internal IntPtr _impl; /* a pointer to a MonoImage */
internal Assembly assembly;
internal string fqname;
internal string name;
internal string scopename;
internal bool is_resource;
internal int token;
#pragma warning restore 649
const BindingFlags defaultBindingFlags =
BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
protected
Module () {
}
public ModuleHandle ModuleHandle {
get {
return new ModuleHandle (_impl);
}
}
partial class Module {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern int get_MetadataToken (Module module);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern int GetMDStreamVersion (IntPtr module_handle);
public FieldInfo GetField (string name)
{
return GetField (name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
}
public FieldInfo[] GetFields ()
{
return GetFields (BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
}
public MethodInfo GetMethod (string name)
{
return GetMethodImpl (name, defaultBindingFlags, null, CallingConventions.Any, null, null);
}
public MethodInfo GetMethod (string name, Type[] types)
{
if (types == null)
throw new ArgumentNullException ("types");
return GetMethodImpl (name, defaultBindingFlags, null, CallingConventions.Any, types, null);
}
public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
{
if (types == null)
throw new ArgumentNullException ("types");
return GetMethodImpl (name, bindingAttr, binder, callConvention, types, modifiers);
}
public MethodInfo[] GetMethods ()
{
return GetMethods (BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
}
[SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
{
throw new NotImplementedException ();
}
[ComVisible (true)]
public virtual Type GetType(string className)
{
return GetType (className, false, false);
}
[ComVisible (true)]
public virtual Type GetType(string className, bool ignoreCase)
{
return GetType (className, false, ignoreCase);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern Type[] InternalGetTypes ();
public override string ToString ()
{
return name;
}
internal Guid MvId {
get {
@@ -153,9 +63,9 @@ namespace System.Reflection {
internal Exception resolve_token_exception (int metadataToken, ResolveTokenError error, string tokenType) {
if (error == ResolveTokenError.OutOfRange)
return new ArgumentOutOfRangeException ("metadataToken", String.Format ("Token 0x{0:x} is not valid in the scope of module {1}", metadataToken, name));
return new ArgumentOutOfRangeException ("metadataToken", String.Format ("Token 0x{0:x} is not valid in the scope of module {1}", metadataToken, Name));
else
return new ArgumentException (String.Format ("Token 0x{0:x} is not a valid {1} token in the scope of module {2}", metadataToken, tokenType, name), "metadataToken");
return new ArgumentException (String.Format ("Token 0x{0:x} is not a valid {1} token in the scope of module {2}", metadataToken, tokenType, Name), "metadataToken");
}
internal IntPtr[] ptrs_from_types (Type[] types) {
@@ -172,27 +82,11 @@ namespace System.Reflection {
}
}
public FieldInfo ResolveField (int metadataToken) {
return ResolveField (metadataToken, null, null);
}
public MemberInfo ResolveMember (int metadataToken) {
return ResolveMember (metadataToken, null, null);
}
public MethodBase ResolveMethod (int metadataToken) {
return ResolveMethod (metadataToken, null, null);
}
public Type ResolveType (int metadataToken) {
return ResolveType (metadataToken, null, null);
}
internal static Type MonoDebugger_ResolveType (Module module, int token)
{
ResolveTokenError error;
IntPtr handle = ResolveTypeToken (module._impl, token, null, null, out error);
IntPtr handle = ResolveTypeToken (module.GetImpl (), token, null, null, out error);
if (handle == IntPtr.Zero)
return null;
else
@@ -210,22 +104,6 @@ namespace System.Reflection {
return new Guid (GetGuidInternal ());
}
private static bool filter_by_type_name (Type m, object filterCriteria) {
string s = (string)filterCriteria;
if (s.Length > 0 && s [s.Length - 1] == '*')
return m.Name.StartsWith (s.Substring (0, s.Length - 1), StringComparison.Ordinal);
return m.Name == s;
}
private static bool filter_by_type_name_ignore_case (Type m, object filterCriteria) {
string s = (string)filterCriteria;
if (s.Length > 0 && s [s.Length - 1] == '*')
return m.Name.StartsWith (s.Substring (0, s.Length - 1), StringComparison.OrdinalIgnoreCase);
return string.Compare (m.Name, s, StringComparison.OrdinalIgnoreCase) == 0;
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern IntPtr GetHINSTANCE ();
@@ -256,195 +134,13 @@ namespace System.Reflection {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern void GetPEKind (IntPtr module, out PortableExecutableKinds peKind, out ImageFileMachine machine);
#if !MOBILE
void _Module.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException ();
}
void _Module.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException ();
}
void _Module.GetTypeInfoCount (out uint pcTInfo)
{
throw new NotImplementedException ();
}
void _Module.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams,
IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException ();
}
#endif
public override bool Equals (object o)
{
return o == (object) this;
}
public override int GetHashCode ()
{
return base.GetHashCode ();
}
public static bool operator == (Module left, Module right)
{
if ((object)left == (object)right)
return true;
if ((object)left == null ^ (object)right == null)
return false;
return left.Equals (right);
}
public static bool operator != (Module left, Module right)
{
if ((object)left == (object)right)
return false;
if ((object)left == null ^ (object)right == null)
return true;
return !left.Equals (right);
}
public virtual Assembly Assembly {
get { throw CreateNIE (); }
}
public virtual string Name {
get { throw CreateNIE (); }
}
public virtual string ScopeName {
get { throw CreateNIE (); }
}
public virtual int MDStreamVersion {
get { throw CreateNIE (); }
}
public virtual Guid ModuleVersionId {
get { throw CreateNIE (); }
}
public virtual string FullyQualifiedName {
get { throw CreateNIE (); }
}
public virtual int MetadataToken {
get { throw CreateNIE (); }
}
static Exception CreateNIE ()
{
return new NotImplementedException ("Derived classes must implement it");
}
public virtual bool IsResource()
{
throw CreateNIE ();
}
public virtual Type[] FindTypes(TypeFilter filter, object filterCriteria)
{
throw CreateNIE ();
}
public virtual object[] GetCustomAttributes(bool inherit)
{
throw CreateNIE ();
}
public virtual object[] GetCustomAttributes(Type attributeType, bool inherit)
{
throw CreateNIE ();
}
public virtual IList<CustomAttributeData> GetCustomAttributesData ()
{
throw CreateNIE ();
}
public virtual FieldInfo GetField (string name, BindingFlags bindingAttr)
{
throw CreateNIE ();
}
public virtual FieldInfo[] GetFields (BindingFlags bindingFlags)
{
throw CreateNIE ();
}
protected virtual MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
{
throw CreateNIE ();
}
public virtual MethodInfo[] GetMethods (BindingFlags bindingFlags)
{
throw CreateNIE ();
}
public virtual void GetPEKind (out PortableExecutableKinds peKind, out ImageFileMachine machine)
{
throw CreateNIE ();
}
[ComVisible (true)]
public virtual Type GetType(string className, bool throwOnError, bool ignoreCase)
{
throw CreateNIE ();
}
public virtual bool IsDefined (Type attributeType, bool inherit)
{
throw CreateNIE ();
}
public virtual FieldInfo ResolveField (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments)
{
throw CreateNIE ();
}
public virtual MemberInfo ResolveMember (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments)
{
throw CreateNIE ();
}
public virtual MethodBase ResolveMethod (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments)
{
throw CreateNIE ();
}
public virtual byte[] ResolveSignature (int metadataToken)
{
throw CreateNIE ();
}
public virtual string ResolveString (int metadataToken)
{
throw CreateNIE ();
}
public virtual Type ResolveType (int metadataToken, Type [] genericTypeArguments, Type [] genericMethodArguments)
{
throw CreateNIE ();
}
public virtual X509Certificate GetSignerCertificate ()
{
throw CreateNIE ();
throw NotImplemented.ByDesign;
}
public virtual Type[] GetTypes()
{
throw CreateNIE ();
}
public virtual IEnumerable<CustomAttributeData> CustomAttributes {
get { return GetCustomAttributesData (); }
internal virtual IntPtr GetImpl () {
throw NotImplemented.ByDesign;
}
}
}

View File

@@ -1,5 +1,5 @@
//
// System.Reflection/MonoAssembly.cs
// System.Reflection/RuntimeAssembly.cs
//
// Author:
// Rodrigo Kumpera (rkumpera@novell.com)
@@ -30,6 +30,7 @@ using System;
using System.Collections;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
#if !FULL_AOT_RUNTIME
using System.Reflection.Emit;
#endif
@@ -45,7 +46,11 @@ using Mono;
namespace System.Reflection {
abstract class RuntimeAssembly : Assembly
[ComVisible (true)]
[ComDefaultInterfaceAttribute (typeof (_Assembly))]
[Serializable]
[ClassInterface(ClassInterfaceType.None)]
class RuntimeAssembly : Assembly
{
public override void GetObjectData (SerializationInfo info, StreamingContext context)
{
@@ -166,14 +171,7 @@ namespace System.Reflection {
#endif
return AssemblyName.Create (this, true);
}
}
[ComVisible (true)]
[ComDefaultInterfaceAttribute (typeof (_Assembly))]
[Serializable]
[ClassInterface(ClassInterfaceType.None)]
class MonoAssembly : RuntimeAssembly
{
public
override
Type GetType (string name, bool throwOnError, bool ignoreCase)
@@ -236,18 +234,22 @@ namespace System.Reflection {
return GetModules (getResourceModules);
}
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public
override
Assembly GetSatelliteAssembly (CultureInfo culture)
{
return GetSatelliteAssembly (culture, null, true);
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return GetSatelliteAssembly (culture, null, true, ref stackMark);
}
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
public
override
Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
{
return GetSatelliteAssembly (culture, version, true);
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return GetSatelliteAssembly (culture, version, true, ref stackMark);
}
//FIXME remove GetManifestModule under v4, it's a v2 artifact

View File

@@ -1,5 +1,5 @@
//
// System.Reflection/MonoEvent.cs
// System.Reflection/RuntimeEventInfo.cs
//
// Author:
// Paolo Molaro (lupus@ximian.com)
@@ -49,24 +49,28 @@ namespace System.Reflection {
public MethodInfo raise_method;
public EventAttributes attrs;
public MethodInfo[] other_methods;
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern void get_event_info (MonoEvent ev, out MonoEventInfo info);
internal static MonoEventInfo GetEventInfo (MonoEvent ev)
{
MonoEventInfo mei;
MonoEventInfo.get_event_info (ev, out mei);
return mei;
}
}
abstract class RuntimeEventInfo : EventInfo, ISerializable
[Serializable]
[StructLayout (LayoutKind.Sequential)]
internal sealed class RuntimeEventInfo : EventInfo
#if !NETCORE
, ISerializable
#endif
{
internal BindingFlags BindingFlags {
get {
return 0;
}
#pragma warning disable 169
IntPtr klass;
IntPtr handle;
#pragma warning restore 169
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern void get_event_info (RuntimeEventInfo ev, out MonoEventInfo info);
internal static MonoEventInfo GetEventInfo (RuntimeEventInfo ev)
{
MonoEventInfo mei;
get_event_info (ev, out mei);
return mei;
}
public override Module Module {
@@ -75,6 +79,12 @@ namespace System.Reflection {
}
}
internal BindingFlags BindingFlags {
get {
return GetBindingFlags ();
}
}
internal RuntimeType GetDeclaringTypeInternal ()
{
return (RuntimeType) DeclaringType;
@@ -91,6 +101,7 @@ namespace System.Reflection {
return GetDeclaringTypeInternal ().GetRuntimeModule ();
}
#if !NETCORE
#region ISerializable
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
@@ -106,26 +117,30 @@ namespace System.Reflection {
MemberTypes.Event);
}
#endregion
}
#endif
[Serializable]
[StructLayout (LayoutKind.Sequential)]
internal sealed class MonoEvent: RuntimeEventInfo
{
#pragma warning disable 169
IntPtr klass;
IntPtr handle;
#pragma warning restore 169
internal BindingFlags GetBindingFlags ()
{
MonoEventInfo info = GetEventInfo (this);
public override EventAttributes Attributes {
MethodInfo method = info.add_method;
if (method == null)
method = info.remove_method;
if (method == null)
method = info.raise_method;
return RuntimeType.FilterPreCalculate (method != null && method.IsPublic, GetDeclaringTypeInternal () != ReflectedType , method != null && method.IsStatic);
}
public override EventAttributes Attributes {
get {
return MonoEventInfo.GetEventInfo (this).attrs;
return GetEventInfo (this).attrs;
}
}
public override MethodInfo GetAddMethod (bool nonPublic)
{
MonoEventInfo info = MonoEventInfo.GetEventInfo (this);
MonoEventInfo info = GetEventInfo (this);
if (nonPublic || (info.add_method != null && info.add_method.IsPublic))
return info.add_method;
return null;
@@ -133,7 +148,7 @@ namespace System.Reflection {
public override MethodInfo GetRaiseMethod (bool nonPublic)
{
MonoEventInfo info = MonoEventInfo.GetEventInfo (this);
MonoEventInfo info = GetEventInfo (this);
if (nonPublic || (info.raise_method != null && info.raise_method.IsPublic))
return info.raise_method;
return null;
@@ -141,7 +156,7 @@ namespace System.Reflection {
public override MethodInfo GetRemoveMethod (bool nonPublic)
{
MonoEventInfo info = MonoEventInfo.GetEventInfo (this);
MonoEventInfo info = GetEventInfo (this);
if (nonPublic || (info.remove_method != null && info.remove_method.IsPublic))
return info.remove_method;
return null;
@@ -149,7 +164,7 @@ namespace System.Reflection {
public override MethodInfo[] GetOtherMethods (bool nonPublic)
{
MonoEventInfo info = MonoEventInfo.GetEventInfo (this);
MonoEventInfo info = GetEventInfo (this);
if (nonPublic)
return info.other_methods;
int num_public = 0;
@@ -170,19 +185,19 @@ namespace System.Reflection {
public override Type DeclaringType {
get {
return MonoEventInfo.GetEventInfo (this).declaring_type;
return GetEventInfo (this).declaring_type;
}
}
public override Type ReflectedType {
get {
return MonoEventInfo.GetEventInfo (this).reflected_type;
return GetEventInfo (this).reflected_type;
}
}
public override string Name {
get {
return MonoEventInfo.GetEventInfo (this).name;
return GetEventInfo (this).name;
}
}
@@ -216,9 +231,11 @@ namespace System.Reflection {
}
}
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<MonoEvent> (other);
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeEventInfo> (other);
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int get_metadata_token (MonoEvent monoEvent);
internal static extern int get_metadata_token (RuntimeEventInfo monoEvent);
}
}

View File

@@ -23,7 +23,7 @@
//
//
// System.Reflection/MonoField.cs
// System.Reflection/RuntimeFieldInfo.cs
// The class used to represent Fields from the mono runtime.
//
// Author:
@@ -43,8 +43,27 @@ using System.Diagnostics.Contracts;
namespace System.Reflection {
abstract class RuntimeFieldInfo : FieldInfo, ISerializable
abstract class RtFieldInfo : FieldInfo {
internal abstract object UnsafeGetValue (object obj);
internal abstract void UnsafeSetValue (Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture);
internal abstract void CheckConsistency(Object target);
}
[Serializable]
[StructLayout (LayoutKind.Sequential)]
class RuntimeFieldInfo : RtFieldInfo
#if !NETCORE
, ISerializable
#endif
{
#pragma warning disable 649
internal IntPtr klass;
internal RuntimeFieldHandle fhandle;
string name;
Type type;
FieldAttributes attrs;
#pragma warning restore 649
internal BindingFlags BindingFlags {
get {
return 0;
@@ -73,6 +92,7 @@ namespace System.Reflection {
return GetDeclaringTypeInternal ().GetRuntimeModule ();
}
#if !NETCORE
#region ISerializable Implementation
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
@@ -87,14 +107,12 @@ namespace System.Reflection {
MemberTypes.Field);
}
#endregion
}
#endif
abstract class RtFieldInfo : RuntimeFieldInfo
{
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern object UnsafeGetValue (object obj);
internal override extern object UnsafeGetValue (object obj);
internal void CheckConsistency(Object target)
internal override void CheckConsistency(Object target)
{
// only test instance fields
if ((Attributes & FieldAttributes.Static) != FieldAttributes.Static)
@@ -122,7 +140,7 @@ namespace System.Reflection {
[DebuggerStepThroughAttribute]
[Diagnostics.DebuggerHidden]
internal void UnsafeSetValue (Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
internal override void UnsafeSetValue (Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
{
bool domainInitialized = false;
RuntimeFieldHandle.SetValue (this, obj, value, null, Attributes, null, ref domainInitialized);
@@ -157,16 +175,6 @@ namespace System.Reflection {
return RuntimeFieldHandle.GetValueDirect(this, (RuntimeType)FieldType, &obj, (RuntimeType)DeclaringType);
}
}
}
[Serializable]
[StructLayout (LayoutKind.Sequential)]
internal class MonoField : RtFieldInfo {
internal IntPtr klass;
internal RuntimeFieldHandle fhandle;
string name;
Type type;
FieldAttributes attrs;
public override FieldAttributes Attributes {
get {
@@ -220,8 +228,10 @@ namespace System.Reflection {
return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
}
#if !NETCORE
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal override extern int GetFieldOffset ();
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern object GetValueInternal (object obj);
@@ -273,9 +283,9 @@ namespace System.Reflection {
SetValueInternal (this, obj, val);
}
internal MonoField Clone (string newName)
internal RuntimeFieldInfo Clone (string newName)
{
MonoField field = new MonoField ();
RuntimeFieldInfo field = new RuntimeFieldInfo ();
field.name = newName;
field.type = type;
field.attrs = attrs;
@@ -319,7 +329,9 @@ namespace System.Reflection {
}
#endif
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<MonoField> (other);
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeFieldInfo> (other);
#endif
public override int MetadataToken {
get {
@@ -328,7 +340,7 @@ namespace System.Reflection {
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern int get_metadata_token (MonoField monoField);
internal static extern int get_metadata_token (RuntimeFieldInfo monoField);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
extern Type[] GetTypeModifiers (bool optional);
@@ -338,5 +350,15 @@ namespace System.Reflection {
public override Type[] GetRequiredCustomModifiers () => GetCustomModifiers (false);
private Type[] GetCustomModifiers (bool optional) => GetTypeModifiers (optional) ?? Type.EmptyTypes;
#if NETCORE
internal object[] GetPseudoCustomAttributes () {
throw new NotImplementedException ();
}
internal CustomAttributeData[] GetPseudoCustomAttributesData () {
throw new NotImplementedException ();
}
#endif
}
}

View File

@@ -1,5 +1,5 @@
//
// MonoMethod.cs: The class used to represent methods from the mono runtime.
// RuntimeMethodInfo.cs: The class used to represent methods from the mono runtime.
//
// Authors:
// Paolo Molaro (lupus@ximian.com)
@@ -29,6 +29,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
@@ -42,9 +43,43 @@ using System.Security;
using System.Threading;
using System.Text;
using System.Diagnostics;
using System.Diagnostics.Contracts;
namespace System.Reflection {
#if NETCORE
[Flags()]
internal enum PInvokeAttributes
{
NoMangle = 0x0001,
CharSetMask = 0x0006,
CharSetNotSpec = 0x0000,
CharSetAnsi = 0x0002,
CharSetUnicode = 0x0004,
CharSetAuto = 0x0006,
BestFitUseAssem = 0x0000,
BestFitEnabled = 0x0010,
BestFitDisabled = 0x0020,
BestFitMask = 0x0030,
ThrowOnUnmappableCharUseAssem = 0x0000,
ThrowOnUnmappableCharEnabled = 0x1000,
ThrowOnUnmappableCharDisabled = 0x2000,
ThrowOnUnmappableCharMask = 0x3000,
SupportsLastError = 0x0040,
CallConvMask = 0x0700,
CallConvWinapi = 0x0100,
CallConvCdecl = 0x0200,
CallConvStdcall = 0x0300,
CallConvThiscall = 0x0400,
CallConvFastcall = 0x0500,
MaxValue = 0xFFFF,
}
#endif
internal struct MonoMethodInfo
{
@@ -105,14 +140,29 @@ namespace System.Reflection {
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern MarshalAsAttribute get_retval_marshal (IntPtr handle);
static internal ParameterInfo GetReturnParameterInfo (MonoMethod method)
static internal ParameterInfo GetReturnParameterInfo (RuntimeMethodInfo method)
{
return MonoParameterInfo.New (GetReturnType (method.mhandle), method, get_retval_marshal (method.mhandle));
return RuntimeParameterInfo.New (GetReturnType (method.mhandle), method, get_retval_marshal (method.mhandle));
}
}
abstract class RuntimeMethodInfo : MethodInfo, ISerializable
/*
* Note: most of this class needs to be duplicated for the contructor, since
* the .NET reflection class hierarchy is so broken.
*/
[Serializable()]
[StructLayout (LayoutKind.Sequential)]
class RuntimeMethodInfo : MethodInfo
#if !NETCORE
, ISerializable
#endif
{
#pragma warning disable 649
internal IntPtr mhandle;
string name;
Type reftype;
#pragma warning restore 649
internal BindingFlags BindingFlags {
get {
return 0;
@@ -131,7 +181,11 @@ namespace System.Reflection {
}
}
#if NETCORE
string FormatNameAndSig (bool serialization)
#else
internal override string FormatNameAndSig (bool serialization)
#endif
{
// Serialization uses ToString to resolve MethodInfo overloads.
StringBuilder sbName = new StringBuilder(Name);
@@ -144,7 +198,7 @@ namespace System.Reflection {
sbName.Append(RuntimeMethodHandle.ConstructInstantiation(this, format));
sbName.Append("(");
MonoParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention, serialization);
RuntimeParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention, serialization);
sbName.Append(")");
return sbName.ToString();
@@ -170,12 +224,12 @@ namespace System.Reflection {
return ((RuntimeType)DeclaringType).GetRuntimeModule();
}
#if !NETCORE
#region ISerializable Implementation
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException("info");
Contract.EndContractBlock();
MemberInfoSerializationHolder.GetSerializationInfo(
info,
@@ -192,26 +246,38 @@ namespace System.Reflection {
return ReturnType.FormatTypeName(true) + " " + FormatNameAndSig(true);
}
#endregion
}
#endif
/*
* Note: most of this class needs to be duplicated for the contructor, since
* the .NET reflection class hierarchy is so broken.
*/
[Serializable()]
[StructLayout (LayoutKind.Sequential)]
internal class MonoMethod : RuntimeMethodInfo
{
#pragma warning disable 649
internal IntPtr mhandle;
string name;
Type reftype;
#pragma warning restore 649
internal MonoMethod () {
internal static MethodBase GetMethodFromHandleNoGenericCheck (RuntimeMethodHandle handle)
{
return GetMethodFromHandleInternalType_native (handle.Value, IntPtr.Zero, false);
}
internal MonoMethod (RuntimeMethodHandle mhandle) {
internal static MethodBase GetMethodFromHandleNoGenericCheck (RuntimeMethodHandle handle, RuntimeTypeHandle reflectedType)
{
return GetMethodFromHandleInternalType_native (handle.Value, reflectedType.Value, false);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
[PreserveDependency(".ctor(System.Reflection.ExceptionHandlingClause[],System.Reflection.LocalVariableInfo[],System.Byte[],System.Boolean,System.Int32,System.Int32)", "System.Reflection.MethodBody")]
internal extern static MethodBody GetMethodBodyInternal (IntPtr handle);
internal static MethodBody GetMethodBody (IntPtr handle)
{
return GetMethodBodyInternal (handle);
}
internal static MethodBase GetMethodFromHandleInternalType (IntPtr method_handle, IntPtr type_handle) {
return GetMethodFromHandleInternalType_native (method_handle, type_handle, true);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
extern static MethodBase GetMethodFromHandleInternalType_native (IntPtr method_handle, IntPtr type_handle, bool genericCheck);
internal RuntimeMethodInfo () {
}
internal RuntimeMethodInfo (RuntimeMethodHandle mhandle) {
this.mhandle = mhandle.Value;
}
@@ -219,17 +285,18 @@ namespace System.Reflection {
internal static extern string get_name (MethodBase method);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern MonoMethod get_base_method (MonoMethod method, bool definition);
internal static extern RuntimeMethodInfo get_base_method (RuntimeMethodInfo method, bool definition);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int get_metadata_token (MonoMethod method);
internal static extern int get_metadata_token (RuntimeMethodInfo method);
public override MethodInfo GetBaseDefinition ()
{
return get_base_method (this, true);
}
internal override MethodInfo GetBaseMethod ()
// TODO: Remove, needed only for MonoCustomAttribute
internal MethodInfo GetBaseMethod ()
{
return get_base_method (this, false);
}
@@ -442,7 +509,11 @@ namespace System.Reflection {
if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
attrs [count ++] = new PreserveSigAttribute ();
if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) {
#if NETCORE
throw new NotImplementedException ();
#else
attrs [count ++] = DllImportAttribute.GetCustomAttribute (this);
#endif
}
return attrs;
@@ -577,12 +648,15 @@ namespace System.Reflection {
hasUserType = true;
}
if (hasUserType)
if (hasUserType) {
#if FULL_AOT_RUNTIME
throw new NotSupportedException ("User types are not supported under full aot");
#elif NETCORE
throw new NotImplementedException ();
#else
return new MethodOnTypeBuilderInst (this, methodInstantiation);
#endif
}
MethodInfo ret = MakeGenericMethod_impl (methodInstantiation);
if (ret == null)
@@ -630,7 +704,11 @@ namespace System.Reflection {
}
public override MethodBody GetMethodBody () {
#if NETCORE
throw new NotImplementedException ();
#else
return GetMethodBody (mhandle);
#endif
}
public override IList<CustomAttributeData> GetCustomAttributesData () {
@@ -660,12 +738,21 @@ namespace System.Reflection {
get { return get_core_clr_security_level () == 1; }
}
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<MonoMethod> (other);
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeMethodInfo> (other);
#endif
}
abstract class RuntimeConstructorInfo : ConstructorInfo, ISerializable
[Serializable()]
[StructLayout (LayoutKind.Sequential)]
class RuntimeConstructorInfo : ConstructorInfo, ISerializable
{
#pragma warning disable 649
internal IntPtr mhandle;
string name;
Type reftype;
#pragma warning restore 649
public override Module Module {
get {
return GetRuntimeModule ();
@@ -694,7 +781,9 @@ namespace System.Reflection {
{
if (info == null)
throw new ArgumentNullException("info");
Contract.EndContractBlock();
#if NETCORE
throw new NotImplementedException ();
#else
MemberInfoSerializationHolder.GetSerializationInfo(
info,
Name,
@@ -703,12 +792,17 @@ namespace System.Reflection {
SerializationToString(),
MemberTypes.Constructor,
null);
#endif
}
internal string SerializationToString()
{
#if NETCORE
throw new NotImplementedException ();
#else
// We don't need the return type for constructors.
return FormatNameAndSig(true);
#endif
}
internal void SerializationInvoke (Object target, SerializationInfo info, StreamingContext context)
@@ -716,17 +810,6 @@ namespace System.Reflection {
Invoke (target, new object[] { info, context });
}
#endregion
}
[Serializable()]
[StructLayout (LayoutKind.Sequential)]
internal class MonoCMethod : RuntimeConstructorInfo
{
#pragma warning disable 649
internal IntPtr mhandle;
string name;
Type reftype;
#pragma warning restore 649
public override MethodImplAttributes GetMethodImplementationFlags ()
{
@@ -777,7 +860,7 @@ namespace System.Reflection {
ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo (mhandle, this);
MonoMethod.ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
RuntimeMethodInfo.ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
if (obj == null && DeclaringType.ContainsGenericParameters)
throw new MemberAccessException ("Cannot create an instance of " + DeclaringType + " because Type.ContainsGenericParameters is true.");
@@ -861,7 +944,7 @@ namespace System.Reflection {
get {
if (name != null)
return name;
return MonoMethod.get_name (this);
return RuntimeMethodInfo.get_name (this);
}
}
@@ -878,24 +961,15 @@ namespace System.Reflection {
}
public override MethodBody GetMethodBody () {
return GetMethodBody (mhandle);
return RuntimeMethodInfo.GetMethodBody (mhandle);
}
public override string ToString () {
StringBuilder sb = new StringBuilder ();
sb.Append ("Void ");
sb.Append (Name);
sb.Append ("(");
ParameterInfo[] p = GetParameters ();
for (int i = 0; i < p.Length; ++i) {
if (i > 0)
sb.Append (", ");
sb.Append (p[i].ParameterType.Name);
}
if (CallingConvention == CallingConventions.Any)
sb.Append (", ...");
sb.Append (")");
return sb.ToString ();
#if NETCORE
throw new NotImplementedException ();
#else
return "Void " + FormatNameAndSig (false);
#endif
}
public override IList<CustomAttributeData> GetCustomAttributesData () {
@@ -912,7 +986,9 @@ namespace System.Reflection {
public extern int get_core_clr_security_level ();
#endif
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<MonoCMethod> (other);
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeConstructorInfo> (other);
#endif
public override bool IsSecurityTransparent {
get { return get_core_clr_security_level () == 0; }
@@ -933,6 +1009,6 @@ namespace System.Reflection {
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern int get_metadata_token (MonoCMethod method);
internal static extern int get_metadata_token (RuntimeConstructorInfo method);
}
}

View File

@@ -1,5 +1,5 @@
//
// System.Reflection/MonoModule.cs
// System.Reflection/RuntimeModule.cs
//
// Author:
// Rodrigo Kumpera (rkumpera@novell.com)
@@ -38,17 +38,27 @@ using System.Runtime.Serialization;
namespace System.Reflection {
abstract class RuntimeModule : Module
{
}
[ComVisible (true)]
[ComDefaultInterfaceAttribute (typeof (_Module))]
[Serializable]
[ClassInterface(ClassInterfaceType.None)]
class MonoModule : RuntimeModule
[StructLayout (LayoutKind.Sequential)]
class RuntimeModule : Module
{
#pragma warning disable 649
#region Sync with object-internals.h
#region Sync with ModuleBuilder
internal IntPtr _impl; /* a pointer to a MonoImage */
internal Assembly assembly;
internal string fqname;
internal string name;
internal string scopename;
internal bool is_resource;
internal int token;
#endregion
#endregion
#pragma warning restore 649
public
override
Assembly Assembly {
@@ -181,6 +191,8 @@ namespace System.Reflection {
return (globalType != null) ? globalType.GetMethods (bindingFlags) : new MethodInfo [0];
}
internal override ModuleHandle GetModuleHandleImpl() => new ModuleHandle (_impl);
public override
void GetPEKind (out PortableExecutableKinds peKind, out ImageFileMachine machine) {
ModuleHandle.GetPEKind (out peKind, out machine);
@@ -236,7 +248,7 @@ namespace System.Reflection {
if (handle == IntPtr.Zero)
throw resolve_token_exception (metadataToken, error, "MethodBase");
else
return MethodBase.GetMethodFromHandleNoGenericCheck (new RuntimeMethodHandle (handle));
return RuntimeMethodInfo.GetMethodFromHandleNoGenericCheck (new RuntimeMethodHandle (handle));
}
public
@@ -312,5 +324,9 @@ namespace System.Reflection {
{
return (RuntimeAssembly)assembly;
}
internal override IntPtr GetImpl () {
return _impl;
}
}
}

View File

@@ -1,4 +1,4 @@
// System.Reflection.ParameterInfo
// System.Reflection.RuntimeParameterInfo
//
// Authors:
// Sean MacIsaac (macisaac@ximian.com)
@@ -28,7 +28,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !FULL_AOT_RUNTIME
#if MONO_FEATURE_SRE
using System.Reflection.Emit;
#endif
using System.Runtime.CompilerServices;
@@ -38,21 +38,21 @@ using System.Text;
namespace System.Reflection
{
abstract class RuntimeParameterInfo : ParameterInfo
{
}
#if !NETCORE
[ComVisible (true)]
[ComDefaultInterfaceAttribute (typeof (_ParameterInfo))]
[Serializable]
[ClassInterfaceAttribute (ClassInterfaceType.None)]
#endif
[StructLayout (LayoutKind.Sequential)]
class MonoParameterInfo : RuntimeParameterInfo {
class RuntimeParameterInfo : ParameterInfo {
internal MarshalAsAttribute marshalAs;
internal static void FormatParameters (StringBuilder sb, ParameterInfo[] p, CallingConventions callingConvention, bool serialization)
{
#if NETCORE
throw new NotImplementedException ();
#else
for (int i = 0; i < p.Length; ++i) {
if (i > 0)
sb.Append (", ");
@@ -77,10 +77,11 @@ namespace System.Reflection
sb.Append (", ");
sb.Append ("...");
}
#endif
}
#if !FULL_AOT_RUNTIME
internal MonoParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
#if MONO_FEATURE_SRE
internal RuntimeParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
this.ClassImpl = type;
this.MemberImpl = member;
if (pb != null) {
@@ -93,10 +94,15 @@ namespace System.Reflection
this.AttrsImpl = ParameterAttributes.None;
}
}
internal static ParameterInfo New (ParameterBuilder pb, Type type, MemberInfo member, int position)
{
return new RuntimeParameterInfo (pb, type, member, position);
}
#endif
/*FIXME this constructor looks very broken in the position parameter*/
internal MonoParameterInfo (ParameterInfo pinfo, Type type, MemberInfo member, int position) {
internal RuntimeParameterInfo (ParameterInfo pinfo, Type type, MemberInfo member, int position) {
this.ClassImpl = type;
this.MemberImpl = member;
if (pinfo != null) {
@@ -110,7 +116,7 @@ namespace System.Reflection
}
}
internal MonoParameterInfo (ParameterInfo pinfo, MemberInfo member) {
internal RuntimeParameterInfo (ParameterInfo pinfo, MemberInfo member) {
this.ClassImpl = pinfo.ParameterType;
this.MemberImpl = member;
this.NameImpl = pinfo.Name;
@@ -120,10 +126,10 @@ namespace System.Reflection
}
/* to build a ParameterInfo for the return type of a method */
internal MonoParameterInfo (Type type, MemberInfo member, MarshalAsAttribute marshalAs) {
internal RuntimeParameterInfo (Type type, MemberInfo member, MarshalAsAttribute marshalAs) {
this.ClassImpl = type;
this.MemberImpl = member;
this.NameImpl = "";
this.NameImpl = null;
this.PositionImpl = -1; // since parameter positions are zero-based, return type pos is -1
this.AttrsImpl = ParameterAttributes.Retval;
this.marshalAs = marshalAs;
@@ -150,6 +156,8 @@ namespace System.Reflection
public override
object RawDefaultValue {
get {
if (DefaultValue != null && DefaultValue.GetType ().IsEnum)
return ((Enum)DefaultValue).GetValue ();
/*FIXME right now DefaultValue doesn't throw for reflection-only assemblies. Change this once the former is fixed.*/
return DefaultValue;
}
@@ -207,14 +215,7 @@ namespace System.Reflection
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern int GetMetadataToken ();
public
override
Type[] GetOptionalCustomModifiers () {
Type[] types = GetTypeModifiers (true);
if (types == null)
return Type.EmptyTypes;
return types;
}
public override Type[] GetOptionalCustomModifiers () => GetCustomModifiers (true);
internal object[] GetPseudoCustomAttributes ()
{
@@ -241,8 +242,13 @@ namespace System.Reflection
if (IsOptional)
attrs [count ++] = new OptionalAttribute ();
if (marshalAs != null)
if (marshalAs != null) {
#if NETCORE
throw new NotImplementedException ();
#else
attrs [count ++] = marshalAs.Copy ();
#endif
}
return attrs;
}
@@ -282,14 +288,7 @@ namespace System.Reflection
return attrsData;
}
public
override
Type[] GetRequiredCustomModifiers () {
Type[] types = GetTypeModifiers (false);
if (types == null)
return Type.EmptyTypes;
return types;
}
public override Type[] GetRequiredCustomModifiers () => GetCustomModifiers (false);
public override bool HasDefaultValue {
get {
@@ -307,26 +306,21 @@ namespace System.Reflection
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern Type[] GetTypeModifiers (bool optional);
#if !FULL_AOT_RUNTIME
internal static ParameterInfo New (ParameterBuilder pb, Type type, MemberInfo member, int position)
{
return new MonoParameterInfo (pb, type, member, position);
}
#endif
internal static ParameterInfo New (ParameterInfo pinfo, Type type, MemberInfo member, int position)
{
return new MonoParameterInfo (pinfo, type, member, position);
return new RuntimeParameterInfo (pinfo, type, member, position);
}
internal static ParameterInfo New (ParameterInfo pinfo, MemberInfo member)
{
return new MonoParameterInfo (pinfo, member);
return new RuntimeParameterInfo (pinfo, member);
}
internal static ParameterInfo New (Type type, MemberInfo member, MarshalAsAttribute marshalAs)
{
return new MonoParameterInfo (type, member, marshalAs);
}
return new RuntimeParameterInfo (type, member, marshalAs);
}
private Type[] GetCustomModifiers (bool optional) => GetTypeModifiers (optional) ?? Type.EmptyTypes;
}
}

View File

@@ -1,5 +1,5 @@
//
// MonoProperty.cs: The class used to represent Properties from the mono runtime.
// RuntimePropertyInfo.cs: The class used to represent Properties from the mono runtime.
//
// Authors:
// Paolo Molaro (lupus@ximian.com)
@@ -38,6 +38,7 @@ using System.Runtime.Serialization;
using System.Security;
using System.Text;
using System.Diagnostics.Contracts;
using Mono;
namespace System.Reflection {
@@ -48,16 +49,6 @@ namespace System.Reflection {
public MethodInfo get_method;
public MethodInfo set_method;
public PropertyAttributes attrs;
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void get_property_info (MonoProperty prop, ref MonoPropertyInfo info,
PInfo req_info);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern Type[] GetTypeModifiers (MonoProperty prop, bool optional);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern object get_default_value (MonoProperty prop);
}
[Flags]
@@ -74,8 +65,31 @@ namespace System.Reflection {
internal delegate object GetterAdapter (object _this);
internal delegate R Getter<T,R> (T _this);
abstract class RuntimePropertyInfo : PropertyInfo, ISerializable
[Serializable]
[StructLayout (LayoutKind.Sequential)]
internal class RuntimePropertyInfo : PropertyInfo
#if !NETCORE
, ISerializable
#endif
{
#pragma warning disable 649
internal IntPtr klass;
internal IntPtr prop;
MonoPropertyInfo info;
PInfo cached;
GetterAdapter cached_getter;
#pragma warning restore 649
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void get_property_info (RuntimePropertyInfo prop, ref MonoPropertyInfo info,
PInfo req_info);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern Type[] GetTypeModifiers (RuntimePropertyInfo prop, bool optional);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern object get_default_value (RuntimePropertyInfo prop);
internal BindingFlags BindingFlags {
get {
return 0;
@@ -112,6 +126,9 @@ namespace System.Reflection {
private string FormatNameAndSig(bool serialization)
{
#if NETCORE
throw new NotImplementedException ();
#else
StringBuilder sbName = new StringBuilder(PropertyType.FormatTypeName(serialization));
sbName.Append(" ");
@@ -120,14 +137,16 @@ namespace System.Reflection {
var pi = GetIndexParameters ();
if (pi.Length > 0) {
sbName.Append (" [");
MonoParameterInfo.FormatParameters (sbName, pi, 0, serialization);
RuntimeParameterInfo.FormatParameters (sbName, pi, 0, serialization);
sbName.Append ("]");
}
return sbName.ToString();
#endif
}
#endregion
#if !NETCORE
#region ISerializable Implementation
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
@@ -150,24 +169,12 @@ namespace System.Reflection {
return FormatNameAndSig(true);
}
#endregion
}
[Serializable]
[StructLayout (LayoutKind.Sequential)]
internal class MonoProperty : RuntimePropertyInfo {
#pragma warning disable 649
internal IntPtr klass;
internal IntPtr prop;
MonoPropertyInfo info;
PInfo cached;
GetterAdapter cached_getter;
#pragma warning restore 649
#endif
void CachePropertyInfo (PInfo flags)
{
if ((cached & flags) != flags) {
MonoPropertyInfo.get_property_info (this, ref info, flags);
get_property_info (this, ref info, flags);
cached |= flags;
}
}
@@ -274,7 +281,7 @@ namespace System.Reflection {
var dest = new ParameterInfo [length];
for (int i = 0; i < length; ++i) {
dest [i] = MonoParameterInfo.New (src [i], this);
dest [i] = RuntimeParameterInfo.New (src [i], this);
}
return dest;
}
@@ -292,11 +299,11 @@ namespace System.Reflection {
/*TODO verify for attribute based default values, just like ParameterInfo*/
public override object GetConstantValue ()
{
return MonoPropertyInfo.get_default_value (this);
return get_default_value (this);
}
public override object GetRawConstantValue() {
return MonoPropertyInfo.get_default_value (this);
return get_default_value (this);
}
// According to MSDN the inherit parameter is ignored here and
@@ -360,7 +367,7 @@ namespace System.Reflection {
getterType = getterDelegateType.MakeGenericType (typeVector);
getterDelegate = Delegate.CreateDelegate (getterType, method);
adapterFrame = typeof (MonoProperty).GetMethod (frameName, BindingFlags.Static | BindingFlags.NonPublic);
adapterFrame = typeof (RuntimePropertyInfo).GetMethod (frameName, BindingFlags.Static | BindingFlags.NonPublic);
adapterFrame = adapterFrame.MakeGenericMethod (typeVector);
return (GetterAdapter)Delegate.CreateDelegate (typeof (GetterAdapter), getterDelegate, adapterFrame, true);
}
@@ -436,25 +443,19 @@ namespace System.Reflection {
method.Invoke (obj, invokeAttr, binder, parms, culture);
}
public override Type[] GetOptionalCustomModifiers () {
Type[] types = MonoPropertyInfo.GetTypeModifiers (this, true);
if (types == null)
return Type.EmptyTypes;
return types;
}
public override Type[] GetOptionalCustomModifiers () => GetCustomModifiers (true);
public override Type[] GetRequiredCustomModifiers () {
Type[] types = MonoPropertyInfo.GetTypeModifiers (this, false);
if (types == null)
return Type.EmptyTypes;
return types;
}
public override Type[] GetRequiredCustomModifiers () => GetCustomModifiers (false);
private Type[] GetCustomModifiers (bool optional) => GetTypeModifiers (this, optional) ?? Type.EmptyTypes;
public override IList<CustomAttributeData> GetCustomAttributesData () {
return CustomAttributeData.GetCustomAttributes (this);
}
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<MonoProperty> (other);
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimePropertyInfo> (other);
#endif
public override int MetadataToken {
get {
@@ -463,12 +464,12 @@ namespace System.Reflection {
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal static extern int get_metadata_token (MonoProperty monoProperty);
internal static extern int get_metadata_token (RuntimePropertyInfo monoProperty);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern PropertyInfo internal_from_handle_type (IntPtr event_handle, IntPtr type_handle);
internal static PropertyInfo GetPropertyFromHandle (Mono.RuntimePropertyHandle handle, RuntimeTypeHandle reflectedType)
internal static PropertyInfo GetPropertyFromHandle (RuntimePropertyHandle handle, RuntimeTypeHandle reflectedType)
{
if (handle.Value == IntPtr.Zero)
throw new ArgumentException ("The handle is invalid.");