本文整理汇总了Python中pypy.translator.cli.dotnet.unbox函数的典型用法代码示例。如果您正苦于以下问题:Python unbox函数的具体用法?Python unbox怎么用?Python unbox使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unbox函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cli2py
def cli2py(space, b_obj):
# TODO: support other types and find the most efficient way to
# select the correct case
if b_obj is None:
return space.w_None
w_obj = unbox(b_obj, W_Root)
if w_obj is not None:
return w_obj # it's already a wrapped object!
b_type = b_obj.GetType()
if b_type == typeof(System.Int32):
intval = unbox(b_obj, ootype.Signed)
return space.wrap(intval)
elif b_type == typeof(System.Double):
floatval = unbox(b_obj, ootype.Float)
return space.wrap(floatval)
elif b_type == typeof(System.Boolean):
boolval = unbox(b_obj, ootype.Bool)
return space.wrap(boolval)
elif b_type == typeof(System.String):
strval = unbox(b_obj, ootype.String)
return space.wrap(strval)
else:
namespace, classname = split_fullname(b_type.ToString())
assemblyname = b_type.get_Assembly().get_FullName()
w_cls = load_cli_class(space, assemblyname, namespace, classname)
cliobj = W_CliObject(space, b_obj)
return wrapper_from_cliobj(space, w_cls, cliobj)
示例2: cli2py
def cli2py(space, b_obj):
# TODO: support other types and find the most efficient way to
# select the correct case
if b_obj is None:
return space.w_None
w_obj = unbox(b_obj, W_Root)
if w_obj is not None:
return w_obj # it's already a wrapped object!
b_type = b_obj.GetType()
if b_type == typeof(System.Int32):
intval = unbox(b_obj, ootype.Signed)
return space.wrap(intval)
elif b_type == typeof(System.Double):
floatval = unbox(b_obj, ootype.Float)
return space.wrap(floatval)
elif b_type == typeof(System.Boolean):
boolval = unbox(b_obj, ootype.Bool)
return space.wrap(boolval)
elif b_type == typeof(System.String):
strval = unbox(b_obj, ootype.String)
return space.wrap(strval)
else:
msg = "Can't convert object %s to Python" % str(b_obj.ToString())
raise OperationError(space.w_TypeError, space.wrap(msg))
示例3: fn
def fn():
const.xx = 42
obj = fieldinfo.GetValue(None)
# get the 'xx' field by using reflection
t = obj.GetType()
x_info = t.GetField('xx')
x_value = x_info.GetValue(obj)
return unbox(x_value, ootype.Signed)
示例4: revealconst
def revealconst(self, T):
assert isinstance(T, ootype.OOType)
return unbox(self.obj, T)