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

Add option to the XML input to rewrite methods to throw / stubs. #555

Closed
wants to merge 1 commit into from
Closed
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
45 changes: 36 additions & 9 deletions src/linker/Linker.Steps/ResolveFromXmlStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,44 @@ void ProcessMethods (TypeDefinition type, XPathNodeIterator iterator)

protected virtual void ProcessMethod (TypeDefinition type, XPathNodeIterator iterator)
{
if (IsExcluded (iterator.Current))
return;
string action = null;
if (IsExcluded (iterator.Current)) {
action = GetAttribute (iterator.Current, "action");
if (String.IsNullOrEmpty (action))
return;
}

string value = GetSignature (iterator.Current);
if (!String.IsNullOrEmpty (value))
ProcessMethodSignature (type, value);
ProcessMethodSignature (type, value, action);

value = GetAttribute (iterator.Current, "name");
if (!String.IsNullOrEmpty (value))
ProcessMethodName (type, value);
ProcessMethodName (type, value, action);
}

void ProcessMethodSignature (TypeDefinition type, string signature)
void ProcessMethodSignature (TypeDefinition type, string signature, string action)
{
MethodDefinition meth = GetMethod (type, signature);
MarkMethod (type, meth, signature);
if (action == null)
MarkMethod (type, meth, signature);
else
MarkMethodAction (meth, action);
}

void MarkMethodAction (MethodDefinition method, string action)
{
switch (action) {
case "throw":
Annotations.SetAction (method, MethodAction.ConvertToThrow);
break;
case "stub":
Annotations.SetAction (method, MethodAction.ConvertToStub);
break;
default:
Context.LogMessage ($"Unknown method action `{action}`.");
break;
}
}

void MarkMethod (TypeDefinition type, MethodDefinition method, string signature)
Expand Down Expand Up @@ -447,14 +469,19 @@ void MarkMethodIfNotNull (MethodDefinition method)
MarkMethod (method);
}

void ProcessMethodName (TypeDefinition type, string name)
void ProcessMethodName (TypeDefinition type, string name, string action)
{
if (!type.HasMethods)
return;

foreach (MethodDefinition method in type.Methods)
if (name == method.Name)
foreach (MethodDefinition method in type.Methods) {
if (name != method.Name)
continue;
if (action == null)
MarkMethod (type, method, name);
else
MarkMethodAction (method, action);
}
}

protected static MethodDefinition GetMethod (TypeDefinition type, string signature)
Expand Down