diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-06-03 18:52:16 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-06-03 18:52:16 -0400 |
commit | 8c4edc27656b7b60b4036a158c30f4fc1caccdd7 (patch) | |
tree | d94def35b98482be3c6e13e536109d1fa6d1a941 /src | |
parent | cfc7233a0641b4c571068f67be7f2b4dba6d1c3f (diff) | |
download | SMAPI-8c4edc27656b7b60b4036a158c30f4fc1caccdd7.tar.gz SMAPI-8c4edc27656b7b60b4036a158c30f4fc1caccdd7.tar.bz2 SMAPI-8c4edc27656b7b60b4036a158c30f4fc1caccdd7.zip |
tweak new code, add release note (#718)
Diffstat (limited to 'src')
-rw-r--r-- | src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs b/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs index 579c3a08..c4e6013e 100644 --- a/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs +++ b/src/SMAPI/Framework/ModLoading/Framework/RecursiveRewriter.cs @@ -57,16 +57,18 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework /// <returns>Returns whether the module was modified.</returns> public bool RewriteModule() { - Tuple<bool,Exception> aggregateResult = this.Module.GetTypes() - .AsParallel().WithExecutionMode(ParallelExecutionMode.ForceParallelism) + // rewrite each type in the assembly, tracking whether any type was rewritten (Item1) + // and any exception that occurred during rewriting (Item2). + Tuple<bool, Exception> result = this.Module + .GetTypes() + .Where(type => type.BaseType != null) // skip special types like <Module> + .AsParallel() + .WithExecutionMode(ParallelExecutionMode.ForceParallelism) .Select(type => { + bool anyRewritten = false; try { - bool anyRewritten = false; - if (type.BaseType == null) - return new Tuple<bool, Exception>(anyRewritten, null); // special type like <Module> - anyRewritten |= this.RewriteCustomAttributes(type.CustomAttributes); anyRewritten |= this.RewriteGenericParameters(type.GenericParameters); @@ -112,19 +114,20 @@ namespace StardewModdingAPI.Framework.ModLoading.Framework } } - return new Tuple<bool, Exception>(anyRewritten, null); + return Tuple.Create(anyRewritten, null as Exception); } catch (Exception e) { - return new Tuple<bool, Exception>(false, e.InnerException ?? e); + return Tuple.Create(anyRewritten, e); } }) - .Aggregate((tupleA, tupleB) => new Tuple<bool, Exception>(tupleA.Item1 | tupleB.Item1, tupleA.Item2 ?? tupleB.Item2)); // Aggregate result and exception - if (aggregateResult.Item2 != null) - { - throw aggregateResult.Item2; // rethrow inner Exception - } - return aggregateResult.Item1; + .Aggregate((a, b) => Tuple.Create(a.Item1 || b.Item1, a.Item2 ?? b.Item2)); + + bool rewritten = result.Item1; + Exception exception = result.Item2; + return exception == null + ? rewritten + : throw exception; } |