Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data / System / Data / OleDb / PropertyIDSet.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="PropertyIDSet.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
8
9 using System;
10 using System.Data;
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;
18
19 namespace System.Data.OleDb {
20
21     internal sealed class PropertyIDSet : DbBuffer {
22     
23         static private readonly int PropertyIDSetAndValueSize = ODB.SizeOf_tagDBPROPIDSET + ADP.PtrSize; // sizeof(tagDBPROPIDSET) + sizeof(int)
24         static private readonly int PropertyIDSetSize = ODB.SizeOf_tagDBPROPIDSET;
25
26         private int _count;
27
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) {
31             _count = 1;
32
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);
37
38             Marshal.WriteInt32(base.handle, ADP.PtrSize, /*propertyid count*/1);
39
40             ptr = ADP.IntPtrOffset(base.handle, ODB.OffsetOf_tagDBPROPIDSET_PropertySet);
41             Marshal.StructureToPtr(propertySet, ptr, false/*deleteold*/);
42
43             // write the propertyID at the same offset
44             Marshal.WriteInt32(base.handle, PropertyIDSetSize, propertyID);
45         }
46
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*/);
53             }
54         }
55
56         internal int Count {
57             get {
58                 return _count;
59             }
60         }
61     }
62 }