PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_2_0/Src/Microsoft.Scripting.Core/Com/BoundDispEvent.cs

#
C# | 64 lines | 38 code | 11 blank | 15 comment | 2 complexity | 3815981c238672888a0870b3d6460996 MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the  Microsoft Public License, please send an email to 
 8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Microsoft Public License.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15using System; using Microsoft;
16
17
18#if !SILVERLIGHT // ComObject
19
20using Microsoft.Linq.Expressions;
21using System.Runtime.CompilerServices;
22using Microsoft.Runtime.CompilerServices;
23
24
25namespace Microsoft.Scripting.Com {
26    // TODO: should this be an IDO?
27    public sealed class BoundDispEvent {
28        private object _rcw;
29        private Guid _sourceIid;
30        private int _dispid;
31
32        internal BoundDispEvent(object rcw, Guid sourceIid, int dispid) {
33            _rcw = rcw;
34            _sourceIid = sourceIid;
35            _dispid = dispid;
36        }
37
38        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates")]  // TODO: fix
39        [SpecialName]
40        public object op_AdditionAssignment(object func) {
41            return InPlaceAdd(func);
42        }
43
44        [SpecialName]
45        public object InPlaceAdd(object func) {
46            ComEventSink comEventSink = ComEventSink.FromRuntimeCallableWrapper(_rcw, _sourceIid, true);
47            comEventSink.AddHandler(_dispid, func);
48            return this;
49        }
50
51        [SpecialName]
52        public object InPlaceSubtract(object func) {
53            ComEventSink comEventSink = ComEventSink.FromRuntimeCallableWrapper(_rcw, _sourceIid, false);
54            if (comEventSink == null) {
55                throw Error.RemovingUnregisteredEvent();
56            }
57
58            comEventSink.RemoveHandler(_dispid, func);
59            return this;
60        }
61    }
62}
63
64#endif