© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
7 replies
Mek

✅ Just curious about something

using Diary.Models;
using Diary.Services;
using ReactiveUI;
using System;
using System.Reactive;
using System.Reactive.Linq;

namespace Diary.ViewModels;

public class LoginViewModel : ViewModelBase
{
    private Database _db;
    private Helpers _hp;
    private string _username;
    private string _password;
    private User _user;

    public LoginViewModel(Database db, Helpers hp)
    {
        _db = db;
        _hp = hp;

        IObservable<bool> usernameOk = this.WhenAnyValue(
            x => x.Username,
            x => !string.IsNullOrEmpty(x) && CheckUsername());

        IObservable<bool> passwordOk = this.WhenAnyValue(
            x => x.Password,
            x => !string.IsNullOrEmpty(x) && CheckPassword());
        IObservable<bool> okEnabled = passwordOk
            .Concat(usernameOk);

        Login = ReactiveCommand.Create(CreateUser, okEnabled);
        Exit = ReactiveCommand.Create(() => { });
    }

    public User CreateUser()
    {
        User currentUser = _db.GetUser(Username);

        return new User
        {
            Id = currentUser.Id,
            FirstName = currentUser.FirstName,
            LastName = currentUser.LastName,
            Email = currentUser.Email,
            Username = currentUser.Username,
            Password = currentUser.Password
        };
    }
using Diary.Models;
using Diary.Services;
using ReactiveUI;
using System;
using System.Reactive;
using System.Reactive.Linq;

namespace Diary.ViewModels;

public class LoginViewModel : ViewModelBase
{
    private Database _db;
    private Helpers _hp;
    private string _username;
    private string _password;
    private User _user;

    public LoginViewModel(Database db, Helpers hp)
    {
        _db = db;
        _hp = hp;

        IObservable<bool> usernameOk = this.WhenAnyValue(
            x => x.Username,
            x => !string.IsNullOrEmpty(x) && CheckUsername());

        IObservable<bool> passwordOk = this.WhenAnyValue(
            x => x.Password,
            x => !string.IsNullOrEmpty(x) && CheckPassword());
        IObservable<bool> okEnabled = passwordOk
            .Concat(usernameOk);

        Login = ReactiveCommand.Create(CreateUser, okEnabled);
        Exit = ReactiveCommand.Create(() => { });
    }

    public User CreateUser()
    {
        User currentUser = _db.GetUser(Username);

        return new User
        {
            Id = currentUser.Id,
            FirstName = currentUser.FirstName,
            LastName = currentUser.LastName,
            Email = currentUser.Email,
            Username = currentUser.Username,
            Password = currentUser.Password
        };
    }
in this file, I initialize the private Database _db; and in the main method of the class, LoginViewModel, I bring the database in as a parameter, and set _db = db; for use throughout the class as shown in the above code. This threw the error
Member 'Database.GetUser(string)' cannot be accessed with an instance reference; qualify it with a type name instead
Member 'Database.GetUser(string)' cannot be accessed with an instance reference; qualify it with a type name instead
. So i changed it to
Database.GetUser(...)
Database.GetUser(...)
and it seems to like it just fine. So my question is, what's the difference between
_db.GetUser()
_db.GetUser()
and
Database.GetUser()
Database.GetUser()
? 🤷‍♂️
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Not big issue just curious about warning in C#
C#CC# / help
2mo ago
✅ not understanding something about accessors
C#CC# / help
3y ago
❔ Learning C#, and curious about advanced return statements...
C#CC# / help
3y ago
✅ just a quick question about if, else, else if
C#CC# / help
2y ago