summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs')
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs165
1 files changed, 40 insertions, 125 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs
index 015a73be09..654e166a05 100644
--- a/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs
+++ b/src/mscorlib/src/System/Reflection/Emit/MethodBuilder.cs
@@ -16,12 +16,12 @@ namespace System.Reflection.Emit
using System.Collections.Generic;
using System.Security.Permissions;
using System.Runtime.InteropServices;
+ using System.Diagnostics;
using System.Diagnostics.Contracts;
- [HostProtection(MayLeakOnAbort = true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_MethodBuilder))]
-[System.Runtime.InteropServices.ComVisible(true)]
+ [System.Runtime.InteropServices.ComVisible(true)]
public sealed class MethodBuilder : MethodInfo, _MethodBuilder
{
#region Private Data Members
@@ -90,16 +90,16 @@ namespace System.Reflection.Emit
ModuleBuilder mod, TypeBuilder type, bool bIsGlobalMethod)
{
if (name == null)
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
if (name.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
+ throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name));
if (name[0] == '\0')
- throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
+ throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), nameof(name));
if (mod == null)
- throw new ArgumentNullException("mod");
+ throw new ArgumentNullException(nameof(mod));
Contract.EndContractBlock();
if (parameterTypes != null)
@@ -107,7 +107,7 @@ namespace System.Reflection.Emit
foreach(Type t in parameterTypes)
{
if (t == null)
- throw new ArgumentNullException("parameterTypes");
+ throw new ArgumentNullException(nameof(parameterTypes));
}
}
@@ -196,14 +196,13 @@ namespace System.Reflection.Emit
m_module.CheckContext(types);
}
- [System.Security.SecurityCritical] // auto-generated
internal void CreateMethodBodyHelper(ILGenerator il)
{
// Sets the IL of the method. An ILGenerator is passed as an argument and the method
// queries this instance to get all of the information which it needs.
if (il == null)
{
- throw new ArgumentNullException("il");
+ throw new ArgumentNullException(nameof(il));
}
Contract.EndContractBlock();
@@ -367,7 +366,7 @@ namespace System.Reflection.Emit
}
else
{
- Contract.Assert(false, "We should never get here!");
+ Debug.Assert(false, "We should never get here!");
return null;
}
}
@@ -389,7 +388,6 @@ namespace System.Reflection.Emit
return m_mdMethodFixups;
}
- [System.Security.SecurityCritical] // auto-generated
internal SignatureHelper GetMethodSignature()
{
if (m_parameterTypes == null)
@@ -480,7 +478,6 @@ namespace System.Reflection.Emit
#endregion
#region Object Overrides
- [System.Security.SecuritySafeCritical] // auto-generated
public override bool Equals(Object obj) {
if (!(obj is MethodBuilder)) {
return false;
@@ -505,7 +502,6 @@ namespace System.Reflection.Emit
return this.m_strName.GetHashCode();
}
- [System.Security.SecuritySafeCritical] // auto-generated
public override String ToString()
{
StringBuilder sb = new StringBuilder(1000);
@@ -599,17 +595,17 @@ namespace System.Reflection.Emit
public override bool IsSecurityCritical
{
- get { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); }
+ get { return true; }
}
public override bool IsSecuritySafeCritical
{
- get { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); }
+ get { return false; }
}
public override bool IsSecurityTransparent
{
- get { throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule")); }
+ get { return false; }
}
#endregion
@@ -693,10 +689,10 @@ namespace System.Reflection.Emit
public GenericTypeParameterBuilder[] DefineGenericParameters (params string[] names)
{
if (names == null)
- throw new ArgumentNullException("names");
+ throw new ArgumentNullException(nameof(names));
if (names.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "names");
+ throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), nameof(names));
Contract.EndContractBlock();
if (m_inst != null)
@@ -704,7 +700,7 @@ namespace System.Reflection.Emit
for (int i = 0; i < names.Length; i ++)
if (names[i] == null)
- throw new ArgumentNullException("names");
+ throw new ArgumentNullException(nameof(names));
if (m_tkMethod.Token != 0)
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_MethodBuilderBaked"));
@@ -721,7 +717,6 @@ namespace System.Reflection.Emit
#endregion
#region Public Members
- [System.Security.SecuritySafeCritical] // auto-generated
public MethodToken GetToken()
{
// We used to always "tokenize" a MethodBuilder when it is constructed. After change list 709498
@@ -767,16 +762,15 @@ namespace System.Reflection.Emit
m_containingType.m_lastTokenizedMethod = i;
}
- Contract.Assert(currentMethod == this, "We should have found this method in m_containingType.m_listMethods");
- Contract.Assert(currentToken.Token != 0, "The token should not be 0");
+ Debug.Assert(currentMethod == this, "We should have found this method in m_containingType.m_listMethods");
+ Debug.Assert(currentToken.Token != 0, "The token should not be 0");
return currentToken;
}
- [System.Security.SecurityCritical] // auto-generated
private MethodToken GetTokenNoLock()
{
- Contract.Assert(m_tkMethod.Token == 0, "m_tkMethod should not have been initialized");
+ Debug.Assert(m_tkMethod.Token == 0, "m_tkMethod should not have been initialized");
int sigLength;
byte[] sigBytes = GetMethodSignature().InternalGetSignature(out sigLength);
@@ -841,7 +835,6 @@ namespace System.Reflection.Emit
}
- [System.Security.SecuritySafeCritical] // auto-generated
public ParameterBuilder DefineParameter(int position, ParameterAttributes attributes, String strParamName)
{
if (position < 0)
@@ -858,7 +851,6 @@ namespace System.Reflection.Emit
return new ParameterBuilder(this, position, attributes, strParamName);
}
- [System.Security.SecuritySafeCritical] // auto-generated
[Obsolete("An alternate API is available: Emit the MarshalAs custom attribute instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
{
@@ -915,55 +907,15 @@ namespace System.Reflection.Emit
m_symCustomAttrs.Add(new SymCustomAttr(name, data));
}
-#if FEATURE_CAS_POLICY
- [System.Security.SecuritySafeCritical] // auto-generated
- public void AddDeclarativeSecurity(SecurityAction action, PermissionSet pset)
- {
- if (pset == null)
- throw new ArgumentNullException("pset");
- Contract.EndContractBlock();
-
- ThrowIfGeneric ();
-
-#pragma warning disable 618
- if (!Enum.IsDefined(typeof(SecurityAction), action) ||
- action == SecurityAction.RequestMinimum ||
- action == SecurityAction.RequestOptional ||
- action == SecurityAction.RequestRefuse)
- {
- throw new ArgumentOutOfRangeException("action");
- }
-#pragma warning restore 618
-
- // cannot declarative security after type is created
- m_containingType.ThrowIfCreated();
-
- // Translate permission set into serialized format (uses standard binary serialization format).
- byte[] blob = null;
- int length = 0;
- if (!pset.IsEmpty())
- {
- blob = pset.EncodeXml();
- length = blob.Length;
- }
-
- // Write the blob into the metadata.
- TypeBuilder.AddDeclarativeSecurity(m_module.GetNativeHandle(), MetadataTokenInternal, action, blob, length);
- }
-#endif // FEATURE_CAS_POLICY
-
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #endif
public void SetMethodBody(byte[] il, int maxStack, byte[] localSignature, IEnumerable<ExceptionHandler> exceptionHandlers, IEnumerable<int> tokenFixups)
{
if (il == null)
{
- throw new ArgumentNullException("il", Environment.GetResourceString("ArgumentNull_Array"));
+ throw new ArgumentNullException(nameof(il), Environment.GetResourceString("ArgumentNull_Array"));
}
if (maxStack < 0)
{
- throw new ArgumentOutOfRangeException("maxStack", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+ throw new ArgumentOutOfRangeException(nameof(maxStack), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
Contract.EndContractBlock();
@@ -1056,9 +1008,6 @@ namespace System.Reflection.Emit
/// <summary>
/// Obsolete.
/// </summary>
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #endif
public void CreateMethodBody(byte[] il, int count)
{
ThrowIfGeneric();
@@ -1075,7 +1024,7 @@ namespace System.Reflection.Emit
if (il != null && (count < 0 || count > il.Length))
{
- throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_Index"));
+ throw new ArgumentOutOfRangeException(nameof(count), Environment.GetResourceString("ArgumentOutOfRange_Index"));
}
if (il == null)
@@ -1095,7 +1044,6 @@ namespace System.Reflection.Emit
m_bIsBaked = true;
}
- [System.Security.SecuritySafeCritical] // auto-generated
public void SetImplementationFlags(MethodImplAttributes attributes)
{
ThrowIfGeneric ();
@@ -1158,7 +1106,6 @@ namespace System.Reflection.Emit
public String Signature
{
- [System.Security.SecuritySafeCritical] // auto-generated
get
{
return GetMethodSignature().ToString();
@@ -1166,18 +1113,13 @@ namespace System.Reflection.Emit
}
-#if FEATURE_CORECLR
-[System.Security.SecurityCritical] // auto-generated
-#else
-[System.Security.SecuritySafeCritical]
-#endif
[System.Runtime.InteropServices.ComVisible(true)]
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
{
if (con == null)
- throw new ArgumentNullException("con");
+ throw new ArgumentNullException(nameof(con));
if (binaryAttribute == null)
- throw new ArgumentNullException("binaryAttribute");
+ throw new ArgumentNullException(nameof(binaryAttribute));
Contract.EndContractBlock();
ThrowIfGeneric();
@@ -1191,11 +1133,10 @@ namespace System.Reflection.Emit
ParseCA(con, binaryAttribute);
}
- [System.Security.SecuritySafeCritical] // auto-generated
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
{
if (customBuilder == null)
- throw new ArgumentNullException("customBuilder");
+ throw new ArgumentNullException(nameof(customBuilder));
Contract.EndContractBlock();
ThrowIfGeneric();
@@ -1239,29 +1180,6 @@ namespace System.Reflection.Emit
internal bool m_isDllImport = false;
#endregion
-
-#if !FEATURE_CORECLR
- void _MethodBuilder.GetTypeInfoCount(out uint pcTInfo)
- {
- throw new NotImplementedException();
- }
-
- void _MethodBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
- {
- throw new NotImplementedException();
- }
-
- void _MethodBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
- {
- throw new NotImplementedException();
- }
-
- void _MethodBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
- {
- throw new NotImplementedException();
- }
-#endif
-
}
internal class LocalSymInfo
@@ -1366,9 +1284,6 @@ namespace System.Reflection.Emit
checked { m_iNameSpaceCount++; }
}
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #endif
internal virtual void EmitLocalSymInfo(ISymbolWriter symWriter)
{
int i;
@@ -1468,51 +1383,51 @@ namespace System.Reflection.Emit
{
if (tryOffset < 0)
{
- throw new ArgumentOutOfRangeException("tryOffset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+ throw new ArgumentOutOfRangeException(nameof(tryOffset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if (tryLength < 0)
{
- throw new ArgumentOutOfRangeException("tryLength", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+ throw new ArgumentOutOfRangeException(nameof(tryLength), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if (filterOffset < 0)
{
- throw new ArgumentOutOfRangeException("filterOffset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+ throw new ArgumentOutOfRangeException(nameof(filterOffset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if (handlerOffset < 0)
{
- throw new ArgumentOutOfRangeException("handlerOffset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+ throw new ArgumentOutOfRangeException(nameof(handlerOffset), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if (handlerLength < 0)
{
- throw new ArgumentOutOfRangeException("handlerLength", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+ throw new ArgumentOutOfRangeException(nameof(handlerLength), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if ((long)tryOffset + tryLength > Int32.MaxValue)
{
- throw new ArgumentOutOfRangeException("tryLength", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, Int32.MaxValue - tryOffset));
+ throw new ArgumentOutOfRangeException(nameof(tryLength), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, Int32.MaxValue - tryOffset));
}
if ((long)handlerOffset + handlerLength > Int32.MaxValue)
{
- throw new ArgumentOutOfRangeException("handlerLength", Environment.GetResourceString("ArgumentOutOfRange_Range", 0, Int32.MaxValue - handlerOffset));
+ throw new ArgumentOutOfRangeException(nameof(handlerLength), Environment.GetResourceString("ArgumentOutOfRange_Range", 0, Int32.MaxValue - handlerOffset));
}
// Other tokens migth also be invalid. We only check nil tokens as the implementation (SectEH_Emit in corhlpr.cpp) requires it,
// and we can't check for valid tokens until the module is baked.
if (kind == ExceptionHandlingClauseOptions.Clause && (exceptionTypeToken & 0x00FFFFFF) == 0)
{
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeToken", exceptionTypeToken), "exceptionTypeToken");
+ throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeToken", exceptionTypeToken), nameof(exceptionTypeToken));
}
Contract.EndContractBlock();
if (!IsValidKind(kind))
{
- throw new ArgumentOutOfRangeException("kind", Environment.GetResourceString("ArgumentOutOfRange_Enum"));
+ throw new ArgumentOutOfRangeException(nameof(kind), Environment.GetResourceString("ArgumentOutOfRange_Enum"));
}
m_tryStartOffset = tryOffset;
@@ -1527,13 +1442,13 @@ namespace System.Reflection.Emit
internal ExceptionHandler(int tryStartOffset, int tryEndOffset, int filterOffset, int handlerStartOffset, int handlerEndOffset,
int kind, int exceptionTypeToken)
{
- Contract.Assert(tryStartOffset >= 0);
- Contract.Assert(tryEndOffset >= 0);
- Contract.Assert(filterOffset >= 0);
- Contract.Assert(handlerStartOffset >= 0);
- Contract.Assert(handlerEndOffset >= 0);
- Contract.Assert(IsValidKind((ExceptionHandlingClauseOptions)kind));
- Contract.Assert(kind != (int)ExceptionHandlingClauseOptions.Clause || (exceptionTypeToken & 0x00FFFFFF) != 0);
+ Debug.Assert(tryStartOffset >= 0);
+ Debug.Assert(tryEndOffset >= 0);
+ Debug.Assert(filterOffset >= 0);
+ Debug.Assert(handlerStartOffset >= 0);
+ Debug.Assert(handlerEndOffset >= 0);
+ Debug.Assert(IsValidKind((ExceptionHandlingClauseOptions)kind));
+ Debug.Assert(kind != (int)ExceptionHandlingClauseOptions.Clause || (exceptionTypeToken & 0x00FFFFFF) != 0);
m_tryStartOffset = tryStartOffset;
m_tryEndOffset = tryEndOffset;