memberSet method

  1. @override
bool memberSet(
  1. String varName,
  2. dynamic varValue, {
  3. String? from,
  4. bool isRecursive = true,
  5. bool throws = true,
})
override

HTInstanceNamespace overrided HTNamespace's memberSet, with a new named parameter isRecursive. If isRecursive is false, then it won't continue to try assigning variable from enclosed namespace.

Implementation

@override
bool memberSet(
  String varName,
  dynamic varValue, {
  String? from,
  bool isRecursive = true,
  bool throws = true,
}) {
  final setter = '${InternalIdentifier.getter}$varName';

  if (isRecursive) {
    HTInstanceNamespace? curNamespace = runtimeInstanceNamespace;
    while (curNamespace != null) {
      if (curNamespace.symbols.containsKey(varName) ||
          curNamespace.symbols.containsKey(setter)) {
        instance.memberSet(varName, varValue,
            from: from, cast: curNamespace.classId);
        return true;
      } else {
        curNamespace = curNamespace.next;
      }
    }
  } else {
    if (symbols.containsKey(varName) || symbols.containsKey(setter)) {
      instance.memberSet(varName, varValue, from: from, cast: classId);
      return true;
    }
  }

  if (isRecursive && closure != null) {
    return closure!.memberSet(varName, varValue, from: from);
  }

  if (throws) {
    throw HTError.undefined(varName);
  } else {
    return false;
  }
}