Skip to content

Instantly share code, notes, and snippets.

@Yoticc
Last active November 26, 2023 16:27
Show Gist options
  • Save Yoticc/9a186f8cd37e91cae854d48b9d04fc05 to your computer and use it in GitHub Desktop.
Save Yoticc/9a186f8cd37e91cae854d48b9d04fc05 to your computer and use it in GitHub Desktop.
Dnlib: Add custom attribute UnmanagedCallersOnly. How to add array field argument in CutsomAttribute.
var attbr = new CustomAttribute(module.Import(/*Ctor of UnmanagedCallersOnlyAttribute*/));
attbr.NamedArguments.Add(new(true, module.CorLibTypes.String, "EntryPoint", new(module.CorLibTypes.String, /*entrypoint name, just string*/)));
attbr.NamedArguments.Add(new(true, /*System.Type[] TypeSig*/, "CallConvs", new(/*System.Type[] TypeSig*/, /*CallConv types, just Type[]*/.Select(t => new CAArgument(/*System.Type TypeSig*/, module.ImportAsTypeSig(t))).ToList())));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment