PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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
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
  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. * ***************************************************************************/
  15. using System; using Microsoft;
  16. #if !SILVERLIGHT // ComObject
  17. using Microsoft.Linq.Expressions;
  18. using System.Runtime.CompilerServices;
  19. using Microsoft.Runtime.CompilerServices;
  20. namespace Microsoft.Scripting.Com {
  21. // TODO: should this be an IDO?
  22. public sealed class BoundDispEvent {
  23. private object _rcw;
  24. private Guid _sourceIid;
  25. private int _dispid;
  26. internal BoundDispEvent(object rcw, Guid sourceIid, int dispid) {
  27. _rcw = rcw;
  28. _sourceIid = sourceIid;
  29. _dispid = dispid;
  30. }
  31. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates")] // TODO: fix
  32. [SpecialName]
  33. public object op_AdditionAssignment(object func) {
  34. return InPlaceAdd(func);
  35. }
  36. [SpecialName]
  37. public object InPlaceAdd(object func) {
  38. ComEventSink comEventSink = ComEventSink.FromRuntimeCallableWrapper(_rcw, _sourceIid, true);
  39. comEventSink.AddHandler(_dispid, func);
  40. return this;
  41. }
  42. [SpecialName]
  43. public object InPlaceSubtract(object func) {
  44. ComEventSink comEventSink = ComEventSink.FromRuntimeCallableWrapper(_rcw, _sourceIid, false);
  45. if (comEventSink == null) {
  46. throw Error.RemovingUnregisteredEvent();
  47. }
  48. comEventSink.RemoveHandler(_dispid, func);
  49. return this;
  50. }
  51. }
  52. }
  53. #endif