C #: is there a way to make creating getters and setters automatic?

I am writing a Mongo web application using their official C # driver.

To implement links, they must be loaded manually.

so let's say that

class User {
    ...
    public MongoDBRef Topic { get; set; }
}

To get the topic, we need to do the following:

db.FetchDBRefAs<Topic>(user.Topic);

And to create a new one:

user.Topic = new MongoDBRef(TopicsTable, topic._id);

I decided to create a virtual property to make it more convenient:

    [BsonIgnore]
    public Topic _Topic
    {
        get
        {
            return db.FetchDBRefAs<Topic>(Topic);
        }
        set
        {
            CreatedAd = new MongoDBRef(TopicsTable, value._id);
        }
    }

Now I can use it as follows:

 user._Topic = someTopic;
 anotherTopic = user._Topic;

Obviously, this is a big pain to do this for all referenced objects.

Is there a way to make this process automatic?

thank

+3
source share
2 answers

Visual Studio, . , , , .

+5

Visual Studio.

prop , .

(propfull), (propg) - , (ctor).

.

+3

Source: https://habr.com/ru/post/1788464/


All Articles