Full framework

This commit is contained in:
Ben Adams
2017-11-13 12:14:24 +00:00
parent 5eb9c25574
commit f250bdef96
7 changed files with 84 additions and 35 deletions

View File

@@ -12,6 +12,7 @@ using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace System.Diagnostics
@@ -162,7 +163,7 @@ namespace System.Diagnostics
// ResolveStateMachineMethod may have set declaringType to null
if (type != null)
{
var declaringTypeName = TypeNameHelper.GetTypeDisplayName(type, fullName: true, includeGenericParameterNames: true);
var declaringTypeName = TypeNameHelper.GetTypeDisplayName(type, fullName: true, includeGenericParameterNames: true);
methodDisplayInfo.DeclaringTypeName = declaringTypeName;
}
@@ -297,6 +298,17 @@ namespace System.Diagnostics
candidateConstructors = dt.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => m.Name == matchName);
if (TryResolveSourceMethod(candidateConstructors, kind, matchHint, ref method, ref type, out ordinal)) return true;
if (methodName == ".cctor")
{
candidateConstructors = dt.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly).Where(m => m.Name == matchName);
foreach (var cctor in candidateConstructors)
{
method = cctor;
type = dt;
return true;
}
}
return false;
}
@@ -321,7 +333,6 @@ namespace System.Diagnostics
}
}
var rawIL = nethodBody?.GetILAsByteArray();
if (rawIL == null) continue;
@@ -342,23 +353,15 @@ namespace System.Diagnostics
return true;
}
}
else if (reader.Operand is Type t)
{
if (t == type)
{
method = candidateMethod;
type = method.DeclaringType;
return true;
}
}
}
}
return false;
}
private static void GetOrdinal(MethodBase method, ref int? ordinal)
{
var lamdaStart = method.Name.IndexOf((char) GeneratedNameKind.LambdaMethod + "__") + 3;
var lamdaStart = method.Name.IndexOf((char)GeneratedNameKind.LambdaMethod + "__") + 3;
if (lamdaStart > 3)
{
var secondStart = method.Name.IndexOf("_", lamdaStart) + 1;
@@ -584,7 +587,28 @@ namespace System.Diagnostics
{
return false;
}
if (type == typeof(Task) && method.Name == "ExecuteWithThreadLocal")
if (type == typeof(Task))
{
switch (method.Name)
{
case "ExecuteWithThreadLocal":
case "Execute":
case "ExecutionContextCallback":
case "ExecuteEntry":
case "InnerInvoke":
return false;
}
}
if (type == typeof(ExecutionContext))
{
switch (method.Name)
{
case "RunInternal":
case "Run":
return false;
}
}
if (type.Namespace == "System.Threading" && (type.Name?.StartsWith("_") ?? false))
{
return false;
}

View File

@@ -19,7 +19,7 @@ namespace System.Diagnostics.Internal
public OpCode OpCode { get; private set; }
public int MetadataToken { get; private set; }
public object Operand { get; private set; }
public MemberInfo Operand { get; private set; }
public bool Read(MethodBase methodInfo)
{
@@ -35,13 +35,13 @@ namespace System.Diagnostics.Internal
OpCode ReadOpCode()
{
byte instruction = ReadByte();
if (instruction != 254)
if (instruction < 254)
return singleByteOpCode[instruction];
else
return doubleByteOpCode[ReadByte()];
}
object ReadOperand(OpCode code, MethodBase methodInfo)
MemberInfo ReadOperand(OpCode code, MethodBase methodInfo)
{
MetadataToken = 0;
switch (code.OperandType)
@@ -50,11 +50,23 @@ namespace System.Diagnostics.Internal
MetadataToken = ReadInt();
Type[] methodArgs = null;
if (methodInfo.GetType() != typeof(ConstructorInfo) && !methodInfo.GetType().IsSubclassOf(typeof(ConstructorInfo)))
{
methodArgs = methodInfo.GetGenericArguments();
}
Type[] typeArgs = null;
if (methodInfo.DeclaringType != null)
{
typeArgs = methodInfo.DeclaringType.GetGenericArguments();
return methodInfo.Module.ResolveMember(MetadataToken, typeArgs, methodArgs);
}
try
{
return methodInfo.Module.ResolveMember(MetadataToken, typeArgs, methodArgs);
}
catch
{
// Can return System.ArgumentException : Token xxx is not a valid MemberInfo token in the scope of module xxx.dll
return null;
}
}
return null;
}