【发布时间】:2017-12-18 21:21:57
【问题描述】:
我已经研究了一段时间,并且知道我缺少一些非常简单的东西。该代码在前一个开发人员离开之前可以使用,但现在我需要在 iPad 上发布,它无法正常工作。我正在使用 Visual Studio for Mac。
public class DemoPatientService : BaseService, IPatientService
{
public ObservableCollection<PatientSummary> MockPatientSummary;
public DemoPatientService()
{
MockPatientSummary = realm.All<PatientSummary>().ToObservableCollection();
}
}
public class PatientSummary : IPatientSummary
{
public string PatientID { get; set;}
}
public interface IPatientSummary
{
string PatientID
}
public class BaseService
{
protected readonly Realm realm;
public BaseService()
{
var config = new RealmConfiguration();
config = new RealmConfiguration(MYWSettings.Instance.DemoDatabasePath);
realm = Realm.GetInstance(config);
}
}
错误 CS0311:类型“VSTSQL.Data.Mobile.Models.PatientSummary”不能用作泛型类型或方法“Realm.All()”中的类型参数“T”。没有从“PatientSummary”到“Realms.RealmObject”的隐式引用转换。 (CS0311)
【问题讨论】:
-
这段代码以前真的有效吗?看起来
All<T>()方法需要Realms.RealmObject类型的任何东西,而PatienSummary显然不需要。 -
我所知道的是,某些版本的代码已部署给测试人员,所以它在某处工作。
-
那您如何了解版本历史并查找更改?
-
All<T>一直有一个where T : RealmObject通用约束,所以即使使用旧版本的 Realm,这段代码也不可能在当前形式下工作。
标签: c# generics xamarin.forms realm