【问题标题】:type resolution with Splat library and Xamarin.Mac使用 Splat 库和 Xamarin.Mac 进行类型解析
【发布时间】:2016-07-01 23:57:09
【问题描述】:

我有一个 Xamarin.iOS 项目,它使用 splat 库 https://github.com/paulcbetts/splat 使 System.Drawing 类型在可移植类库中可用。如果父类使用(比如)System.Drawing.RectangleF,那么通过使用 Splat,在 Xamarin.IOS 代码中对此类进行子类化就可以了。但是,Xamarin.Mac 并非如此,至少不是我这样做的方式。各种类型相互冲突——至少是 Point 和 RectangleF。

我不知道这是否与 Xamarin 最近的更新(对 Xamarin 6)有关。

下面是一些示例代码,我正在制作一个完整的项目来演示 Github 上的问题。 https://github.com/verybadcat/splat -- macbug 分支。

它看起来类似于此处描述的问题 [Splat [0.3.4] on Xamarin.iOS: issues with RectangleF and PointF

可移植类库项目:

using System.Drawing;
namespace PCL
{
  public class RectOwner
  {
    public RectangleF Rect { get; set;}
  }
}

IOS 项目——这很好用:

using PCL;

namespace IOSApp
{
  public class RectOwnerIOS: RectOwner
  {
    public RectOwnerIOS ()
    {
      this.Rect = new System.Drawing.RectangleF (10, 20, 30, 40);
    }
  }
}

Mac 项目 -- 未构建:

using PCL;


namespace MacApp
{
  public class RectOwnerSubclass: RectOwner
  {
    public RectOwnerSubclass ()
    {
      this.Rect = new System.Drawing.RectangleF (5, 6, 7, 8); // errors here:
      // /Users/william/Documents/splat/MacApp/RectOwnerMac.cs(16,16): Error CS7069: Reference to type `System.Drawing.RectangleF' claims it is defined assembly `Splat, Version=1.6.2.0, Culture=neutral, PublicKeyToken=null', but it could not be found (CS7069) (MacApp)
     // /Users/william/Documents/splat/MacApp/RectOwnerMac.cs(23,23): Error CS0029: Cannot implicitly convert type `System.Drawing.RectangleF [Xamarin.Mac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]' to `System.Drawing.RectangleF [Splat, Version=1.6.2.0, Culture=neutral, PublicKeyToken=null]' (CS0029) (MacApp)
    }
  }
}

如何构建 Mac 项目?

【问题讨论】:

  • 我降级到 Xamarin Studio 5.10 和相应的 Xamarin.Mac 版本。我仍然看到失败。

标签: c# xamarin xamarin.mac


【解决方案1】:

好的,所以有问题的错误是:

RectOwnerMac.cs(11,12): error CS7069: Reference to type `System.Drawing.RectangleF' claims it is defined assembly `Splat, Version=1.6.2.0, Culture=neutral, PublicKeyToken=null', but it could not be found
RectOwnerMac.cs(11,19): error CS0029: Cannot implicitly convert type `System.Drawing.RectangleF [Xamarin.Mac, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]' to `System.Drawing.RectangleF [Splat, Version=1.6.2.0, Culture=neutral, PublicKeyToken=null]'

这实际上是在说“Splat 声称声明了一个 RectangleF,但我找不到它。哦,他们的东西和 RectangleF 与我能找到的不匹配。

如果您查看源代码,则完全正确。在 Splat-portable 中,他们声明了自己的 RectangleF 类,但“诱饵和切换”Splat-XamarinMac 没有,也没有类型转发器。

您可以通过将 TypeForwardedSystemDrawing.cs 添加到 Split-XamarinMac 项目、重建(并注释掉或修复 UIKit 编译错误)来解决此问题。

随时向 Splat 团队提出问题,以最终解决此问题。

请注意,如果您尝试将 Splat 移植到 XM 4.5 目标框架,则需要引入 OpenTK,因为由于各种遗留原因,SD 类型在此处定义:

$ monop -r:/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/Xamarin.Mac.dll | grep Drawing.Rectangle
$ monop -r:/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/4.5/OpenTK.dll | grep Drawing.Rectangle
System.Drawing.Rectangle
System.Drawing.RectangleF

【讨论】:

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