【问题标题】:custom functions SQLite with Mono带有 Mono 的自定义函数 SQLite
【发布时间】:2012-10-30 21:06:15
【问题描述】:

有没有办法使用 Mono 添加 SQLite 自定义函数? (Mono.Data.Sqlite)

我尝试添加距离函数返回两个地理位置之间的距离

    [SqliteFunctionAttribute(Name = "distance", Arguments = 4, FuncType = FunctionType.Scalar)]
    class SqliteDistance : SqliteFunction
    {
        public override object Invoke(object[] args)
        {
            double radius = 6367;
            double lat1 = System.Convert.ToDouble(args[0]);
            double lng1 = System.Convert.ToDouble(args[1]);
            double lat2 = System.Convert.ToDouble(args[2]);
            double lng2 = System.Convert.ToDouble(args[3]);

            return radius * 2 * Math.Asin( Math.Min(1, Math.Sqrt( ( Math.Pow(Math.Sin((lat2* (Math.PI / 180) - lat1 * (Math.PI / 180) ) / 2.0), 2.0) + Math.Cos(lat1* (Math.PI / 180)) * Math.Cos(lat2* (Math.PI / 180)) * Math.Pow(Math.Sin(( lng2* (Math.PI / 180)-lng1* (Math.PI / 180)) / 2.0), 2.0) ) ) ) ); 
        }
    }

它给了我一个错误:

在使用 --aot-only 运行时尝试 JIT 编译方法 '(wrapper native-to-managed) Mono.Data.Sqlite.SqliteFunction:ScalarCallback (intptr,int,intptr)'。请参阅http://docs.xamarin.com/ios/about/limitations 了解更多信息。

【问题讨论】:

  • 关于如何实现这样的自定义方法的任何示例?我需要实现acos、cos、sin等数学函数……

标签: c# sql sqlite mono xamarin.ios


【解决方案1】:

查看错误报告页面的 Reverse Callbacks 段落:实际上,您需要将 MonoPInvokeCallbackAttribute 属性应用于方法(并且需要将其设为静态)。

这是对 iOS 设备的限制,因为它们不支持 JIT 编译器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多