encapsulate method
Encapsulate any value to a Hetu object, for members accessing and type check.
Implementation
HTEntity encapsulate(dynamic object) {
if (object is HTEntity) {
return object;
} else if (object == null) {
return HTEntity.nullValue;
}
late String typeString;
if (object is bool) {
typeString = _lexicon.typeBoolean;
} else if (object is int) {
typeString = _lexicon.typeInteger;
} else if (object is double) {
typeString = _lexicon.typeFloat;
} else if (object is String) {
typeString = _lexicon.typeString;
} else if (object is List) {
typeString = 'List';
// var valueType = HTType.ANY;
// if (object.isNotEmpty) {
// valueType = encapsulate(object.first).valueType;
// for (final item in object) {
// final value = encapsulate(item).valueType;
// if (value.isNotA(valueType)) {
// valueType = HTType.ANY;
// break;
// }
// }
// }
// return HTList(object, this, valueType: valueType);
} else if (object is Set) {
typeString = 'Set';
} else if (object is Map) {
typeString = 'Map';
// var keyType = HTType.ANY;
// var valueType = HTType.ANY;
// if (object.keys.isNotEmpty) {
// keyType = encapsulate(object.keys.first).valueType;
// for (final item in object.keys) {
// final value = encapsulate(item).valueType;
// if (value.isNotA(keyType)) {
// keyType = HTType.ANY;
// break;
// }
// }
// }
// if (object.values.isNotEmpty) {
// valueType = encapsulate(object.values.first).valueType;
// for (final item in object.values) {
// final value = encapsulate(item).valueType;
// if (value.isNotA(valueType)) {
// valueType = HTType.ANY;
// break;
// }
// }
// }
// return HTMap(object, this, keyType: keyType, valueType: valueType);
} else if (object is Iterable) {
typeString = 'Iterable';
} else if (object is Iterator) {
typeString = 'Iterator';
} else if (object is math.Random) {
typeString = 'Random';
} else {
var reflected = false;
for (final reflect in externTypeReflection) {
final result = reflect(object);
if (result != null) {
reflected = true;
typeString = result;
break;
}
}
if (!reflected) {
typeString = object.runtimeType.toString();
typeString = _lexicon.getBaseTypeId(typeString);
}
}
return HTExternalInstance(object, this, typeString);
}