Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Harmony/Internal/PatchTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ internal static MethodBase GetOriginalMethod(this HarmonyMethod attr)
switch (attr.methodType)
{
case MethodType.Normal:
if (attr.methodName is null)
if (string.IsNullOrEmpty(attr.methodName))
return null;
return AccessTools.DeclaredMethod(attr.declaringType, attr.methodName, attr.argumentTypes);

case MethodType.Getter:
if (attr.methodName is null)
if (string.IsNullOrEmpty(attr.methodName))
return AccessTools.DeclaredIndexerGetter(attr.declaringType, attr.argumentTypes);
return AccessTools.DeclaredPropertyGetter(attr.declaringType, attr.methodName);

case MethodType.Setter:
if (attr.methodName is null)
if (string.IsNullOrEmpty(attr.methodName))
return AccessTools.DeclaredIndexerSetter(attr.declaringType, attr.argumentTypes);
return AccessTools.DeclaredPropertySetter(attr.declaringType, attr.methodName);

Expand All @@ -113,14 +113,14 @@ internal static MethodBase GetOriginalMethod(this HarmonyMethod attr)
.FirstOrDefault();

case MethodType.Enumerator:
if (attr.methodName is null)
if (string.IsNullOrEmpty(attr.methodName))
return null;
var enumMethod = AccessTools.DeclaredMethod(attr.declaringType, attr.methodName, attr.argumentTypes);
return AccessTools.EnumeratorMoveNext(enumMethod);

#if NET45_OR_GREATER || NETSTANDARD || NETCOREAPP
case MethodType.Async:
if (attr.methodName is null)
if (string.IsNullOrEmpty(attr.methodName))
return null;
var asyncMethod = AccessTools.DeclaredMethod(attr.declaringType, attr.methodName, attr.argumentTypes);
return AccessTools.AsyncMoveNext(asyncMethod);
Expand Down
29 changes: 14 additions & 15 deletions Harmony/Tools/AccessTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ public static FieldInfo DeclaredField(Type type, string name)
FileLog.Debug("AccessTools.DeclaredField: type is null");
return null;
}
if (name is null)
if (string.IsNullOrEmpty(name))
{
FileLog.Debug("AccessTools.DeclaredField: name is null");
FileLog.Debug("AccessTools.DeclaredField: name is null/empty");
return null;
}
var fieldInfo = type.GetField(name, allDeclared);
Expand Down Expand Up @@ -183,9 +183,9 @@ public static FieldInfo Field(Type type, string name)
FileLog.Debug("AccessTools.Field: type is null");
return null;
}
if (name is null)
if (string.IsNullOrEmpty(name))
{
FileLog.Debug("AccessTools.Field: name is null");
FileLog.Debug("AccessTools.Field: name is null/empty");
return null;
}
var fieldInfo = FindIncludingBaseTypes(type, t => t.GetField(name, all));
Expand Down Expand Up @@ -234,9 +234,9 @@ public static PropertyInfo DeclaredProperty(Type type, string name)
FileLog.Debug("AccessTools.DeclaredProperty: type is null");
return null;
}
if (name is null)
if (string.IsNullOrEmpty(name))
{
FileLog.Debug("AccessTools.DeclaredProperty: name is null");
FileLog.Debug("AccessTools.DeclaredProperty: name is null/empty");
return null;
}
var property = type.GetProperty(name, allDeclared);
Expand Down Expand Up @@ -338,9 +338,9 @@ public static PropertyInfo Property(Type type, string name)
FileLog.Debug("AccessTools.Property: type is null");
return null;
}
if (name is null)
if (string.IsNullOrEmpty(name))
{
FileLog.Debug("AccessTools.Property: name is null");
FileLog.Debug("AccessTools.Property: name is null/empty");
return null;
}
var property = FindIncludingBaseTypes(type, t => t.GetProperty(name, all));
Expand Down Expand Up @@ -446,9 +446,9 @@ public static MethodInfo DeclaredMethod(Type type, string name, Type[] parameter
FileLog.Debug("AccessTools.DeclaredMethod: type is null");
return null;
}
if (name is null)
if (string.IsNullOrEmpty(name))
{
FileLog.Debug("AccessTools.DeclaredMethod: name is null");
FileLog.Debug("AccessTools.DeclaredMethod: name is null/empty");
return null;
}
MethodInfo result;
Expand Down Expand Up @@ -495,9 +495,9 @@ public static MethodInfo Method(Type type, string name, Type[] parameters = null
FileLog.Debug("AccessTools.Method: type is null");
return null;
}
if (name is null)
if (string.IsNullOrEmpty(name))
{
FileLog.Debug("AccessTools.Method: name is null");
FileLog.Debug("AccessTools.Method: name is null/empty");
return null;
}
MethodInfo result;
Expand Down Expand Up @@ -857,9 +857,9 @@ public static Type Inner(Type type, string name)
FileLog.Debug("AccessTools.Inner: type is null");
return null;
}
if (name is null)
if (string.IsNullOrEmpty(name))
{
FileLog.Debug("AccessTools.Inner: name is null");
FileLog.Debug("AccessTools.Inner: name is null/empty");
return null;
}
return FindIncludingBaseTypes(type, t => t.GetNestedType(name, all));
Expand Down Expand Up @@ -1722,7 +1722,6 @@ public static DelegateType MethodDelegate<DelegateType>(string typeColonName, ob
{
var method = DeclaredMethod(typeColonName);
return MethodDelegate<DelegateType>(method, instance, virtualCall);

}

/// <summary>Creates a delegate for a given delegate definition, attributed with [<see cref="HarmonyLib.HarmonyDelegate"/>]</summary>
Expand Down