[英]How to detect if a property is numeric type in haxe?
我需要检测对象的属性是否为数字(Int或Float),我所拥有的是对象引用,属性名称为字符串
这是我的实现, compoent
是对象引用,但是没有用
public function IsNumeric():Bool
{
if (Std.is(Type.typeof(Reflect.getProperty(compoent, propertyName)), Int)) return true;
if (Std.is(Type.typeof(Reflect.getProperty(compoent, propertyName)), Float)) return true;
return false;
}
有人可以帮忙吗?
它比您尝试的要简单一些: Std.is( value, type )
class Test {
static function main(){
js.Lib.alert( Std.is("string", Int) );
js.Lib.alert( Std.is(0, Int) );
js.Lib.alert( Std.is(0.3, Int) );
js.Lib.alert( Std.is("string", Float) );
js.Lib.alert( Std.is(0, Float) );
js.Lib.alert( Std.is(0.3, Float) );
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.