private void RegisterRegex(DbConnection connection) { var sqlFunction = new RegExSQLiteFunction(); #if NETSTANDARD ((SqliteConnection)connection).CreateFunction <string, string, bool>("REGEXP", (pattern, input) => sqlFunction.IsMatch(pattern, input)); #else var attr = new SQLiteFunctionAttribute("REGEXP", 2, FunctionType.Scalar); ((SQLiteConnection)connection).BindFunction(attr, sqlFunction); #endif }
/// <summary> /// Binds the given <paramref name="function"/> to the <paramref see="connection"/>. /// </summary> public void BindFunction(SQLiteFunctionBase function) { Ensure.NotNull(function, nameof(function)); Ensure.That <InvalidOperationException>(Connection.State == ConnectionState.Open, "Cannot bind a function to a closed."); var funcAttr = new SQLiteFunctionAttribute { Name = function.Name, FuncType = function.Type, Arguments = function.ArgumentCount }; Connection.BindFunction(funcAttr, function); }