protected override IntPtr CreateNativeResources()

in src/cs/Microsoft.PhoneticMatching/Matchers/FuzzyMatcher/AbstractFuzzyMatcher.cs [219:248]


        protected override IntPtr CreateNativeResources(params object[] args)
        {
            if (args.Length != 5)
            {
                throw new ArgumentException("Fuzzy matcher needs parameters to instantiate native resource.");
            }

            this.isAccelerated = (bool)args[0];
            var targets = args[1] as IList<Target>;
            var distance = args[2] as DistanceFunc;
            var extractionToPronounceable = args[3] as Func<Extraction, Pronounceable>;
            var targetToExtraction = args[4] as Func<Target, Extraction>;

            // Managed object needs to be initialized *before* creating the native fuzzy matcher.
            this.InitializeManaged(targets, distance, targetToExtraction, extractionToPronounceable);

            int targetsCount = targets.Count;

            IntPtr native = IntPtr.Zero;

            NativeResourceWrapper.CallNative((buffer) =>
            {
                int bufferSize = NativeResourceWrapper.BufferSize;
                var result = FuzzyMatcherBase.FuzzyMatcher_Create(targetsCount, this.nativeDistanceDelegate, this.isAccelerated, out native, buffer, ref bufferSize);
                NativeResourceWrapper.BufferSize = bufferSize;
                return result;
            });

            return native;
        }