summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs')
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs126
1 files changed, 23 insertions, 103 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs
index cb2667a104..b592053f9f 100644
--- a/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs
+++ b/src/mscorlib/src/System/Reflection/Emit/DynamicILGenerator.cs
@@ -6,7 +6,6 @@
namespace System.Reflection.Emit
{
-
using System;
using System.Globalization;
using System.Diagnostics.SymbolStore;
@@ -22,7 +21,6 @@ namespace System.Reflection.Emit
internal class DynamicILGenerator : ILGenerator
{
-
internal DynamicScope m_scope;
private int m_methodSigToken;
@@ -44,16 +42,6 @@ namespace System.Reflection.Emit
new DynamicResolver(this));
}
-#if FEATURE_APPX
- private bool ProfileAPICheck
- {
- get
- {
- return ((DynamicMethod)m_methodBuilder).ProfileAPICheck;
- }
- }
-#endif // FEATURE_APPX
-
// *** ILGenerator api ***
public override LocalBuilder DeclareLocal(Type localType, bool pinned)
@@ -66,12 +54,7 @@ namespace System.Reflection.Emit
RuntimeType rtType = localType as RuntimeType;
if (rtType == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
-
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
-#endif
+ throw new ArgumentException(SR.Argument_MustBeRuntimeType);
localBuilder = new LocalBuilder(m_localCount, localType, m_methodBuilder);
// add the localType to local signature
@@ -98,7 +81,7 @@ namespace System.Reflection.Emit
{
RuntimeMethodInfo rtMeth = meth as RuntimeMethodInfo;
if (rtMeth == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(meth));
+ throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(meth));
RuntimeType declaringType = rtMeth.GetRuntimeType();
if (declaringType != null && (declaringType.IsGenericType || declaringType.IsArray))
@@ -111,7 +94,7 @@ namespace System.Reflection.Emit
// rule out not allowed operations on DynamicMethods
if (opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn))
{
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOpCodeOnDynamicMethod"));
+ throw new ArgumentException(SR.Argument_InvalidOpCodeOnDynamicMethod);
}
token = GetTokenFor(dynMeth);
}
@@ -149,7 +132,7 @@ namespace System.Reflection.Emit
RuntimeConstructorInfo rtConstructor = con as RuntimeConstructorInfo;
if (rtConstructor == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(con));
+ throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(con));
RuntimeType declaringType = rtConstructor.GetRuntimeType();
int token;
@@ -178,7 +161,7 @@ namespace System.Reflection.Emit
RuntimeType rtType = type as RuntimeType;
if (rtType == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
+ throw new ArgumentException(SR.Argument_MustBeRuntimeType);
int token = GetTokenFor(rtType);
EnsureCapacity(7);
@@ -194,7 +177,7 @@ namespace System.Reflection.Emit
RuntimeFieldInfo runtimeField = field as RuntimeFieldInfo;
if (runtimeField == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeFieldInfo"), nameof(field));
+ throw new ArgumentException(SR.Argument_MustBeRuntimeFieldInfo, nameof(field));
int token;
if (field.DeclaringType == null)
@@ -235,7 +218,7 @@ namespace System.Reflection.Emit
if (optionalParameterTypes != null)
if ((callingConvention & CallingConventions.VarArgs) == 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
+ throw new InvalidOperationException(SR.InvalidOperation_NotAVarArgCallingConvention);
sig = GetMemberRefSignature(callingConvention,
returnType,
@@ -271,13 +254,13 @@ namespace System.Reflection.Emit
throw new ArgumentNullException(nameof(methodInfo));
if (!(opcode.Equals(OpCodes.Call) || opcode.Equals(OpCodes.Callvirt) || opcode.Equals(OpCodes.Newobj)))
- throw new ArgumentException(Environment.GetResourceString("Argument_NotMethodCallOpcode"), nameof(opcode));
+ throw new ArgumentException(SR.Argument_NotMethodCallOpcode, nameof(opcode));
if (methodInfo.ContainsGenericParameters)
- throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), nameof(methodInfo));
+ throw new ArgumentException(SR.Argument_GenericsInvalid, nameof(methodInfo));
if (methodInfo.DeclaringType != null && methodInfo.DeclaringType.ContainsGenericParameters)
- throw new ArgumentException(Environment.GetResourceString("Argument_GenericsInvalid"), nameof(methodInfo));
+ throw new ArgumentException(SR.Argument_GenericsInvalid, nameof(methodInfo));
Contract.EndContractBlock();
int tk;
@@ -345,7 +328,7 @@ namespace System.Reflection.Emit
// Begins an exception filter block. Emits a branch instruction to the end of the current exception block.
if (CurrExcStackCount == 0)
- throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
+ throw new NotSupportedException(SR.Argument_NotInExceptionBlock);
__ExceptionInfo current = CurrExcStack[CurrExcStackCount - 1];
@@ -359,7 +342,7 @@ namespace System.Reflection.Emit
public override void BeginCatchBlock(Type exceptionType)
{
if (CurrExcStackCount == 0)
- throw new NotSupportedException(Environment.GetResourceString("Argument_NotInExceptionBlock"));
+ throw new NotSupportedException(SR.Argument_NotInExceptionBlock);
Contract.EndContractBlock();
__ExceptionInfo current = CurrExcStack[CurrExcStackCount - 1];
@@ -370,7 +353,7 @@ namespace System.Reflection.Emit
{
if (exceptionType != null)
{
- throw new ArgumentException(Environment.GetResourceString("Argument_ShouldNotSpecifyExceptionType"));
+ throw new ArgumentException(SR.Argument_ShouldNotSpecifyExceptionType);
}
this.Emit(OpCodes.Endfilter);
@@ -384,7 +367,7 @@ namespace System.Reflection.Emit
throw new ArgumentNullException(nameof(exceptionType));
if (rtType == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
+ throw new ArgumentException(SR.Argument_MustBeRuntimeType);
Label endLabel = current.GetEndLabel();
this.Emit(OpCodes.Leave, endLabel);
@@ -409,7 +392,7 @@ namespace System.Reflection.Emit
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
public override void UsingNamespace(String ns)
{
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
+ throw new NotSupportedException(SR.InvalidOperation_NotAllowedInDynamicMethod);
}
[SuppressMessage("Microsoft.Contracts", "CC1055")] // Skip extra error checking to avoid *potential* AppCompat problems.
@@ -419,17 +402,17 @@ namespace System.Reflection.Emit
int endLine,
int endColumn)
{
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
+ throw new NotSupportedException(SR.InvalidOperation_NotAllowedInDynamicMethod);
}
public override void BeginScope()
{
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
+ throw new NotSupportedException(SR.InvalidOperation_NotAllowedInDynamicMethod);
}
public override void EndScope()
{
- throw new NotSupportedException(Environment.GetResourceString("InvalidOperation_NotAllowedInDynamicMethod"));
+ throw new NotSupportedException(SR.InvalidOperation_NotAllowedInDynamicMethod);
}
private int GetMemberRefToken(MethodBase methodInfo, Type[] optionalParameterTypes)
@@ -437,13 +420,13 @@ namespace System.Reflection.Emit
Type[] parameterTypes;
if (optionalParameterTypes != null && (methodInfo.CallingConvention & CallingConventions.VarArgs) == 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotAVarArgCallingConvention"));
+ throw new InvalidOperationException(SR.InvalidOperation_NotAVarArgCallingConvention);
RuntimeMethodInfo rtMeth = methodInfo as RuntimeMethodInfo;
DynamicMethod dm = methodInfo as DynamicMethod;
if (rtMeth == null && dm == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(methodInfo));
+ throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(methodInfo));
ParameterInfo[] paramInfo = methodInfo.GetParametersNoCopy();
if (paramInfo != null && paramInfo.Length != 0)
@@ -498,94 +481,36 @@ namespace System.Reflection.Emit
#region GetTokenFor helpers
private int GetTokenFor(RuntimeType rtType)
{
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
-#endif
-
return m_scope.GetTokenFor(rtType.TypeHandle);
}
private int GetTokenFor(RuntimeFieldInfo runtimeField)
{
-#if FEATURE_APPX
- if (ProfileAPICheck)
- {
- RtFieldInfo rtField = runtimeField as RtFieldInfo;
- if (rtField != null && (rtField.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtField.FullName));
- }
-#endif
-
return m_scope.GetTokenFor(runtimeField.FieldHandle);
}
private int GetTokenFor(RuntimeFieldInfo runtimeField, RuntimeType rtType)
{
-#if FEATURE_APPX
- if (ProfileAPICheck)
- {
- RtFieldInfo rtField = runtimeField as RtFieldInfo;
- if (rtField != null && (rtField.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtField.FullName));
-
- if ((rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
- }
-#endif
-
return m_scope.GetTokenFor(runtimeField.FieldHandle, rtType.TypeHandle);
}
private int GetTokenFor(RuntimeConstructorInfo rtMeth)
{
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-#endif
-
return m_scope.GetTokenFor(rtMeth.MethodHandle);
}
private int GetTokenFor(RuntimeConstructorInfo rtMeth, RuntimeType rtType)
{
-#if FEATURE_APPX
- if (ProfileAPICheck)
- {
- if ((rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-
- if ((rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
- }
-#endif
-
return m_scope.GetTokenFor(rtMeth.MethodHandle, rtType.TypeHandle);
}
private int GetTokenFor(RuntimeMethodInfo rtMeth)
{
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-#endif
-
return m_scope.GetTokenFor(rtMeth.MethodHandle);
}
private int GetTokenFor(RuntimeMethodInfo rtMeth, RuntimeType rtType)
{
-#if FEATURE_APPX
- if (ProfileAPICheck)
- {
- if ((rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-
- if ((rtType.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtType.FullName));
- }
-#endif
-
return m_scope.GetTokenFor(rtMeth.MethodHandle, rtType.TypeHandle);
}
@@ -596,10 +521,6 @@ namespace System.Reflection.Emit
private int GetTokenForVarArgMethod(RuntimeMethodInfo rtMeth, SignatureHelper sig)
{
-#if FEATURE_APPX
- if (ProfileAPICheck && (rtMeth.InvocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NON_W8P_FX_API) != 0)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_APIInvalidForCurrentContext", rtMeth.FullName));
-#endif
VarArgMethod varArgMeth = new VarArgMethod(rtMeth, sig);
return m_scope.GetTokenFor(varArgMeth);
}
@@ -962,8 +883,8 @@ namespace System.Reflection.Emit
public DynamicMethod DynamicMethod { get { return m_method; } }
internal DynamicScope DynamicScope { get { return m_scope; } }
-#endregion
-#region Public Scope Methods
+ #endregion
+ #region Public Scope Methods
#endregion
}
@@ -1032,7 +953,7 @@ namespace System.Reflection.Emit
Type t = m.DeclaringType.GetGenericTypeDefinition();
throw new ArgumentException(String.Format(
- CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_MethodDeclaringTypeGenericLcg"), m, t));
+ CultureInfo.CurrentCulture, SR.Argument_MethodDeclaringTypeGenericLcg, m, t));
}
}
@@ -1119,5 +1040,4 @@ namespace System.Reflection.Emit
m_signature = signature;
}
}
-
}