Created
December 10, 2020 05:03
-
-
Save distantcam/09bc3f3cf445adddb4f3e6c911d7e530 to your computer and use it in GitHub Desktop.
A Fody weaver to strip C# 9 records markers so the assembly is compatible with C# 8 / Xamarin mono build tools.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using Fody; | |
using Mono.Cecil; | |
public class StripIsExternalInitWeaver : BaseModuleWeaver | |
{ | |
public override void Execute() | |
{ | |
var types = ModuleDefinition.Types.Concat(ModuleDefinition.Types.SelectMany(t => t.NestedTypes)); | |
foreach (var type in types) | |
{ | |
foreach (var prop in type.Properties) | |
{ | |
if (prop is null || | |
prop.SetMethod is null || | |
prop.SetMethod.ReturnType is not RequiredModifierType setReturnType || | |
setReturnType.ModifierType.FullName != "System.Runtime.CompilerServices.IsExternalInit" || | |
setReturnType.ElementType.FullName != "System.Void") | |
{ | |
continue; | |
} | |
prop.SetMethod.ReturnType = TypeSystem.VoidReference; | |
} | |
} | |
} | |
public override IEnumerable<string> GetAssembliesForScanning() | |
{ | |
yield return "netstandard"; | |
yield return "mscorlib"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment