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


Python clr.StrongBox方法代碼示例

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


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

示例1: test_ref_params

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_ref_params():
    f1 = 3.5;
    a = StrongBox[float](f1)
    com_obj.mSingleRefParam(a)
    AreEqual(a.Value, f1+ 2)
    
    com_obj.mSingleRefParam(5.2)    
    	
    str1 = "a"
    a = StrongBox[str](str1)
    b = StrongBox[object](com_obj)
    com_obj.mTwoRefParams(a,b)
    AreEqual(a.Value, "a")
    AreEqual(b.Value, com_obj)
    
#Try passing null to methods which accept pointers. TypeError should be thrown for all except strings 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:18,代碼來源:InOutParams.py

示例2: test_iterator_dispose

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_iterator_dispose(self):
        # getting an enumerator from an enumerable should dispose the new enumerator
        from IronPythonTest import EnumerableTest, MyEnumerator
        box = clr.StrongBox[bool](False)
        ietest = EnumerableTest(box)
        for x in ietest:
            pass
            
        self.assertEqual(box.Value, True)
        
        # enumerating on an enumerator shouldn't dispose the box
        box = clr.StrongBox[bool](False)
        ietest = MyEnumerator(box)
        for x in ietest:
            pass
            
        self.assertEqual(box.Value, False) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_cliclass.py

示例3: test_system_drawing

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_system_drawing(self):
        import clr
        if is_netcoreapp:
            clr.AddReference("System.Drawing.Primitives")
        else:
            clr.AddReference("System.Drawing")
        from System.Drawing import Rectangle
        r = Rectangle(0, 0, 3, 7)
        s = Rectangle(3, 0, 8, 14)
        
        # calling the static method
        i = Rectangle.Intersect(r, s)
        self.assertEqual(i, Rectangle(3, 0, 0, 7))
        self.assertEqual(r, Rectangle(0, 0, 3, 7))
        self.assertEqual(s, Rectangle(3, 0, 8, 14))
        
        # calling the instance
        i = r.Intersect(s)
        self.assertEqual(i, None)
        self.assertEqual(r, Rectangle(3, 0, 0, 7))
        self.assertEqual(s, Rectangle(3, 0, 8, 14))
        
        # calling instance w/ StrongBox
        r = Rectangle(0, 0, 3, 7)
        box = clr.StrongBox[Rectangle](r)
        i = box.Intersect(s)
        self.assertEqual(i, None)
        self.assertEqual(box.Value, Rectangle(3, 0, 0, 7))
        self.assertEqual(s, Rectangle(3, 0, 8, 14))
        
        # should be able to access properties through the box
        self.assertEqual(box.X, 3)
        
        # multiple sites should produce the same function
        i = box.Intersect
        j = box.Intersect 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:38,代碼來源:test_methoddispatch.py

示例4: test_ref_bytearr

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_ref_bytearr(self):
        from IronPythonTest.BinderTest import COtherConcern, Flag
        import clr
        self.target = COtherConcern()
        
        arr = System.Array[System.Byte]((2,3,4))
        
        res = self.target.M702(arr)
        self.assertEqual(Flag.Value, 702)
        self.assertEqual(type(res), System.Array[System.Byte])
        self.assertEqual(len(res), 0)
        
        i, res = self.target.M703(arr)
        self.assertEqual(Flag.Value, 703)
        self.assertEqual(i, 42)
        self.assertEqual(type(res), System.Array[System.Byte])
        self.assertEqual(len(res), 0)
        
        i, res = self.target.M704(arr, arr)
        self.assertEqual(Flag.Value, 704)
        self.assertEqual(i, 42)
        self.assertEqual(arr, res)
        
        sarr = clr.StrongBox[System.Array[System.Byte]](arr)
        res = self.target.M702(sarr)
        self.assertEqual(Flag.Value, 702)
        self.assertEqual(res, None)
        res = sarr.Value
        self.assertEqual(type(res), System.Array[System.Byte])
        self.assertEqual(len(res), 0)
        
        sarr.Value = arr
        i = self.target.M703(sarr)
        self.assertEqual(Flag.Value, 703)
        self.assertEqual(i, 42)
        self.assertEqual(len(sarr.Value), 0)
        
        i = self.target.M704(arr, sarr)
        self.assertEqual(Flag.Value, 704)
        self.assertEqual(i, 42)
        self.assertEqual(sarr.Value, arr) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:43,代碼來源:test_methodbinder1.py

