using System.Threading;
using System.Text;
using System.Diagnostics;
+using System.Diagnostics.Contracts;
namespace System.Reflection {
}
};
- abstract class RuntimeMethodInfo : MethodInfo
+ abstract class RuntimeMethodInfo : MethodInfo, ISerializable
{
internal BindingFlags BindingFlags {
get {
return 0;
}
}
+
+ RuntimeType ReflectedTypeInternal {
+ get {
+ return (RuntimeType) ReflectedType;
+ }
+ }
+
+ internal override string FormatNameAndSig (bool serialization)
+ {
+ // Serialization uses ToString to resolve MethodInfo overloads.
+ StringBuilder sbName = new StringBuilder(Name);
+
+ // serialization == true: use unambiguous (except for assembly name) type names to distinguish between overloads.
+ // serialization == false: use basic format to maintain backward compatibility of MethodInfo.ToString().
+ TypeNameFormatFlags format = serialization ? TypeNameFormatFlags.FormatSerialization : TypeNameFormatFlags.FormatBasic;
+
+ if (IsGenericMethod)
+ sbName.Append(RuntimeMethodHandle.ConstructInstantiation(this, format));
+
+ sbName.Append("(");
+ ParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention, serialization);
+ sbName.Append(")");
+
+ return sbName.ToString();
+ }
+
+ public override String ToString()
+ {
+ return ReturnType.FormatTypeName() + " " + FormatNameAndSig(false);
+ }
+
+ #region ISerializable Implementation
+ public void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ if (info == null)
+ throw new ArgumentNullException("info");
+ Contract.EndContractBlock();
+
+ MemberInfoSerializationHolder.GetSerializationInfo(
+ info,
+ Name,
+ ReflectedTypeInternal,
+ ToString(),
+ SerializationToString(),
+ MemberTypes.Method,
+ IsGenericMethod & !IsGenericMethodDefinition ? GetGenericArguments() : null);
+ }
+
+ internal string SerializationToString()
+ {
+ return ReturnType.FormatTypeName(true) + " " + FormatNameAndSig(true);
+ }
+ #endregion
}
/*
*/
[Serializable()]
[StructLayout (LayoutKind.Sequential)]
- internal class MonoMethod : RuntimeMethodInfo, ISerializable
+ internal class MonoMethod : RuntimeMethodInfo
{
#pragma warning disable 649
internal IntPtr mhandle;
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern DllImportAttribute GetDllImportAttribute (IntPtr mhandle);
+ internal extern void GetPInvoke (out PInvokeAttributes flags, out string entryPoint, out string dllName);
internal object[] GetPseudoCustomAttributes ()
{
if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
attrs [count ++] = new PreserveSigAttribute ();
if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) {
- DllImportAttribute attr = GetDllImportAttribute (mhandle);
- if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
- attr.PreserveSig = true;
- attrs [count ++] = attr;
+ attrs [count ++] = DllImportAttribute.GetCustomAttribute (this);
}
return attrs;
}
- public override string ToString () {
- StringBuilder sb = new StringBuilder ();
- Type retType = ReturnType;
- if (Type.ShouldPrintFullName (retType))
- sb.Append (retType.ToString ());
- else
- sb.Append (retType.Name);
- sb.Append (" ");
- sb.Append (Name);
- if (IsGenericMethod) {
- Type[] gen_params = GetGenericArguments ();
- sb.Append ("[");
- for (int j = 0; j < gen_params.Length; j++) {
- if (j > 0)
- sb.Append (",");
- sb.Append (gen_params [j].Name);
- }
- sb.Append ("]");
- }
- sb.Append ("(");
-
- var p = GetParametersInternal ();
- ParameterInfo.FormatParameters (sb, p);
-
- if ((CallingConvention & CallingConventions.VarArgs) != 0) {
- if (p.Length > 0)
- sb.Append (", ");
- sb.Append ("...");
- }
-
- sb.Append (")");
- return sb.ToString ();
- }
-
-
- // ISerializable
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- Type[] genericArguments = IsGenericMethod && !IsGenericMethodDefinition
- ? GetGenericArguments () : null;
- MemberInfoSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Method, genericArguments);
- }
-
public override MethodInfo MakeGenericMethod (Type [] methodInstantiation)
{
if (methodInstantiation == null)
public override IList<CustomAttributeData> GetCustomAttributesData () {
return CustomAttributeData.GetCustomAttributes (this);
}
+
+ //seclevel { transparent = 0, safe-critical = 1, critical = 2}
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ public extern int get_core_clr_security_level ();
+
+ public override bool IsSecurityTransparent {
+ get { return get_core_clr_security_level () == 0; }
+ }
+
+ public override bool IsSecurityCritical {
+ get { return get_core_clr_security_level () > 0; }
+ }
+
+ public override bool IsSecuritySafeCritical {
+ get { return get_core_clr_security_level () == 1; }
+ }
}
- abstract class RuntimeConstructorInfo : ConstructorInfo
+ abstract class RuntimeConstructorInfo : ConstructorInfo, ISerializable
{
+ public override Module Module {
+ get {
+ return GetRuntimeModule ();
+ }
+ }
+
+ internal RuntimeModule GetRuntimeModule ()
+ {
+ return RuntimeTypeHandle.GetModule((RuntimeType)DeclaringType);
+ }
+
internal BindingFlags BindingFlags {
get {
return 0;
}
}
+
+ RuntimeType ReflectedTypeInternal {
+ get {
+ return (RuntimeType) ReflectedType;
+ }
+ }
+
+ #region ISerializable Implementation
+ public void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ if (info == null)
+ throw new ArgumentNullException("info");
+ Contract.EndContractBlock();
+ MemberInfoSerializationHolder.GetSerializationInfo(
+ info,
+ Name,
+ ReflectedTypeInternal,
+ ToString(),
+ SerializationToString(),
+ MemberTypes.Constructor,
+ null);
+ }
+
+ internal string SerializationToString()
+ {
+ // We don't need the return type for constructors.
+ return FormatNameAndSig(true);
+ }
+
+ internal void SerializationInvoke (Object target, SerializationInfo info, StreamingContext context)
+ {
+ Invoke (target, new object[] { info, context });
+ }
+ #endregion
}
[Serializable()]
[StructLayout (LayoutKind.Sequential)]
- internal class MonoCMethod : RuntimeConstructorInfo, ISerializable
+ internal class MonoCMethod : RuntimeConstructorInfo
{
#pragma warning disable 649
internal IntPtr mhandle;
return sb.ToString ();
}
- // ISerializable
- public void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- MemberInfoSerializationHolder.Serialize ( info, Name, ReflectedType, ToString(), MemberTypes.Constructor);
- }
-
public override IList<CustomAttributeData> GetCustomAttributesData () {
return CustomAttributeData.GetCustomAttributes (this);
}