当前位置: 首页>>代码示例>>Python>>正文


Python clr.GetClrType方法代码示例

本文整理汇总了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") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:clrtype.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:clrtype.py

示例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])) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:clrtype.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_missing.py

示例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() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_reachtype.py

示例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__) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_exceptions.py

示例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") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:23,代码来源:clrtype.py

示例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() 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:24,代码来源:test_reachtype.py

示例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 
开发者ID:bvn-architecture,项目名称:RevitBatchProcessor,代码行数:26,代码来源:win32_pinvoke.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:generate_alltypes.py

示例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]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:41,代码来源:generate_comdispatch.py

示例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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:clrtype.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:clrtype.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:clrtype.py

示例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 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_missing.py


注:本文中的clr.GetClrType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。