Skip to content

Commit 8da0c8f

Browse files
committed
Implemented namespace overrides. Refactored away the Utiliities class and renamed ComArray -> InterfaceArray.
1 parent 13f9ecb commit 8da0c8f

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

ComObject.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
// THE SOFTWARE.
2020
using System;
21+
using System.Reflection;
2122
using System.Runtime.InteropServices;
2223
using SharpGen.Runtime.Diagnostics;
2324

@@ -98,7 +99,7 @@ public static bool EqualsComObject<T>(T left, T right) where T : ComObject
9899
public virtual T QueryInterface<T>() where T : ComObject
99100
{
100101
IntPtr parentPtr;
101-
this.QueryInterface(Utilities.GetGuidFromType(typeof(T)), out parentPtr);
102+
this.QueryInterface(typeof(T).GetTypeInfo().GUID, out parentPtr);
102103
return FromPointer<T>(parentPtr);
103104
}
104105

@@ -169,7 +170,7 @@ public static T QueryInterfaceOrNull<T>(IntPtr comPointer) where T : ComObject
169170
return null;
170171
}
171172

172-
var guid = Utilities.GetGuidFromType(typeof(T));
173+
var guid = typeof(T).GetTypeInfo().GUID;
173174
IntPtr pointerT;
174175
var result = (Result)Marshal.QueryInterface(comPointer, ref guid, out pointerT);
175176
return (result.Failure) ? null : FromPointer<T>(pointerT);
@@ -185,7 +186,7 @@ public static T QueryInterfaceOrNull<T>(IntPtr comPointer) where T : ComObject
185186
/// <unmanaged-short>IUnknown::QueryInterface</unmanaged-short>
186187
public virtual T QueryInterfaceOrNull<T>() where T : ComObject
187188
{
188-
return FromPointer<T>(QueryInterfaceOrNull(Utilities.GetGuidFromType(typeof(T))));
189+
return FromPointer<T>(QueryInterfaceOrNull(typeof(T).GetTypeInfo().GUID));
189190
}
190191

191192
///<summary>
@@ -196,7 +197,7 @@ public virtual T QueryInterfaceOrNull<T>() where T : ComObject
196197
protected void QueryInterfaceFrom<T>(T fromObject) where T : ComObject
197198
{
198199
IntPtr parentPtr;
199-
fromObject.QueryInterface(Utilities.GetGuidFromType(this.GetType()), out parentPtr);
200+
fromObject.QueryInterface(this.GetType().GetTypeInfo().GUID, out parentPtr);
200201
NativePointer = parentPtr;
201202
}
202203

InspectableShadow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private unsafe static int GetIids(IntPtr thisPtr, int* iidCount, IntPtr* iids)
6262
iids = (IntPtr*)Marshal.AllocCoTaskMem(IntPtr.Size * countGuids);
6363
*iidCount = countGuids;
6464

65-
Utilities.CopyMemory((IntPtr)iids, new Span<IntPtr>(container.Guids));
65+
MemoryHelpers.CopyMemory((IntPtr)iids, new Span<IntPtr>(container.Guids));
6666
}
6767
catch (Exception exception)
6868
{

Win32/ComStreamProxy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public unsafe uint Read(IntPtr buffer, uint numberOfBytesToRead)
4545
uint count = (uint)sourceStream.Read(tempBuffer, 0, (int)countRead);
4646
if (count == 0)
4747
return totalRead;
48-
Utilities.Write(new IntPtr(totalRead + (byte*)buffer), new Span<byte>(tempBuffer), (int)count);
48+
MemoryHelpers.Write(new IntPtr(totalRead + (byte*)buffer), new Span<byte>(tempBuffer), (int)count);
4949
numberOfBytesToRead -= count;
5050
totalRead += count;
5151
}
@@ -59,7 +59,7 @@ public unsafe uint Write(IntPtr buffer, uint numberOfBytesToWrite)
5959
while (numberOfBytesToWrite > 0)
6060
{
6161
uint countWrite = (uint)Math.Min(numberOfBytesToWrite, tempBuffer.Length);
62-
Utilities.Read(new IntPtr(totalWrite + (byte*)buffer), new Span<byte>(tempBuffer), (int)countWrite);
62+
MemoryHelpers.Read(new IntPtr(totalWrite + (byte*)buffer), new Span<byte>(tempBuffer), (int)countWrite);
6363
sourceStream.Write(tempBuffer, 0, (int)countWrite);
6464
numberOfBytesToWrite -= countWrite;
6565
totalWrite += countWrite;

Win32/Variant.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public unsafe object Value
9393
var buffer = new byte[(int)variantValue.recordValue.RecordInfo];
9494
if (buffer.Length > 0)
9595
{
96-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<byte>(buffer), buffer.Length);
96+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<byte>(buffer), buffer.Length);
9797
}
9898
return buffer;
9999
}
@@ -147,69 +147,69 @@ public unsafe object Value
147147
{
148148
var array = stackalloc RawBool[size];
149149
var span = new Span<RawBool>(array, size);
150-
Utilities.Read(variantValue.recordValue.RecordPointer, span, size);
150+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, span, size);
151151
return RawBoolHelpers.ConvertToBoolArray(span);
152152
}
153153
case VariantElementType.Byte:
154154
{
155155
var array = new sbyte[size];
156-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<sbyte>(array), size);
156+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<sbyte>(array), size);
157157
return array;
158158
}
159159
case VariantElementType.UByte:
160160
{
161161
var array = new byte[size];
162-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<byte>(array), size);
162+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<byte>(array), size);
163163
return array;
164164
}
165165
case VariantElementType.UShort:
166166
{
167167
var array = new ushort[size];
168-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<ushort>(array), size);
168+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<ushort>(array), size);
169169
return array;
170170
}
171171
case VariantElementType.Short:
172172
{
173173
var array = new short[size];
174-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<short>(array), size);
174+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<short>(array), size);
175175
return array;
176176
}
177177
case VariantElementType.UInt:
178178
case VariantElementType.UInt1:
179179
{
180180
var array = new uint[size];
181-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<uint>(array), size);
181+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<uint>(array), size);
182182
return array;
183183
}
184184
case VariantElementType.Int:
185185
case VariantElementType.Int1:
186186
{
187187
var array = new int[size];
188-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<int>(array), size);
188+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<int>(array), size);
189189
return array;
190190
}
191191
case VariantElementType.ULong:
192192
{
193193
var array = new ulong[size];
194-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<ulong>(array), size);
194+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<ulong>(array), size);
195195
return array;
196196
}
197197
case VariantElementType.Long:
198198
{
199199
var array = new long[size];
200-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<long>(array), size);
200+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<long>(array), size);
201201
return array;
202202
}
203203
case VariantElementType.Float:
204204
{
205205
var array = new float[size];
206-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<float>(array), size);
206+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<float>(array), size);
207207
return array;
208208
}
209209
case VariantElementType.Double:
210210
{
211211
var array = new double[size];
212-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<double>(array), size);
212+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<double>(array), size);
213213
return array;
214214
}
215215
case VariantElementType.BinaryString:
@@ -242,7 +242,7 @@ public unsafe object Value
242242
case VariantElementType.Pointer:
243243
{
244244
var array = new IntPtr[size];
245-
Utilities.Read(variantValue.recordValue.RecordPointer, new Span<IntPtr>(array), size);
245+
MemoryHelpers.Read(variantValue.recordValue.RecordPointer, new Span<IntPtr>(array), size);
246246
return array;
247247
}
248248
case VariantElementType.FileTime:

0 commit comments

Comments
 (0)