在 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 property return 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));
        }

函数:

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 未标记为异步,因此不需要使用 await 调用它