示例5: test_properties_param

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_properties_param():
    com_obj.PropertyWithParam[20] = 42
    AreEqual(com_obj.PropertyWithParam[0], 62)
    AreEqual(com_obj.PropertyWithParam[20], 42)
    
    strongVar = StrongBox[str]("a")
    com_obj.PropertyWithOutParam[strongVar] = "abcd"
    AreEqual(com_obj.PropertyWithOutParam[strongVar], "abcd")
    AreEqual(strongVar.Value, "abcd")
    
    com_obj.PropertyWithTwoParams[2, 2] = 2
    AreEqual(com_obj.PropertyWithTwoParams[0, 0], 6)
    AreEqual(com_obj.PropertyWithTwoParams[2,2], 2)
  
#Validate that one is able to call default properties with indexers. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:properties.py

示例6: test_optional_out_params

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_optional_out_params():
    b = StrongBox[object]()
    com_obj.mOptionalOutParam("a", b)
    AreEqual(b.Value, "a")
    com_obj.mOptionalOutParam("a") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:OptionalParams.py

示例7: test_python_keyword_syntax

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_python_keyword_syntax():
    com_obj.mSingleOptionalParam(a="a")
    com_obj.mOneOptionalParam("a", b="b")
    com_obj.mTwoOptionalParams("a", b=32.0)
    com_obj.mTwoOptionalParams("a", c=32.0)
    com_obj.mTwoOptionalParams("a", c=32.0, b="b")
    com_obj.mOptionalParamWithDefaultValue(3, b=5)
    #test out params with the keyword syntax
    strongObject = StrongBox[object]()
    com_obj.mOptionalOutParam("a", b=strongObject)
    AreEqual(strongObject.Value, "a")
    #test types with the keyword syntax
    
    AreEqual(com_obj.mOptionalStringParam(a="a"), "a")
    AreEqual(com_obj.mOptionalIntParam(a=3), 3) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:OptionalParams.py

示例8: callMethodWithStrongBox

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def callMethodWithStrongBox(func, arg, outparamType):
    strongArg = StrongBox[outparamType]()
    func(arg, strongArg)
    return strongArg.Value
#--------------------------------------------------------------------------------- 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:OutParams.py

示例9: test_sanity

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_sanity():
    for test_data in simple_primitives_data:
        testFunctionName = test_data[0]
        testType = test_data[1]
        testValue = test_data[2]

        testFunction = getattr(com_obj, testFunctionName)
        strongBox = StrongBox[testType]()
        testFunction(testValue, strongBox)
        AreEqual(strongBox.Value, testValue)
        
        testFunction(1, strongBox)
        AreEqual(strongBox.Value, 1)
        
        testFunction(0, strongBox)
        AreEqual(strongBox.Value, 0)
    
    AreEqual(callMethodWithStrongBox(com_obj.mBstr, "Hello", str), "Hello")
    
    #Interface Types    
    strongVar = StrongBox[object](DispatchWrapper(None))
    com_obj.mIDispatch(com_obj, strongVar)
    AreEqual(strongVar.Value.WrappedObject, com_obj)

    strongVar = StrongBox[object](UnknownWrapper(None))
    com_obj.mIUnknown(com_obj, strongVar)
    AreEqual(strongVar.Value.WrappedObject, com_obj)    
    
    #Complex Types
    strongVar = StrongBox[object](CurrencyWrapper(444))
    com_obj.mCy(CurrencyWrapper(123), strongVar)
    AreEqual(strongVar.Value.WrappedObject, 123)    
    
    now = DateTime.Now
    AreEqual(str(callMethodWithStrongBox(com_obj.mDate, now, DateTime)), str(now))        
        
    AreEqual(callMethodWithStrongBox(com_obj.mVariant, Single(2.0), object), 2.0) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:39,代碼來源:OutParams.py

