使用变量访问对象属性

时间:2019-07-07 07:43:55

标签: android kotlin

我想通过其名称动态访问类的属性。我知道使用反射可能。但我想知道Kotlin是否具有类似于Javascript的内容:

var mutualFriendsNames = db.Users
    .Where(u =>
        db.FriendShips.Any(f => f.FriendId == u.Id && f.UserId == 1) &&
        db.FriendShips.Any(f => f.FriendId == u.Id && f.UserId == 2))
    .Select(p => p.Name);

或者像在python中一样:

var mutualFriendsNames = db.Users
    .Where(u =>
        db.FriendShips.Any(f => 
            (f.FriendId == u.Id && f.UserId == 1) ||
            (f.FriendId == 1 && f.UserId == u.Id)) &&
        db.FriendShips.Any(f => 
            (f.FriendId == u.Id && f.UserId == 2) ||
            (f.FriendId == 2 && f.UserId == u.Id)))
    .Select(p => p.Name);

更新:

所以我想这是当前的方法,谢谢Syed Ahmed Jamil:

Object['propertyname'] = "new value"

0 个答案:

没有答案