本文整理匯總了Python中clr.GetClrType方法的典型用法代碼示例。如果您正苦於以下問題:Python clr.GetClrType方法的具體用法?Python clr.GetClrType怎麽用?Python clr.GetClrType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類clr
的用法示例。
在下文中一共展示了clr.GetClrType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: validate_clr_types
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def validate_clr_types(signature_types, var_signature = False):
if not isinstance(signature_types, tuple):
signature_types = (signature_types,)
for t in signature_types:
if type(t) is type(System.IComparable): # type overloaded on generic arity, eg IComparable and IComparable[T]
t = t[()] # select non-generic version
clr_type = clr.GetClrType(t)
if t == Void:
raise TypeError("Void cannot be used in signature")
is_typed = clr.GetPythonType(clr_type) == t
# is_typed needs to be weakened until the generated type
# gets explicitly published as the underlying CLR type
is_typed = is_typed or (hasattr(t, "__metaclass__") and t.__metaclass__ in [ClrInterface, ClrClass])
if not is_typed:
raise Exception, "Invalid CLR type %s" % str(t)
if not var_signature:
if clr_type.IsByRef:
raise TypeError("Byref can only be used as arguments and locals")
# ArgIterator is not present in Silverlight
if hasattr(System, "ArgIterator") and t == System.ArgIterator:
raise TypeError("Stack-referencing types can only be used as arguments and locals")
示例2: add_wrapper_ctors
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def add_wrapper_ctors(self, baseType, typebld):
python_type_field = self.emit_python_type_field(typebld)
for ctor in baseType.GetConstructors():
ctorparams = ctor.GetParameters()
# leave out the PythonType argument
assert(ctorparams[0].ParameterType == clr.GetClrType(PythonType))
ctorparams = ctorparams[1:]
ctorbld = typebld.DefineConstructor(
ctor.Attributes,
ctor.CallingConvention,
tuple([p.ParameterType for p in ctorparams]))
ilgen = ctorbld.GetILGenerator()
ilgen.Emit(OpCodes.Ldarg, 0)
ilgen.Emit(OpCodes.Ldsfld, python_type_field)
for index in xrange(len(ctorparams)):
ilgen.Emit(OpCodes.Ldarg, index + 1)
ilgen.Emit(OpCodes.Call, ctor)
ilgen.Emit(OpCodes.Ret)
示例3: make_cab
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def make_cab(attrib_type, *args, **kwds):
clrtype = clr.GetClrType(attrib_type)
argtypes = tuple(map(lambda x:clr.GetClrType(type(x)), args))
ci = clrtype.GetConstructor(argtypes)
props = ([],[])
fields = ([],[])
for kwd in kwds:
pi = clrtype.GetProperty(kwd)
if pi is not None:
props[0].append(pi)
props[1].append(kwds[kwd])
else:
fi = clrtype.GetField(kwd)
if fi is not None:
fields[0].append(fi)
fields[1].append(kwds[kwd])
else:
raise TypeError("No %s Member found on %s" % (kwd, clrtype.Name))
return CustomAttributeBuilder(ci, args,
tuple(props[0]), tuple(props[1]),
tuple(fields[0]), tuple(fields[1]))
示例4: CreateAssemblyGenerator
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def CreateAssemblyGenerator(path, name):
dir = IO.Path.GetDirectoryName(path)
file = IO.Path.GetFileName(path)
aname = Reflection.AssemblyName(name)
domain = System.AppDomain.CurrentDomain
ab = domain.DefineDynamicAssembly(aname, Emit.AssemblyBuilderAccess.RunAndSave, dir, None)
mb = ab.DefineDynamicModule(file, file, True);
ab.DefineVersionInfoResource()
constructor = clr.GetClrType(Diagnostics.DebuggableAttribute).GetConstructor(MakeArray(System.Type, clr.GetClrType(Diagnostics.DebuggableAttribute.DebuggingModes)))
attributeValue = MakeArray(System.Object,
Diagnostics.DebuggableAttribute.DebuggingModes.Default |
Diagnostics.DebuggableAttribute.DebuggingModes.DisableOptimizations |
Diagnostics.DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints
)
cab = Emit.CustomAttributeBuilder(constructor, attributeValue)
ab.SetCustomAttribute(cab)
mb.SetCustomAttribute(cab)
return AssemblyGenerator(file, ab, mb, None)
示例5: test_type_from_reflection_emit
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def test_type_from_reflection_emit(self):
import clr
import System
if is_netcoreapp:
clr.AddReference("System.Reflection.Emit")
sr = System.Reflection
sre = System.Reflection.Emit
array = System.Array
cab = array[sre.CustomAttributeBuilder]([sre.CustomAttributeBuilder(clr.GetClrType(System.Security.SecurityTransparentAttribute).GetConstructor(System.Type.EmptyTypes), array[object]([]))])
if is_netcoreapp: # no System.AppDomain.DefineDynamicAssembly
ab = sre.AssemblyBuilder.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.Run, cab) # tracking: 291888
else:
ab = System.AppDomain.CurrentDomain.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.RunAndSave, "temp", None, None, None, None, True, cab) # tracking: 291888
mb = ab.DefineDynamicModule("temp", "temp.dll")
tb = mb.DefineType("EmittedNS.EmittedType", sr.TypeAttributes.Public)
tb.CreateType()
clr.AddReference(ab)
import EmittedNS
EmittedNS.EmittedType()
示例6: test_serializable_clionly
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def test_serializable_clionly(self):
import clr
import System
from IronPythonTest import ExceptionsTest
path = clr.GetClrType(ExceptionsTest).Assembly.Location
mbro = System.AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap(path, "IronPythonTest.EngineTest")
self.assertRaises(AssertionError, mbro.Run, 'raise AssertionError')
import exceptions
for eh in dir(exceptions):
eh = getattr(exceptions, eh)
if isinstance(eh, type) and issubclass(eh, BaseException):
# unicode exceptions require more args...
if (eh.__name__ != 'UnicodeDecodeError' and
eh.__name__ != 'UnicodeEncodeError' and
eh.__name__ != 'UnicodeTranslateError'):
self.assertRaises(eh, mbro.Run, 'raise ' + eh.__name__)
示例7: validate_clr_types
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def validate_clr_types(signature_types, var_signature = False):
if not isinstance(signature_types, tuple):
signature_types = (signature_types,)
for t in signature_types:
if type(t) is type(System.IComparable): # type overloaded on generic arity, eg IComparable and IComparable[T]
t = t[()] # select non-generic version
clr_type = clr.GetClrType(t)
if t == Void:
raise TypeError("Void cannot be used in signature")
is_typed = clr.GetPythonType(clr_type) == t
# is_typed needs to be weakened until the generated type
# gets explicitly published as the underlying CLR type
is_typed = is_typed or (hasattr(t, "__metaclass__") and t.__metaclass__ in [ClrInterface, ClrClass])
if not is_typed:
raise Exception("Invalid CLR type %s" % str(t))
if not var_signature:
if clr_type.IsByRef:
raise TypeError("Byref can only be used as arguments and locals")
# ArgIterator is not present in Silverlight
if hasattr(System, "ArgIterator") and t == System.ArgIterator:
raise TypeError("Stack-referencing types can only be used as arguments and locals")
示例8: test_type_from_reflection_emit
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def test_type_from_reflection_emit(self):
import clr
import System
if is_netcoreapp:
clr.AddReference("System.Reflection.Emit")
sr = System.Reflection
sre = System.Reflection.Emit
array = System.Array
cab = array[sre.CustomAttributeBuilder]([sre.CustomAttributeBuilder(clr.GetClrType(System.Security.SecurityTransparentAttribute).GetConstructor(System.Type.EmptyTypes), array[object]([]))])
if is_netcoreapp: # no System.AppDomain.DefineDynamicAssembly
ab = sre.AssemblyBuilder.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.Run, cab) # tracking: 291888
else:
ab = System.AppDomain.CurrentDomain.DefineDynamicAssembly(sr.AssemblyName("temp"), sre.AssemblyBuilderAccess.RunAndSave, "temp", None, None, None, None, True, cab) # tracking: 291888
mb = ab.DefineDynamicModule("temp", "temp.dll")
tb = mb.DefineType("EmittedNS.EmittedType", sr.TypeAttributes.Public)
tb.CreateType()
clr.AddReference(ab)
import EmittedNS
EmittedNS.EmittedType()
示例9: GetWinApiFunctionImpl
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def GetWinApiFunctionImpl(
functionName,
moduleName,
charSet,
returnType,
*parameterTypes
):
tbuilder = MODULE_BUILDER.DefineType("WIN_API_TYPE" + "_" + moduleName + "_" + functionName)
mbuilder = tbuilder.DefinePInvokeMethod(
functionName,
moduleName,
PINVOKE_METHOD_ATTRIBUTES,
Refl.CallingConventions.Standard,
clr.GetClrType(returnType),
[clr.GetClrType(t) for t in parameterTypes].ToArray[System.Type](),
WIN_API_CALLING_CONVENTION,
charSet
)
mbuilder.SetImplementationFlags(mbuilder.MethodImplementationFlags | Refl.MethodImplAttributes.PreserveSig)
winApiType = tbuilder.CreateType()
methodInfo = winApiType.GetMethod(functionName, PUBLIC_STATIC_BINDING_FLAGS)
def WinApiFunction(*parameters):
return methodInfo.Invoke(None, parameters.ToArray[System.Object]())
return WinApiFunction
示例10: __init__
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def __init__(self, type):
self.name = clr.GetClrType(type).Name
self.type = type
self.ops = self.name+"Ops"
self.min, self.max = get_min_max(type)
self.is_signed = self.min < 0
self.size = self.max-self.min + 1
self.is_float = (self.type(1)/self.type(2) != 0)
示例11: gen_ManagedToComPrimitiveTypes
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def gen_ManagedToComPrimitiveTypes(cw):
import System
import clr
# build inverse map
type_map = {}
for variantType in variantTypes:
# take them in order, first one wins ... handles ERROR and INT32 conflict
if variantType.isPrimitiveType and not type_map.has_key(variantType.managedType):
type_map[variantType.managedType] = variantType.variantType
for managedType, variantType in managed_types_to_variant_types_add:
type_map[managedType] = variantType
def is_system_type(name):
t = getattr(System, name, None)
return t and System.Type.GetTypeCode(t) not in [System.TypeCode.Empty, System.TypeCode.Object]
system_types = filter(is_system_type, type_map.keys())
system_types = sorted(system_types, cmp, lambda name: int(System.Type.GetTypeCode(getattr(System, name))))
other_types = sorted(set(type_map.keys()).difference(set(system_types)))
# switch from sytem types
cw.enter_block("switch (Type.GetTypeCode(argumentType))")
for t in system_types:
cw.write("""case TypeCode.%(code)s:
primitiveVarEnum = VarEnum.VT_%(vt)s;
return true;""", code = System.Type.GetTypeCode(getattr(System, t)).ToString(), vt = type_map[t])
cw.exit_block()
# if statements from the rest
for t in other_types:
clrtype = getattr(System, t, None)
if not clrtype: clrtype = getattr(System.Runtime.InteropServices, t, None)
clrtype = clr.GetClrType(clrtype)
cw.write("""
if (argumentType == typeof(%(type)s)) {
primitiveVarEnum = VarEnum.VT_%(vt)s;
return true;
}""", type = clrtype.Name, vt = type_map[t])
示例12: get_typed_properties
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def get_typed_properties(self):
for item_name, item in self.__dict__.items():
if isinstance(item, property):
if item.fget:
if not self.is_typed_method(item.fget): continue
prop_type = item.fget.return_type
else:
if not self.is_typed_method(item.fset): continue
prop_type = item.fset.arg_types[0]
validate_clr_types(prop_type)
clr_prop_type = clr.GetClrType(prop_type)
yield item, item_name, clr_prop_type
示例13: emit_classattribs
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def emit_classattribs(self, typebld):
if hasattr(self, '_clrclassattribs'):
for attrib_info in self._clrclassattribs:
if isinstance(attrib_info, type):
ci = clr.GetClrType(attrib_info).GetConstructor(())
cab = CustomAttributeBuilder(ci, ())
elif isinstance(attrib_info, CustomAttributeDecorator):
cab = attrib_info.GetBuilder()
else:
make_decorator = attrib_info()
cab = make_decorator.GetBuilder()
typebld.SetCustomAttribute(cab)
示例14: emit_fields
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def emit_fields(self, typebld):
if hasattr(self, "_clrfields"):
for fldname in self._clrfields:
field_type = self._clrfields[fldname]
validate_clr_types(field_type)
typebld.DefineField(
fldname,
clr.GetClrType(field_type),
FieldAttributes.Public)
示例15: MakeArray
# 需要導入模塊: import clr [as 別名]
# 或者: from clr import GetClrType [as 別名]
def MakeArray(type, *values):
a = System.Array.CreateInstance(clr.GetClrType(type), len(values))
for i in range(len(values)):
a[i] = values[i]
return a