sillsdev / icu-dotnet

C# wrapper for ICU4C
MIT License
62 stars 32 forks source link

Allow setting up custom data with udata_setAppData #177

Open dzendras opened 1 year ago

dzendras commented 1 year ago

Is your feature request related to a problem? Please describe.

I want to replace my existing codebase using some earlier icu.net code with the latest nuget package. I need to load a custom *.dat file to memory for a normalizer to use. The existing code is:

 var data = new byte[] { /* utr30.dat */ };
 var unmanagedPointer = Marshal.AllocHGlobal(data.Length);
 Marshal.Copy(data, 0, unmanagedPointer, data.Length);

 ErrorCode status2;
 NativeMethods.udata_setAppData("utr30", unmanagedPointer, out status2);
 ExceptionFromErrorCode.ThrowIfError(status2);

Describe the solution you'd like

Create a .NET wrapper that would allow setting custom data.

Describe alternatives you've considered

Copy ThrowIfError from this repo and reproduce NativeMethods.udata_setAppData in my project in order for it to work. Ugly.