當前位置: 首頁>>代碼示例>>Python>>正文


Python clr.AddReference方法代碼示例

本文整理匯總了Python中clr.AddReference方法的典型用法代碼示例。如果您正苦於以下問題:Python clr.AddReference方法的具體用法?Python clr.AddReference怎麽用?Python clr.AddReference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在clr的用法示例。


在下文中一共展示了clr.AddReference方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_tool

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def run_tool(self, cmd, args=""):
        import clr
        import System
        if is_netcoreapp:
            clr.AddReference("System.Diagnostics.Process")
        process = System.Diagnostics.Process()
        process.StartInfo.FileName = cmd
        process.StartInfo.Arguments = args
        process.StartInfo.CreateNoWindow = True
        process.StartInfo.UseShellExecute = False
        process.StartInfo.RedirectStandardInput = False
        process.StartInfo.RedirectStandardOutput = False
        process.StartInfo.RedirectStandardError = False
        process.Start()
        process.WaitForExit()
        return process.ExitCode 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:process_util.py

示例2: main

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def main():
    if len(sys.argv) != 2:
        print "Usage: ipy run_compiled.py <testfile.py>"
        sys.exit(-1)
    
    testName = sys.argv[1]
    
    print "Compiling ", testName ,"..."
    clr.CompileModules("compiledTest.dll", testName)    
    File.Move(testName, testName+".bak")    
    try:
        print "Running test from compiled binary..."    
        clr.AddReference("compiledTest")    
        __import__(Path.GetFileNameWithoutExtension(testName))    
    finally:
        File.Move(testName+".bak" , testName)
    
#-------------------------------------------------------------------------------------- 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:run_compiled.py

示例3: test_load_count

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def test_load_count(self):
        # verify loading an assembly updates the assembly-loaded count in the repr
        # if a new assembly gets loaded before this that contains System both numbers
        # need to be updated
        import clr, System
        before = repr(System)
        if is_netcoreapp:
            clr.AddReference('System.Drawing.Primitives')
        else:
            clr.AddReference('System.Drawing')
        after = repr(System)

        # Strip common substring from start and end
        start = 0; end = 1
        while before[start] == after[start]: start += 1
        while before[-end] == after[-end]: end += 1
        end -= 1;

        # what remains is an int - number of assemblies loaded.
        # The integer must have increased value by 1
        self.assertEqual(int(before[start:-end]) + 1, int(after[start:-end])) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:23,代碼來源:test_clrload.py

示例4: test_override_createparams

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def test_override_createparams():
        """verify we can override the CreateParams property and get the expected value from the base class"""
    
        clr.AddReference("System.Windows.Forms")
        from System.Windows.Forms import Label, Control
        
        for val in [20, 0xffff]:
            global called
            called = False
            class TransLabel(Label):
                def get_CreateParams(self):
                    global called
                    cp = super(TransLabel, self).CreateParams
                    cp.ExStyle = cp.ExStyle | val
                    called = True
                    return cp
                CreateParams = property(fget=get_CreateParams)
        
            a = TransLabel()
            AreEqual(called, True) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_privateBinding.py

示例5: test__3_registered_with_pia

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def test__3_registered_with_pia():
    run_tlbimp(scriptpw_path, "spwLib")
    run_register_com_component(scriptpw_path)
    clr.AddReference("spwLib.dll")
    
    from spwLib import PasswordClass    
    pc = PasswordClass()
        
    Assert('PasswordClass' in repr(pc))
    Assert('spwLib.PasswordClass' in pc.ToString())
    AreEqual(pc.__class__, PasswordClass)
        
    try: del pc.GetPassword
    except AttributeError: pass
    else: Fail("attribute 'GetPassword' of 'PasswordClass' object is read-only")
        
    _test_common_on_object(pc) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:scriptpw.py

示例6: test_indexing_value_types_cp20370

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def test_indexing_value_types_cp20370(self):
        import clr
        if is_netcoreapp:
            clr.AddReference("System.Drawing.Primitives")
        else:
            clr.AddReference("System.Drawing")
        from System.Drawing import Point

        p = Point(1,2)
        l = [None]
        l[0] = p
        self.assertEqual(id(l[0]), id(p))
        self.assertEqual(id(l[0]), id(p))

        x = {}
        x[p] = p
        self.assertEqual(id(list(x.iterkeys())[0]), id(p))
        self.assertEqual(id(list(x.itervalues())[0]), id(p))

        self.load_iron_python_test()

        from IronPythonTest import StructIndexable
        a = StructIndexable()
        a[0] = 1
        self.assertEqual(a[0], 1) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_regressions.py

示例7: test_cp23878

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def test_cp23878(self):
        import clr
        clr.AddReference("rowantest.delegatedefinitions")
        clr.AddReference("rowantest.typesamples")
        from Merlin.Testing import Delegate, Flag
        from time import sleep

        cwtm = Delegate.ClassWithTargetMethods()
        vi32d = Delegate.VoidInt32Delegate(cwtm.MVoidInt32)
        ar = vi32d.BeginInvoke(32, None, None)
        is_complete = False
        for i in xrange(100):
            sleep(1)
            if ar.IsCompleted:
                is_complete = True
                break
        self.assertTrue(is_complete)
        self.assertEqual(Flag.Value, 32) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_regressions.py

