/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
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
- /* ****************************************************************************
- *
- * Copyright (c) Microsoft Corporation.
- *
- * This source code is subject to terms and conditions of the Microsoft Public License. A
- * copy of the license can be found in the License.html file at the root of this distribution. If
- * you cannot locate the Microsoft Public License, please send an email to
- * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
- * by the terms of the Microsoft Public License.
- *
- * You must not remove this notice, or any other, from this software.
- *
- *
- * ***************************************************************************/
- using System; using Microsoft;
-
-
- #if !SILVERLIGHT // ComObject
-
- using Microsoft.Linq.Expressions;
- using System.Runtime.CompilerServices;
- using Microsoft.Runtime.CompilerServices;
-
-
- namespace Microsoft.Scripting.Com {
- // TODO: should this be an IDO?
- public sealed class BoundDispEvent {
- private object _rcw;
- private Guid _sourceIid;
- private int _dispid;
-
- internal BoundDispEvent(object rcw, Guid sourceIid, int dispid) {
- _rcw = rcw;
- _sourceIid = sourceIid;
- _dispid = dispid;
- }
-
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates")] // TODO: fix
- [SpecialName]
- public object op_AdditionAssignment(object func) {
- return InPlaceAdd(func);
- }
-
- [SpecialName]
- public object InPlaceAdd(object func) {
- ComEventSink comEventSink = ComEventSink.FromRuntimeCallableWrapper(_rcw, _sourceIid, true);
- comEventSink.AddHandler(_dispid, func);
- return this;
- }
-
- [SpecialName]
- public object InPlaceSubtract(object func) {
- ComEventSink comEventSink = ComEventSink.FromRuntimeCallableWrapper(_rcw, _sourceIid, false);
- if (comEventSink == null) {
- throw Error.RemovingUnregisteredEvent();
- }
-
- comEventSink.RemoveHandler(_dispid, func);
- return this;
- }
- }
- }
-
- #endif