I am currently cleaning up some of our legacy code base in which we make use of extern
methods. The parameter names are all over the place in terms of naming conventions. I'd like to consolidate them.
[DllImport("customdll", CallingConvention = CallingConvention.Cdecl)]
public static extern void SetStatus(int new_status);
Can I safely rename new_status
to newStatus
or will that break the contract?
ReSharper suggests it as a change, but I'd like to verify it. I was not able to find documentation on it (for or against it).
I am not asking if renaming the method name itself is possible, just the parameter definitions.
Yes, it is safe to change the name of the parameters (but not the method itself) as long as you keep them in the same order with the proper data types. Parameters in traditional DLLs are populated by ordinal, not by name.
You can also change the name of the method itself if you use the EntryPoint parameter in the DllImport constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With