示例8: test_member_completion_com

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def test_member_completion_com(self):
        superConsole.SendKeys('outputRedirectStart{(}True{)}{ENTER}')
        superConsole.SendKeys('import clr{ENTER}')
        superConsole.SendKeys('import System{ENTER}')
        superConsole.SendKeys('clr.AddReference{(}"Microsoft.Office.Interop.Word"{)}{ENTER}')
        superConsole.SendKeys('import Microsoft.Office.Interop.Word{ENTER}')
        superConsole.SendKeys('wordapp = Microsoft.Office.Interop.Word.ApplicationClass{(}{)}{ENTER}')
        sleep(10) #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=24427
        superConsole.SendKeys('wordapp.Activ{TAB}{ENTER}')
        sleep(15) #http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=24427
        superConsole.SendKeys('outputRedirectStop{(}{)}{ENTER}')
        
        #Verification
        temp = getTestOutput()
        Assert(len(temp[0])==8, str(temp[0]))
        Assert(temp[0][6].startswith('<Microsoft.Scripting.ComInterop.DispCallable object at '), str(temp[0])) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:test_superconsole.py

示例9: test_a_override_patching

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def test_a_override_patching(self):
        from IronPythonTest import TestHelpers

        if is_netcoreapp:
            clr.AddReference("System.Dynamic.Runtime")
            clr.AddReference("System.Linq.Expressions")
        else:
            clr.AddReference("System.Core")

        # derive from object
        class x(object):
            pass
        
        # force creation of GetHashCode built-in function
        TestHelpers.HashObject(x())

        # derive from a type which overrides GetHashCode
        from System.Dynamic import InvokeBinder
        from System.Dynamic import CallInfo
        
        class y(InvokeBinder):
            def GetHashCode(self): return super(InvokeBinder, self).GetHashCode()
        
        # now the super call should work & should include the InvokeBinder new type
        TestHelpers.HashObject(y(CallInfo(0))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_cliclass.py

示例10: test_namespaceimport

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def test_namespaceimport(self):
        import clr
        tmp = self.temporary_dir
        if tmp not in sys.path:
            sys.path.append(tmp)

        code1 = "namespace TestNamespace { public class Test1 {} }"
        code2 = "namespace TestNamespace { public class Test2 {} }"

        test1_cs, test1_dll = os.path.join(tmp, 'testns1.cs'), os.path.join(tmp, 'testns1.dll')
        test2_cs, test2_dll = os.path.join(tmp, 'testns2.cs'), os.path.join(tmp, 'testns2.dll')

        self.write_to_file(test1_cs, code1)
        self.write_to_file(test2_cs, code2)

        self.assertEqual(self.run_csc("/nologo /target:library /out:"+ test1_dll + ' ' + test1_cs), 0)
        self.assertEqual(self.run_csc("/nologo /target:library /out:"+ test2_dll + ' ' + test2_cs), 0)

        clr.AddReference('testns1')
        import TestNamespace
        self.assertEqual(dir(TestNamespace), ['Test1'])
        clr.AddReference('testns2')
        # verify that you don't need to import TestNamespace again to see Test2
        self.assertEqual(dir(TestNamespace), ['Test1', 'Test2']) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:26,代碼來源:test_clrload.py

示例11: _

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def _():
    import sys
    if sys.platform == 'cli':
        import clr
        clr.AddReference('IronPython.SQLite') 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:7,代碼來源:__init__.py

示例12: _add_reference_to_dlr_core

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def _add_reference_to_dlr_core():
    if is_cli:
        clr.AddReference("System.Core") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:5,代碼來源:ipunittest.py

示例13: load_ironpython_test

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def load_ironpython_test(*args):
    _add_reference_to_dlr_core()
    clr.AddReference("Microsoft.Scripting")
    clr.AddReference("Microsoft.Dynamic")
    clr.AddReference("IronPython")

    if args: 
        return clr.LoadAssemblyFromFileWithPath(_iron_python_test_dll)
    else: 
        clr.AddReferenceToFileAndPath(_iron_python_test_dll) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:ipunittest.py

示例14: load_iron_python_dll

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def load_iron_python_dll(self):
        #When assemblies are installed into the GAC, we should not expect
        #IronPython.dll to exist alongside IronPython.dll
        if os.path.exists(os.path.join(sys.prefix, "IronPython.dll")):
            clr.AddReferenceToFileAndPath(os.path.join(sys.prefix, "IronPython.dll"))
        else:
            clr.AddReference("IronPython") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:9,代碼來源:ipunittest.py

示例15: add_clr_assemblies

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import AddReference [as 別名]
def add_clr_assemblies(self, *dlls):
        """Adds test assemblies as references"""
        import clr
        prefix = "rowantest."
        for x in dlls:
            if x.startswith(prefix):
                clr.AddReference(x)
            else:
                clr.AddReference(prefix + x) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:ipunittest.py


注:本文中的clr.AddReference方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。