ModuleMarshaler.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #region MIT License
  2. /*Copyright (c) 2012 Robert Rouhani <robert.rouhani@gmail.com>
  3. SharpFont based on Tao.FreeType, Copyright (c) 2003-2007 Tao Framework Team
  4. Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. this software and associated documentation files (the "Software"), to deal in
  6. the Software without restriction, including without limitation the rights to
  7. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8. of the Software, and to permit persons to whom the Software is furnished to do
  9. so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.*/
  19. #endregion
  20. using System;
  21. using System.Runtime.InteropServices;
  22. namespace SharpFont.Internal
  23. {
  24. internal sealed class ModuleMarshaler : ICustomMarshaler
  25. {
  26. private static readonly ModuleMarshaler Instance = new ModuleMarshaler();
  27. private ModuleMarshaler()
  28. {
  29. }
  30. public static ICustomMarshaler GetInstance(string cookie)
  31. {
  32. return Instance;
  33. }
  34. public void CleanUpManagedData(object managedObj)
  35. {
  36. if (managedObj == null)
  37. throw new ArgumentNullException("managedObj");
  38. if (managedObj.GetType() != typeof(Module))
  39. throw new ArgumentException("Managed object is not a Module.");
  40. }
  41. public void CleanUpNativeData(IntPtr pNativeData)
  42. {
  43. //Do nothing.
  44. }
  45. public int GetNativeDataSize()
  46. {
  47. return 0;
  48. }
  49. public IntPtr MarshalManagedToNative(object managedObj)
  50. {
  51. if (managedObj == null)
  52. throw new ArgumentNullException("managedObj");
  53. if (managedObj.GetType() != typeof(Module))
  54. throw new ArgumentException("Managed object is not a Module.");
  55. //TODO if we have any setters in ListNode, marshal them.
  56. return ((Module)managedObj).Reference;
  57. }
  58. public object MarshalNativeToManaged(IntPtr pNativeData)
  59. {
  60. return new Module(pNativeData);
  61. }
  62. }
  63. }