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