PropertyIDSet.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //------------------------------------------------------------------------------
  2. // <copyright file="PropertyIDSet.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">[....]</owner>
  6. // <owner current="true" primary="false">[....]</owner>
  7. //------------------------------------------------------------------------------
  8. using System;
  9. using System.Data;
  10. using System.Data.Common;
  11. using System.Data.ProviderBase;
  12. using System.Diagnostics;
  13. using System.Runtime.InteropServices;
  14. using System.Runtime.CompilerServices;
  15. using System.Security;
  16. using System.Security.Permissions;
  17. namespace System.Data.OleDb {
  18. internal sealed class PropertyIDSet : DbBuffer {
  19. static private readonly int PropertyIDSetAndValueSize = ODB.SizeOf_tagDBPROPIDSET + ADP.PtrSize; // sizeof(tagDBPROPIDSET) + sizeof(int)
  20. static private readonly int PropertyIDSetSize = ODB.SizeOf_tagDBPROPIDSET;
  21. private int _count;
  22. // the PropertyID is stored at the end of the tagDBPROPIDSET structure
  23. // this way only a single memory allocation is required instead of two
  24. internal PropertyIDSet(Guid propertySet, int propertyID) : base(PropertyIDSetAndValueSize) {
  25. _count = 1;
  26. // rgPropertyIDs references where that PropertyID is stored
  27. // depending on IntPtr.Size, tagDBPROPIDSET is either 24 or 28 bytes long
  28. IntPtr ptr = ADP.IntPtrOffset(base.handle, PropertyIDSetSize);
  29. Marshal.WriteIntPtr(base.handle, 0, ptr);
  30. Marshal.WriteInt32(base.handle, ADP.PtrSize, /*propertyid count*/1);
  31. ptr = ADP.IntPtrOffset(base.handle, ODB.OffsetOf_tagDBPROPIDSET_PropertySet);
  32. Marshal.StructureToPtr(propertySet, ptr, false/*deleteold*/);
  33. // write the propertyID at the same offset
  34. Marshal.WriteInt32(base.handle, PropertyIDSetSize, propertyID);
  35. }
  36. // no propertyIDs, just the propertyset guids
  37. internal PropertyIDSet(Guid[] propertySets) : base(PropertyIDSetSize * propertySets.Length) {
  38. _count = propertySets.Length;
  39. for(int i = 0; i < propertySets.Length; ++i) {
  40. IntPtr ptr = ADP.IntPtrOffset(base.handle, (i * PropertyIDSetSize) + ODB.OffsetOf_tagDBPROPIDSET_PropertySet);
  41. Marshal.StructureToPtr(propertySets[i], ptr, false/*deleteold*/);
  42. }
  43. }
  44. internal int Count {
  45. get {
  46. return _count;
  47. }
  48. }
  49. }
  50. }