繁体   English   中英

在 xamarin 应用程序中从 firebase 返回数据时出错

[英]error while returning data from firebase in xamarin app

我有一个 c# 应用程序,它处理 firebase 数据库,以便从中获取特定项目的数据An object reference is required for the non-static field, method, or propertyAppintmentService.GetFollowUp(patient.ID) ) 中返回此错误AppintmentService.GetFollowUp(patient.ID)线,我做错了什么?

public ICommand Appearing { get => _Appearing; set => SetProperty(ref _Appearing, value, nameof(Appearing)); }

 public PatientProfileFollowUpPageModelView(Patient patient)
        {
            Appearing = new AsyncCommand(async () => await LoadData(patient));
        }

function:

async Task LoadData(Patient patient)
        {
            Appoitments = new ObservableCollection<Appoitment>(await AppintmentService.GetFollowUp(patient.ID));

        }

和服务:

public ObservableCollection<Appoitment> GetFollowUp(string PatientID)
        {
            var FollowUp = firebaseClient
             .Child($"Specalists/{PreferencesConfig.Id}/Patients/{PatientID}/Appointments")
             .AsObservable<Appoitment>()
             .AsObservableCollection();

            return FollowUp;
        }

GetFollowUp是 class AppintmentService上的一个方法,因此您需要一个AppintmentService实例才能调用它。

var svc = new AppintmentService);
var result = svc.GetFollowUp(patient.ID)

或者,您可以使GetFollowUp成为static方法,这样您就可以在没有实例的情况下调用它

在任何一种情况下, GetFollowUp没有标记为 async ,因此不需要使用await调用它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM