Weaver.ResolveMethodGeneric moved to Resolvers

This commit is contained in:
vis2k 2019-01-02 13:37:55 +01:00
parent ee618ad8f6
commit abdc6b8e56
2 changed files with 28 additions and 28 deletions

View File

@ -98,5 +98,32 @@ public static MethodDefinition ResolveDefaultPublicCtor(TypeReference variable)
} }
return null; return null;
} }
public static GenericInstanceMethod ResolveMethodGeneric(TypeReference t, AssemblyDefinition scriptDef, string name, TypeReference genericType)
{
foreach (MethodDefinition methodRef in t.Resolve().Methods)
{
if (methodRef.Name == name)
{
if (methodRef.Parameters.Count == 0)
{
if (methodRef.GenericParameters.Count == 1)
{
MethodReference tmp = scriptDef.MainModule.ImportReference(methodRef);
GenericInstanceMethod gm = new GenericInstanceMethod(tmp);
gm.GenericArguments.Add(genericType);
if (gm.GenericArguments[0].FullName == genericType.FullName)
{
return gm;
}
}
}
}
}
Log.Error("ResolveMethodGeneric failed " + t.Name + "::" + name + " " + genericType);
Weaver.fail = true;
return null;
}
} }
} }

View File

@ -1034,33 +1034,6 @@ static bool ProcessNetworkBehaviourType(TypeDefinition td)
return false; return false;
} }
static GenericInstanceMethod ResolveMethodGeneric(TypeReference t, string name, TypeReference genericType)
{
foreach (var methodRef in t.Resolve().Methods)
{
if (methodRef.Name == name)
{
if (methodRef.Parameters.Count == 0)
{
if (methodRef.GenericParameters.Count == 1)
{
MethodReference tmp = scriptDef.MainModule.ImportReference(methodRef);
GenericInstanceMethod gm = new GenericInstanceMethod(tmp);
gm.GenericArguments.Add(genericType);
if (gm.GenericArguments[0].FullName == genericType.FullName)
{
return gm;
}
}
}
}
}
Log.Error("ResolveMethodGeneric failed " + t.Name + "::" + name + " " + genericType);
fail = true;
return null;
}
public static FieldReference ResolveField(TypeReference t, string name) public static FieldReference ResolveField(TypeReference t, string name)
{ {
foreach (FieldDefinition fd in t.Resolve().Fields) foreach (FieldDefinition fd in t.Resolve().Fields)
@ -1217,7 +1190,7 @@ static void SetupTargetTypes()
ReadyConnectionReference = Resolvers.ResolveMethod(ClientSceneType, scriptDef, "get_readyConnection"); ReadyConnectionReference = Resolvers.ResolveMethod(ClientSceneType, scriptDef, "get_readyConnection");
// get specialized GetComponent<NetworkIdentity>() // get specialized GetComponent<NetworkIdentity>()
getComponentReference = ResolveMethodGeneric(ComponentType, "GetComponent", NetworkIdentityType); getComponentReference = Resolvers.ResolveMethodGeneric(ComponentType, scriptDef, "GetComponent", NetworkIdentityType);
getUNetIdReference = Resolvers.ResolveMethod(unetViewTmp, scriptDef, "get_netId"); getUNetIdReference = Resolvers.ResolveMethod(unetViewTmp, scriptDef, "get_netId");