public void CreateCollation(string name, Collation collation) { name = name.ToUpperInvariant(); var nativeCollation = new CollationNative((applicationData, firstLength, firstString, secondLength, secondString) => { var first = this.platformMarshal.MarshalStringNativeUTF8ToManaged(firstString); var second = this.platformMarshal.MarshalStringNativeUTF8ToManaged(secondString); try { return(collation.Invoke(first, second)); } catch { return(0); } }); var collationDelegate = this.platformMarshal.ApplyNativeCallingConventionToCollation(nativeCollation); this.collationDelegates[name] = collationDelegate; var collPtr = this.platformMarshal.MarshalDelegateToNativeFunctionPointer(collationDelegate); int nameLength; var namePtr = this.platformMarshal.MarshalStringManagedToNativeUTF8(name, out nameLength); try { this.sqlite3Provider.Sqlite3CreateCollation(this.db, namePtr, collPtr); } finally { if (namePtr != IntPtr.Zero) { this.platformMarshal.CleanUpStringNativeUTF8(namePtr); } } }
Delegate IPlatformMarshal.ApplyNativeCallingConventionToCollation(CollationNative collation) { return(new CollationNativeCdecl(collation)); }
public void CreateCollation(string name, Collation collation) { name = name.ToUpperInvariant(); var nativeCollation = new CollationNative((applicationData, firstLength, firstString, secondLength, secondString) => { var first = this.platformMarshal.MarshalStringNativeUTF8ToManaged(firstString); var second = this.platformMarshal.MarshalStringNativeUTF8ToManaged(secondString); try { return collation.Invoke(first, second); } catch { return 0; } }); var collationDelegate = this.platformMarshal.ApplyNativeCallingConventionToCollation(nativeCollation); this.collationDelegates[name] = collationDelegate; var collPtr = this.platformMarshal.MarshalDelegateToNativeFunctionPointer(collationDelegate); int nameLength; var namePtr = this.platformMarshal.MarshalStringManagedToNativeUTF8(name, out nameLength); try { this.sqlite3Provider.Sqlite3CreateCollation(this.db, namePtr, collPtr); } finally { if (namePtr != IntPtr.Zero) { this.platformMarshal.CleanUpStringNativeUTF8(namePtr); } } }
Delegate IPlatformMarshal.ApplyNativeCallingConventionToCollation(CollationNative collation) { return new CollationNativeCdecl(collation); }