示例10: test_types

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_types():
    for funcName, type, inp, output in simple_primitives_data:        
        func = getattr(com_obj, funcName)
        strongBoxVar = StrongBox[type](inp)
        func(strongBoxVar)
        AreEqual(strongBoxVar.Value, output)
        
    strongBoxIDisp = StrongBox[object](com_obj)    
    com_obj.mIDispatch(strongBoxIDisp);
    AreEqual(strongBoxIDisp.Value, com_obj)
    
#Test different signatures of the functions 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:InOutParams.py

示例11: test_calling_signatures

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_calling_signatures():
    f1 = 2.5;
    f2 = 5.5;
    a = StrongBox[float](f1)
    b = StrongBox[float](f2)
    com_obj.mTwoInOutParams(a,b) #The function adds two to every parameter
    AreEqual(a.Value, f1+2) 
    AreEqual(b.Value, f1 + f2+2)
    
    now = System.DateTime.Now
    a = StrongBox[System.DateTime](now)
    b = StrongBox[System.DateTime](now)
    com_obj.mOutAndInOutParams(a,b)
    
#Try calling the COM function with params passed in as if they were in params. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:InOutParams.py

示例12: test_sanity_int_types_broken

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_sanity_int_types_broken():
    a = StrongBox[ErrorWrapper](ErrorWrapper(System.Int32.MinValue))
    AreEqual(com_obj.mScode(a), System.Int32.MinValue)
    
    a = ErrorWrapper(5)
    AreEqual(com_obj.mScode(a), 5)
    
    AssertErrorWithMessage(ValueError, "Could not convert argument 0 for call to mScode.",
                           com_obj.mScode, 0)
    
        
###############################################################################
##SIMPLE TYPES################################################################# 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:paramsinretval.py

示例13: setUp

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def setUp(self):
        super(CtorOverrideTest, self).setUp()
        from System import Array
        from clr import StrongBox
        self.box_int = StrongBox[int]
        self.array_int = Array[int]

        self.add_clr_assemblies("baseclasscs", "typesamples") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_ctor_override.py

示例14: setUp

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def setUp(self):
        super(MethodSignatureTest, self).setUp()
        from clr import StrongBox

        self.add_clr_assemblies("baseclasscs", "typesamples")
        self.box_int = StrongBox[int] 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:8,代碼來源:test_method_signature.py

示例15: test_instantiation

# 需要導入模塊: import clr [as 別名]
# 或者: from clr import StrongBox [as 別名]
def test_instantiation(self):
        import clr
        from Merlin.Testing.Delegate import ClassWithTargetMethods, VoidInt32Delegate, VoidVoidDelegate
        d = VoidInt32Delegate
        x = ClassWithTargetMethods()

        # positive
        y = d(x.MVoidInt32)
        y(3)
        y = d(x.MVoidByte)
        y(3)
        y = d(x.MVoidDouble)
        y(3.234)

        # negative
        y = d(x.MInt32Void)
        self.assertRaises(TypeError, y)
        
        y = d(x.MVoidInt32Int32)
        self.assertRaises(TypeError, y, 1, 2)
        
        # need more scenario coverage
        y = d(x.MVoidRefInt32)
        y(2)
        
        y = d(x.MVoidOutInt32)
        z = clr.StrongBox[int](2)
        #y(z)
        
        d = VoidVoidDelegate
        y = d(x.MVoidOutInt32)
        y() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:34,代碼來源:test_delegate.py


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