Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding hook returnType to docs.json file #157

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions src/Docs/DocsHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class DocsHook
public string HookName { get; set; }
public string HookDescription { get; set; }
public Dictionary<string, string> HookParameters { get; set; }
public string ReturnType { get; set; }
public ReturnBehavior ReturnBehavior { get; set; } = ReturnBehavior.Continue;
public string TargetType { get; set; }
public string Category { get; set; }
Expand All @@ -45,6 +46,7 @@ public DocsHook(Hook hook, MethodDefinition methodDef, string targetDirectory)
Type = HookType.Simple;
ReturnBehavior = simpleHook.ReturnBehavior;
HookParameters = GetHookArguments(simpleHook, methodDef);
ReturnType = GetReturnType(simpleHook, methodDef);
break;

case Modify modifyHook:
Expand Down Expand Up @@ -165,6 +167,42 @@ private Dictionary<string, string> GetHookArguments(Simple hook, MethodDefinitio
return hookArguments;
}

private string GetReturnType(Simple hook, MethodDefinition method)
{
string returnType = "";
try
{
switch (hook?.ReturnBehavior)
{
case ReturnBehavior.Continue:
returnType = "void";
break;

case ReturnBehavior.ExitWhenNonNull:
if (hook?.Signature.ReturnType == "System.Void") returnType = "object";
else returnType = Utility.TransformType(hook?.Signature.ReturnType);
break;

case ReturnBehavior.ExitWhenValidType:
if (hook?.Signature.ReturnType == "System.Void") returnType = "object";
else returnType = Utility.TransformType(hook?.Signature.ReturnType);
break;

case ReturnBehavior.ModifyRefArg:
if (hook?.Signature.ReturnType == "System.Void") returnType = "object";
else returnType = Utility.TransformType(hook?.Signature.ReturnType);
break;

case ReturnBehavior.UseArgumentString:
string[] args = Utility.ParseArgumentString(hook.ArgumentString, out string returnValue);
returnType = Utility.TransformType(GetArgStringType(returnValue, method, out string argName));
break;
}
} catch { returnType = "ERROR"; }

return returnType;
}

//Doesn't work if I use the Decompiler class so just do this for now
private static string GetSourceCode(MethodDefinition methodDefinition)
{
Expand Down