diff --git a/nuget/Microsoft.Windows.CsWinRT.targets b/nuget/Microsoft.Windows.CsWinRT.targets
index 7a5dcf1f8..043188691 100644
--- a/nuget/Microsoft.Windows.CsWinRT.targets
+++ b/nuget/Microsoft.Windows.CsWinRT.targets
@@ -199,6 +199,7 @@ $(CsWinRTInternalProjection)
+
diff --git a/src/Tests/UnitTest/TestComponentCSharp_Tests.cs b/src/Tests/UnitTest/TestComponentCSharp_Tests.cs
index ace0ced14..e7e8cbcca 100644
--- a/src/Tests/UnitTest/TestComponentCSharp_Tests.cs
+++ b/src/Tests/UnitTest/TestComponentCSharp_Tests.cs
@@ -30,6 +30,7 @@
using Windows.Devices.Enumeration.Pnp;
using System.Diagnostics;
using Windows.Devices.Enumeration;
+using Windows.UI.Notifications;
#if NET
using WeakRefNS = System;
@@ -76,12 +77,12 @@ public void TestLongClassNameEventSource()
[Fact]
public void TestEventArgsVector()
- {
+ {
var eventArgsVector = TestObject.GetEventArgsVector();
Assert.Equal(1, eventArgsVector.Count);
foreach (var dataErrorChangedEventArgs in eventArgsVector)
{
- var propName = dataErrorChangedEventArgs.PropertyName;
+ var propName = dataErrorChangedEventArgs.PropertyName;
Assert.Equal("name", propName);
}
}
@@ -92,7 +93,7 @@ public void TestNonGenericDelegateVector()
var provideUriVector = TestObject.GetNonGenericDelegateVector();
Assert.Equal(1, provideUriVector.Count);
-
+
foreach (var provideUri in provideUriVector)
{
Uri delegateTarget = provideUri.Invoke();
@@ -197,11 +198,11 @@ public void TestManyBufferExtensionMethods()
Assert.True(buffLen4.Length == 4);
Assert.Throws(() => buffLen4.GetByte(5)); // shouldn't have a 5th element
Assert.True(buffLen4.GetByte(0) == 0x02); // make sure we got the 2nd element of the array
-
+
arrayLen3.CopyTo(buffLen4); // Array to Buffer copying
Assert.True(buffLen4.Length == 4);
Assert.True(buffLen4.GetByte(0) == 0x01); // make sure we updated the first few
- Assert.True(buffLen4.GetByte(1) == 0x02);
+ Assert.True(buffLen4.GetByte(1) == 0x02);
Assert.True(buffLen4.GetByte(2) == 0x03);
Assert.True(buffLen4.GetByte(3) == 0x14); // and kept the last one
@@ -263,14 +264,14 @@ public void TestIsSameDataUsingToArray()
public void TestBufferAsStreamUsingAsBuffer()
{
var arr = new byte[] { 0x01, 0x02 };
- Stream stream = arr.AsBuffer().AsStream();
+ Stream stream = arr.AsBuffer().AsStream();
Assert.True(stream != null);
Assert.True(stream.Length == 2);
}
[Fact]
public void TestBufferAsStreamWithEmptyBuffer1()
- {
+ {
var buffer = new Windows.Storage.Streams.Buffer(0);
Stream stream = buffer.AsStream();
Assert.True(stream != null);
@@ -392,7 +393,7 @@ public void TestWinRTBufferWithZeroLength()
[Fact]
public void TestEmptyBufferCopyTo()
- {
+ {
var buffer = new Windows.Storage.Streams.Buffer(0);
byte[] array = { };
buffer.CopyTo(array);
@@ -527,7 +528,7 @@ public void TestBuffer()
{
var arr1 = new byte[] { 0x01, 0x02 };
var buff = arr1.AsBuffer();
- var arr2 = buff.ToArray(0,2);
+ var arr2 = buff.ToArray(0, 2);
Assert.True(arr1[0] == arr2[0]);
Assert.True(arr1[1] == arr2[1]);
}
@@ -576,7 +577,7 @@ async Task InvokeWriteBufferAsync()
[Fact]
public void TestWriteBuffer()
{
- Assert.True(InvokeWriteBufferAsync().Wait(1000));
+ Assert.True(InvokeWriteBufferAsync().Wait(1000));
}
[Fact]
@@ -900,10 +901,10 @@ public void TestValueSet()
public void TestValueSetArrays()
{
var map = new Dictionary
- {
+ {
["foo"] = new long[] { 1, 2, 3 },
- ["hello"] = new long[0],
- ["world"] = new long[] { 1, 2, 3 },
+ ["hello"] = new long[0],
+ ["world"] = new long[] { 1, 2, 3 },
["bar"] = new long[0]
};
var valueSet = new Windows.Foundation.Collections.ValueSet();
@@ -924,10 +925,10 @@ public void TestFactories()
var cls1 = new Class();
var cls2 = new Class(42);
- Assert.Equal(42, cls2.IntProperty);
+ Assert.Equal(42, cls2.IntProperty);
var cls3 = new Class(42, "foo");
- Assert.Equal(42, cls3.IntProperty);
+ Assert.Equal(42, cls3.IntProperty);
Assert.Equal("foo", cls3.StringProperty);
}
@@ -1975,11 +1976,25 @@ public void TestRepeatBehaviorTypeMapping()
[Fact]
public void TestMatrix3DTypeMapping()
{
- var matrix3D = new Matrix3D {
- M11 = 11, M12 = 12, M13 = 13, M14 = 14,
- M21 = 21, M22 = 22, M23 = 23, M24 = 24,
- M31 = 31, M32 = 32, M33 = 33, M34 = 34,
- OffsetX = 41, OffsetY = 42, OffsetZ = 43,M44 = 44 };
+ var matrix3D = new Matrix3D
+ {
+ M11 = 11,
+ M12 = 12,
+ M13 = 13,
+ M14 = 14,
+ M21 = 21,
+ M22 = 22,
+ M23 = 23,
+ M24 = 24,
+ M31 = 31,
+ M32 = 32,
+ M33 = 33,
+ M34 = 34,
+ OffsetX = 41,
+ OffsetY = 42,
+ OffsetZ = 43,
+ M44 = 44
+ };
TestObject.Matrix3DProperty = matrix3D;
Assert.Equal(matrix3D.M11, TestObject.Matrix3DProperty.M11);
@@ -2028,10 +2043,22 @@ public void TestMatrix4x4TypeMapping()
{
var matrix4x4 = new Matrix4x4
{
- M11 = 11, M12 = 12, M13 = 13, M14 = 14,
- M21 = 21, M22 = 22, M23 = 23, M24 = 24,
- M31 = 31, M32 = 32, M33 = 33, M34 = 34,
- M41 = 41, M42 = 42, M43 = 43, M44 = 44
+ M11 = 11,
+ M12 = 12,
+ M13 = 13,
+ M14 = 14,
+ M21 = 21,
+ M22 = 22,
+ M23 = 23,
+ M24 = 24,
+ M31 = 31,
+ M32 = 32,
+ M33 = 33,
+ M34 = 34,
+ M41 = 41,
+ M42 = 42,
+ M43 = 43,
+ M44 = 44
};
TestObject.Matrix4x4Property = matrix4x4;
Assert.Equal(matrix4x4.M11, TestObject.Matrix4x4Property.M11);
@@ -2307,7 +2334,7 @@ public void TestDelegateUnboxing()
{
var del = Class.BoxedDelegate;
Assert.IsType(del);
- var provideUriDel = (ProvideUri) del;
+ var provideUriDel = (ProvideUri)del;
Assert.Equal(new Uri("http://microsoft.com"), provideUriDel());
}
@@ -2438,8 +2465,6 @@ public void AcquireObject()
// Object gets proxied to the apartment.
Assert.Equal(2, proxyObject.Commands.Count);
agileReference.Dispose();
-
- proxyObject2 = agileReference2.Get();
}
public void CheckValue()
@@ -2448,9 +2473,6 @@ public void CheckValue()
Assert.Equal(ApartmentState.MTA, Thread.CurrentThread.GetApartmentState());
proxyObject = agileReference.Get();
Assert.Equal(2, proxyObject.Commands.Count);
-
- nonAgileObject2 = new Windows.UI.Popups.PopupMenu();
- agileReference2 = nonAgileObject2.AsAgile();
valueAcquired.Set();
}
@@ -2462,8 +2484,8 @@ public void CallProxyObject()
Assert.ThrowsAny(() => proxyObject.Commands);
}
- private Windows.UI.Popups.PopupMenu nonAgileObject, nonAgileObject2;
- private Windows.UI.Popups.PopupMenu proxyObject, proxyObject2;
+ private Windows.UI.Popups.PopupMenu nonAgileObject;
+ private Windows.UI.Popups.PopupMenu proxyObject;
private AgileReference agileReference, agileReference2;
private readonly AutoResetEvent objectAcquired = new AutoResetEvent(false);
private readonly AutoResetEvent valueAcquired = new AutoResetEvent(false);
@@ -2533,8 +2555,8 @@ static Object MakeObject()
static void TestObject() => MakeObject();
- static (IInitializeWithWindow, IWindowNative) MakeImports()
- {
+ static (IInitializeWithWindow, IWindowNative) MakeImports()
+ {
var obj = MakeObject();
var initializeWithWindow = obj.As();
var windowNative = obj.As();
@@ -2544,7 +2566,7 @@ static Object MakeObject()
static void TestImports()
{
var (initializeWithWindow, windowNative) = MakeImports();
-
+
GC.Collect();
GC.WaitForPendingFinalizers();
@@ -2856,7 +2878,7 @@ public void TestProxiedDelegate()
{
proc.Kill();
}
- catch(Exception)
+ catch (Exception)
{
}
}
@@ -2935,7 +2957,7 @@ private void TestSupportedOSPlatformWarnings()
// Types
var a = new WarningAttribute(); // warning CA1416
Assert.NotNull(a);
- var w = new WarningStruct{ i32 = 0 }; // warning CA1416
+ var w = new WarningStruct { i32 = 0 }; // warning CA1416
Assert.Equal(0, w.i32); // warning CA1416
var v = WarningEnum.Value;
Assert.NotEqual(WarningEnum.WarningValue, v); // warning CA1416
@@ -3046,8 +3068,8 @@ public void TestWeakReferenceEventsFromMultipleContexts()
Assert.True(Thread.CurrentThread.GetApartmentState() == ApartmentState.STA);
watcher = DeviceInformation.CreateWatcher();
- var exception = Record.Exception(() => {
- watcher.Added += OnDeviceAdded;
+ var exception = Record.Exception(() => {
+ watcher.Added += OnDeviceAdded;
});
Assert.Null(exception);
@@ -3055,8 +3077,8 @@ public void TestWeakReferenceEventsFromMultipleContexts()
{
Assert.True(Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA);
- exception = Record.Exception(() => {
- watcher.Updated += OnDeviceUpdated;
+ exception = Record.Exception(() => {
+ watcher.Updated += OnDeviceUpdated;
});
Assert.Null(exception);
});
@@ -3069,6 +3091,47 @@ public void TestWeakReferenceEventsFromMultipleContexts()
staThread.Join();
}
+#if NET
+ [Fact]
+ public void TestActivationFactoriesFromMultipleContexts()
+ {
+ Exception exception = null;
+
+ Thread staThread = new Thread(() =>
+ {
+ Assert.True(Thread.CurrentThread.GetApartmentState() == ApartmentState.STA);
+
+ exception = Record.Exception(() =>
+ {
+ var xmlDoc = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
+ _ = new ToastNotification(xmlDoc);
+ });
+
+ });
+ staThread.SetApartmentState(ApartmentState.STA);
+ staThread.Start();
+ staThread.Join();
+
+ Assert.Null(exception);
+
+ Thread mtaThread = new Thread(() =>
+ {
+ Assert.True(Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA);
+
+ exception = Record.Exception(() =>
+ {
+ var xmlDoc = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
+ _ = new ToastNotification(xmlDoc);
+ });
+ });
+ mtaThread.SetApartmentState(ApartmentState.MTA);
+ mtaThread.Start();
+ mtaThread.Join();
+
+ Assert.Null(exception);
+ }
+#endif
+
[Fact]
public void TestDictionary()
{
diff --git a/src/WinRT.Runtime/ComWrappersSupport.cs b/src/WinRT.Runtime/ComWrappersSupport.cs
index 42164f9fd..528859622 100644
--- a/src/WinRT.Runtime/ComWrappersSupport.cs
+++ b/src/WinRT.Runtime/ComWrappersSupport.cs
@@ -69,16 +69,16 @@ public static void MarshalDelegateInvoke(IntPtr thisPtr, Action invoke)
// This can either be if the object implements IAgileObject or the free threaded marshaler.
internal unsafe static bool IsFreeThreaded(IObjectReference objRef)
{
- if (objRef.TryAs(ABI.WinRT.Interop.IAgileObject.IID, out var agilePtr) >= 0)
+ if (objRef.TryAs(InterfaceIIDs.IAgileObject_IID, out var agilePtr) >= 0)
{
Marshal.Release(agilePtr);
return true;
}
- else if (objRef.TryAs(ABI.WinRT.Interop.IMarshal.IID, out var marshalPtr) >= 0)
+ else if (objRef.TryAs(InterfaceIIDs.IMarshal_IID, out var marshalPtr) >= 0)
{
try
{
- Guid iid_IUnknown = IUnknownVftbl.IID;
+ Guid iid_IUnknown = InterfaceIIDs.IUnknown_IID;
Guid iid_unmarshalClass;
Marshal.ThrowExceptionForHR((**(ABI.WinRT.Interop.IMarshal.Vftbl**)marshalPtr).GetUnmarshalClass_0(
marshalPtr, &iid_IUnknown, IntPtr.Zero, MSHCTX.InProc, IntPtr.Zero, MSHLFLAGS.Normal, &iid_unmarshalClass));
@@ -229,7 +229,7 @@ internal static List GetInterfaceTableEntries(
Vtable = (IntPtr)ifaceAbiType.GetAbiToProjectionVftblPtr()
});
- if (!hasCustomIMarshalInterface && iid == ABI.WinRT.Interop.IMarshal.IID)
+ if (!hasCustomIMarshalInterface && iid == InterfaceIIDs.IMarshal_IID)
{
hasCustomIMarshalInterface = true;
}
@@ -298,7 +298,7 @@ internal static List GetInterfaceTableEntries(
entries.Add(new ComInterfaceEntry
{
- IID = ABI.WinRT.Interop.IWeakReferenceSource.IID,
+ IID = InterfaceIIDs.IWeakReferenceSource_IID,
Vtable = ABI.WinRT.Interop.IWeakReferenceSource.AbiToProjectionVftablePtr
});
@@ -308,7 +308,7 @@ internal static List GetInterfaceTableEntries(
{
entries.Add(new ComInterfaceEntry
{
- IID = ABI.WinRT.Interop.IMarshal.IID,
+ IID = InterfaceIIDs.IMarshal_IID,
Vtable = ABI.WinRT.Interop.IMarshal.Vftbl.AbiToProjectionVftablePtr
});
}
@@ -316,7 +316,7 @@ internal static List GetInterfaceTableEntries(
// Add IAgileObject to all CCWs
entries.Add(new ComInterfaceEntry
{
- IID = ABI.WinRT.Interop.IAgileObject.IID,
+ IID = InterfaceIIDs.IAgileObject_IID,
Vtable = IUnknownVftbl.AbiToProjectionVftblPtr
});
@@ -329,7 +329,7 @@ internal static List GetInterfaceTableEntries(
// This should be the last entry as it is included / excluded based on the flags.
entries.Add(new ComInterfaceEntry
{
- IID = IUnknownVftbl.IID,
+ IID = InterfaceIIDs.IUnknown_IID,
Vtable = IUnknownVftbl.AbiToProjectionVftblPtr
});
diff --git a/src/WinRT.Runtime/Context.cs b/src/WinRT.Runtime/Context.cs
index 1b5dc5ffb..ba138e313 100644
--- a/src/WinRT.Runtime/Context.cs
+++ b/src/WinRT.Runtime/Context.cs
@@ -7,11 +7,8 @@
namespace WinRT
{
- static class Context
+ static partial class Context
{
- [DllImport("api-ms-win-core-com-l1-1-0.dll")]
- private static extern unsafe int CoGetContextToken(IntPtr* contextToken);
-
[DllImport("api-ms-win-core-com-l1-1-0.dll")]
private static extern int CoGetObjectContext(ref Guid riid, out IntPtr ppv);
@@ -24,13 +21,6 @@ public static IntPtr GetContextCallback()
return contextCallbackPtr;
}
- public unsafe static IntPtr GetContextToken()
- {
- IntPtr contextToken;
- Marshal.ThrowExceptionForHR(CoGetContextToken(&contextToken));
- return contextToken;
- }
-
// Calls the given callback in the right context.
// On any exception, calls onFail callback if any set.
// If not set, exception is handled due to today we don't
diff --git a/src/WinRT.Runtime/Interop/IAgileReference.net5.cs b/src/WinRT.Runtime/Interop/IAgileReference.net5.cs
index 78ff5392b..33dbee6cb 100644
--- a/src/WinRT.Runtime/Interop/IAgileReference.net5.cs
+++ b/src/WinRT.Runtime/Interop/IAgileReference.net5.cs
@@ -24,7 +24,7 @@ internal interface IAgileReference
#endif
interface IAgileObject
{
- public static readonly Guid IID = new(0x94ea2b94, 0xe9cc, 0x49e0, 0xc0, 0xff, 0xee, 0x64, 0xca, 0x8f, 0x5b, 0x90);
+ public static readonly Guid IID = InterfaceIIDs.IAgileObject_IID;
}
[WindowsRuntimeType]
diff --git a/src/WinRT.Runtime/Interop/IContextCallback.cs b/src/WinRT.Runtime/Interop/IContextCallback.cs
index 3e24df1fa..d98815f9d 100644
--- a/src/WinRT.Runtime/Interop/IContextCallback.cs
+++ b/src/WinRT.Runtime/Interop/IContextCallback.cs
@@ -39,7 +39,7 @@ namespace ABI.WinRT.Interop
[Guid("000001da-0000-0000-C000-000000000046")]
internal sealed unsafe class IContextCallback : global::WinRT.Interop.IContextCallback
{
- internal static readonly Guid IID = new(0x000001da, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
+ internal static readonly Guid IID = InterfaceIIDs.IContextCallback_IID;
[Guid("000001da-0000-0000-C000-000000000046")]
public struct Vftbl
diff --git a/src/WinRT.Runtime/Interop/IMarshal.cs b/src/WinRT.Runtime/Interop/IMarshal.cs
index dbd421014..36139aa96 100644
--- a/src/WinRT.Runtime/Interop/IMarshal.cs
+++ b/src/WinRT.Runtime/Interop/IMarshal.cs
@@ -36,7 +36,7 @@ namespace ABI.WinRT.Interop
[Guid("00000003-0000-0000-c000-000000000046")]
internal sealed class IMarshal
{
- internal static readonly Guid IID = new(0x00000003, 0, 0, 0xc0, 0, 0, 0, 0, 0, 0, 0x46);
+ internal static readonly Guid IID = InterfaceIIDs.IMarshal_IID;
[DllImport("api-ms-win-core-com-l1-1-0.dll")]
private static extern int CoCreateFreeThreadedMarshaler(IntPtr outer, out IntPtr marshalerPtr);
diff --git a/src/WinRT.Runtime/Interop/IWeakReferenceSource.netstandard2.0.cs b/src/WinRT.Runtime/Interop/IWeakReferenceSource.netstandard2.0.cs
index 15cb04999..ec1f02265 100644
--- a/src/WinRT.Runtime/Interop/IWeakReferenceSource.netstandard2.0.cs
+++ b/src/WinRT.Runtime/Interop/IWeakReferenceSource.netstandard2.0.cs
@@ -99,7 +99,7 @@ private static int Do_Abi_GetWeakReference(IntPtr thisPtr, IntPtr* weakReference
}
}
- internal static readonly Guid IID = new(0x00000038, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
+ internal static readonly Guid IID = InterfaceIIDs.IWeakReferenceSource_IID;
public static IntPtr AbiToProjectionVftablePtr => Vftbl.AbiToProjectionVftablePtr;
public static ObjectReference FromAbi(IntPtr thisPtr) => ObjectReference.FromAbi(thisPtr);
diff --git a/src/WinRT.Runtime/Projections/DataErrorsChangedEventArgs.cs b/src/WinRT.Runtime/Projections/DataErrorsChangedEventArgs.cs
index 98793d74e..b44570354 100644
--- a/src/WinRT.Runtime/Projections/DataErrorsChangedEventArgs.cs
+++ b/src/WinRT.Runtime/Projections/DataErrorsChangedEventArgs.cs
@@ -91,15 +91,7 @@ namespace ABI.System.ComponentModel
#endif
unsafe struct DataErrorsChangedEventArgs
{
- private sealed class ActivationFactory : BaseActivationFactory
- {
- public ActivationFactory() : base("Microsoft.UI.Xaml.Data", "Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs")
- {
- }
-
- internal static ABI.Microsoft.UI.Xaml.Data.WinRTDataErrorsChangedEventArgsRuntimeClassFactory Instance =
- new ActivationFactory()._As();
- }
+ private static ABI.Microsoft.UI.Xaml.Data.WinRTDataErrorsChangedEventArgsRuntimeClassFactory Instance = ActivationFactory.Get("Microsoft.UI.Xaml.Data.DataErrorsChangedEventArgs");
public static IObjectReference CreateMarshaler(global::System.ComponentModel.DataErrorsChangedEventArgs value)
{
@@ -108,7 +100,7 @@ public static IObjectReference CreateMarshaler(global::System.ComponentModel.Dat
return null;
}
- return ActivationFactory.Instance.CreateInstance(value.PropertyName);
+ return Instance.CreateInstance(value.PropertyName);
}
public static ObjectReferenceValue CreateMarshaler2(global::System.ComponentModel.DataErrorsChangedEventArgs value)
@@ -118,7 +110,7 @@ public static ObjectReferenceValue CreateMarshaler2(global::System.ComponentMode
return new ObjectReferenceValue();
}
- return ActivationFactory.Instance.CreateInstanceForMarshaling(value.PropertyName);
+ return Instance.CreateInstanceForMarshaling(value.PropertyName);
}
public static IntPtr GetAbi(IObjectReference m) => m?.ThisPtr ?? IntPtr.Zero;
diff --git a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs
index 448d6f602..5104654be 100644
--- a/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs
+++ b/src/WinRT.Runtime/Projections/NotifyCollectionChangedEventArgs.cs
@@ -194,16 +194,8 @@ namespace ABI.System.Collections.Specialized
public
#endif
struct NotifyCollectionChangedEventArgs
- {
- private sealed class ActivationFactory : BaseActivationFactory
- {
- public ActivationFactory() : base("Microsoft.UI.Xaml.Interop", "Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs")
- {
- }
-
- internal static WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory Instance =
- new ActivationFactory()._As();
- }
+ {
+ private static WinRTNotifyCollectionChangedEventArgsRuntimeClassFactory Instance = ActivationFactory.Get("Microsoft.UI.Xaml.Interop.NotifyCollectionChangedEventArgs");
public static IObjectReference CreateMarshaler(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value)
{
@@ -212,7 +204,7 @@ public static IObjectReference CreateMarshaler(global::System.Collections.Specia
return null;
}
- return ActivationFactory.Instance.CreateInstanceWithAllParameters(value.Action, value.NewItems, value.OldItems, value.NewStartingIndex, value.OldStartingIndex, null, out _);
+ return Instance.CreateInstanceWithAllParameters(value.Action, value.NewItems, value.OldItems, value.NewStartingIndex, value.OldStartingIndex, null, out _);
}
public static ObjectReferenceValue CreateMarshaler2(global::System.Collections.Specialized.NotifyCollectionChangedEventArgs value)
@@ -222,7 +214,7 @@ public static ObjectReferenceValue CreateMarshaler2(global::System.Collections.S
return new ObjectReferenceValue();
}
- return ActivationFactory.Instance.CreateInstanceWithAllParameters(value.Action, value.NewItems, value.OldItems, value.NewStartingIndex, value.OldStartingIndex);
+ return Instance.CreateInstanceWithAllParameters(value.Action, value.NewItems, value.OldItems, value.NewStartingIndex, value.OldStartingIndex);
}
public static IntPtr GetAbi(IObjectReference m) => m?.ThisPtr ?? IntPtr.Zero;
diff --git a/src/WinRT.Runtime/Projections/PropertyChangedEventArgs.cs b/src/WinRT.Runtime/Projections/PropertyChangedEventArgs.cs
index a29aafc68..0831eb895 100644
--- a/src/WinRT.Runtime/Projections/PropertyChangedEventArgs.cs
+++ b/src/WinRT.Runtime/Projections/PropertyChangedEventArgs.cs
@@ -102,15 +102,7 @@ namespace ABI.System.ComponentModel
#endif
unsafe struct PropertyChangedEventArgs
{
- private sealed class ActivationFactory : BaseActivationFactory
- {
- public ActivationFactory() : base("Microsoft.UI.Xaml.Data", "Microsoft.UI.Xaml.Data.PropertyChangedEventArgs")
- {
- }
-
- internal static ABI.Microsoft.UI.Xaml.Data.WinRTPropertyChangedEventArgsRuntimeClassFactory Instance =
- new ActivationFactory()._As();
- }
+ private static ABI.Microsoft.UI.Xaml.Data.WinRTPropertyChangedEventArgsRuntimeClassFactory Instance = ActivationFactory.Get("Microsoft.UI.Xaml.Data.PropertyChangedEventArgs");
public static IObjectReference CreateMarshaler(global::System.ComponentModel.PropertyChangedEventArgs value)
{
@@ -119,7 +111,7 @@ public static IObjectReference CreateMarshaler(global::System.ComponentModel.Pro
return null;
}
- return ActivationFactory.Instance.CreateInstance(value.PropertyName, null, out _);
+ return Instance.CreateInstance(value.PropertyName, null, out _);
}
public static ObjectReferenceValue CreateMarshaler2(global::System.ComponentModel.PropertyChangedEventArgs value)
@@ -129,7 +121,7 @@ public static ObjectReferenceValue CreateMarshaler2(global::System.ComponentMode
return new ObjectReferenceValue();
}
- return ActivationFactory.Instance.CreateInstance(value.PropertyName);
+ return Instance.CreateInstance(value.PropertyName);
}
public static IntPtr GetAbi(IObjectReference m) => m?.ThisPtr ?? IntPtr.Zero;
diff --git a/src/WinRT.Runtime/Projections/Uri.cs b/src/WinRT.Runtime/Projections/Uri.cs
index d375c4541..a830084f5 100644
--- a/src/WinRT.Runtime/Projections/Uri.cs
+++ b/src/WinRT.Runtime/Projections/Uri.cs
@@ -96,15 +96,7 @@ public unsafe ObjectReferenceValue CreateUriForMarshaling(string uri)
#endif
unsafe struct Uri
{
- private sealed class ActivationFactory : BaseActivationFactory
- {
- public ActivationFactory() : base("Windows.Foundation", "Windows.Foundation.Uri")
- {
- }
-
- internal static WinRTUriRuntimeClassFactory Instance =
- new ActivationFactory()._As();
- }
+ private static WinRTUriRuntimeClassFactory Instance = ActivationFactory.Get("Windows.Foundation.Uri");
public static IObjectReference CreateMarshaler(global::System.Uri value)
{
@@ -113,7 +105,7 @@ public static IObjectReference CreateMarshaler(global::System.Uri value)
return null;
}
- return ActivationFactory.Instance.CreateUri(value.OriginalString);
+ return Instance.CreateUri(value.OriginalString);
}
public static ObjectReferenceValue CreateMarshaler2(global::System.Uri value)
@@ -123,7 +115,7 @@ public static ObjectReferenceValue CreateMarshaler2(global::System.Uri value)
return new ObjectReferenceValue();
}
- return ActivationFactory.Instance.CreateUriForMarshaling(value.OriginalString);
+ return Instance.CreateUriForMarshaling(value.OriginalString);
}
public static IntPtr GetAbi(IObjectReference m) => m?.ThisPtr ?? IntPtr.Zero;
diff --git a/src/cswinrt/code_writers.h b/src/cswinrt/code_writers.h
index f9826a891..7f183af20 100644
--- a/src/cswinrt/code_writers.h
+++ b/src/cswinrt/code_writers.h
@@ -950,7 +950,7 @@ namespace cswinrt
if (paramsForStaticMethodCall.has_value())
{
w.write("%", bind(paramsForStaticMethodCall.value().first, paramsForStaticMethodCall.value().second,
- w.write_temp("%", bind(paramsForStaticMethodCall.value().first))));
+ w.write_temp("%", method_target)));
}
else
{
@@ -1117,8 +1117,9 @@ namespace cswinrt
auto static_method_params = call_static_method.has_value() ? std::optional(std::pair(call_static_method.value(), method)) : std::nullopt;
if (!is_private)
{
- write_method(w, signature, method.Name(), return_type, interface_member, access_spec, method_spec, platform_attribute,
- static_method_params);
+ write_method(w, signature, method.Name(), return_type,
+ static_method_params.has_value() ? w.write_temp("%", bind(static_method_params.value().first)) : interface_member,
+ access_spec, method_spec, platform_attribute, static_method_params);
}
if (is_overridable || !is_exclusive_to(method.Parent()))
@@ -1174,7 +1175,7 @@ namespace cswinrt
if (params_for_static_getter.has_value())
{
w.write("%", bind(params_for_static_getter.value().first, params_for_static_getter.value().second,
- w.write_temp("%", bind(params_for_static_getter.value().first))));
+ w.write_temp("%", getter_target)));
}
else
{
@@ -1209,7 +1210,7 @@ namespace cswinrt
if (params_for_static_getter.has_value())
{
w.write("%", bind(params_for_static_getter.value().first, params_for_static_getter.value().second,
- w.write_temp("%", bind(params_for_static_getter.value().first))));
+ w.write_temp("%", getter_target)));
}
else
{
@@ -1221,7 +1222,7 @@ namespace cswinrt
if (params_for_static_setter.has_value())
{
w.write("%", bind(params_for_static_setter.value().first, params_for_static_setter.value().second,
- w.write_temp("%", bind(params_for_static_setter.value().first))));
+ w.write_temp("%", setter_target)));
}
else
{
@@ -1359,7 +1360,7 @@ remove => %;
{
auto&& [iface_type_semantics, _, is_static] = paramsForStaticMethodCall.value();
w.write("%", bind(iface_type_semantics, event, true,
- w.write_temp("%", bind(iface_type_semantics)), is_static));
+ w.write_temp("%", event_target), is_static));
}
else
{
@@ -1371,7 +1372,7 @@ remove => %;
{
auto&& [iface_type_semantics, _, is_static] = paramsForStaticMethodCall.value();
w.write("%", bind(iface_type_semantics, event, false,
- w.write_temp("%", bind(iface_type_semantics)), is_static));
+ w.write_temp("%", event_target), is_static));
}
else
{
@@ -1403,7 +1404,9 @@ remove => %;
bool is_private = is_implemented_as_private_method(w, class_type, add);
if (!is_private)
{
- write_event(w, event.Name(), event, interface_member, visibility, ""sv, platform_attribute, call_static_method.has_value() ? std::optional(std::tuple(call_static_method.value(), event, false)) : std::nullopt);
+ write_event(w, event.Name(), event,
+ call_static_method.has_value() ? w.write_temp("%", bind(call_static_method.value())) : interface_member,
+ visibility, ""sv, platform_attribute, call_static_method.has_value() ? std::optional(std::tuple(call_static_method.value(), event, false)) : std::nullopt);
}
if (is_overridable || !is_exclusive_to(event.Parent()))
@@ -1805,87 +1808,170 @@ remove => %;
return result;
}
- void write_composing_factory_method(writer& w, MethodDef const& method);
+ void write_guid_bytes(writer& w, TypeDef const& type)
+ {
+ auto attribute = get_attribute(type, "Windows.Foundation.Metadata", "GuidAttribute");
+ if (!attribute)
+ {
+ throw_invalid("'Windows.Foundation.Metadata.GuidAttribute' attribute for type '", type.TypeNamespace(), ".", type.TypeName(), "' not found");
+ }
- void write_abi_method_with_raw_return_type(writer& w, MethodDef const& method);
+ auto args = attribute.Value().FixedArgs();
- template
- std::string write_factory_cache_object(writer& w, TypeDef const& factory_type, TypeDef const& class_type);
+ using std::get;
+
+ auto get_arg = [&](decltype(args)::size_type index) { return get(args[index].value).value; };
- std::string write_static_cache_object(writer& w, std::string_view cache_type_name, TypeDef const& class_type)
+ w.write_printf(R"(0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X)",
+ (get(get_arg(0)) >> 0) & 0xFF,
+ (get(get_arg(0)) >> 8) & 0xFF,
+ (get(get_arg(0)) >> 16) & 0xFF,
+ (get(get_arg(0)) >> 24) & 0xFF,
+ (get(get_arg(1)) >> 0) & 0xFF,
+ (get(get_arg(1)) >> 8) & 0xFF,
+ (get(get_arg(2)) >> 0) & 0xFF,
+ (get(get_arg(2)) >> 8) & 0xFF,
+ get(get_arg(3)),
+ get(get_arg(4)),
+ get(get_arg(5)),
+ get(get_arg(6)),
+ get(get_arg(7)),
+ get(get_arg(8)),
+ get(get_arg(9)),
+ get(get_arg(10)));
+ }
+
+ void write_class_static_cache_definition(writer& w, TypeDef const& staticsType, TypeDef const& classType)
{
- auto instance =
- w.write_temp(
- "private static readonly _% _instance = new _%();",
- cache_type_name,
- cache_type_name);
- auto factoryAs = w.write_temp("%",
- bind([&](writer& w)
- {
- if (is_static(class_type))
- {
- w.write("_factory._As");
- }
- else
- {
- w.write("ActivationFactory<%>.As", class_type.TypeName());
- }
- })
- );
+ if (staticsType)
+ {
+ auto factory_class_name = settings.netstandard_compat ?
+ w.write_temp("BaseFactory<%.Vftbl>", bind(staticsType, typedef_name_type::ABI, true)) :
+ w.write_temp("BaseFactory");
+
+ auto statics_type_name = staticsType.TypeName();
+ w.write(R"(
+private static % _% = new %("%.%", %.IID);
+)",
+ factory_class_name,
+ statics_type_name,
+ factory_class_name,
+ classType.TypeNamespace(),
+ classType.TypeName(),
+ bind(staticsType, typedef_name_type::StaticAbiClass, true));
+ }
+ }
+ void write_activation_factory_objref_definition(writer& w, TypeDef const& classType)
+ {
+ auto objrefname = w.write_temp("%", bind(classType));
+ w.write(R"(
+private static volatile FactoryObjectReference __%;
+private static FactoryObjectReference %
+{
+ get
+ {
+ var factory = __%;
+ if (factory != null && factory.IsObjectInContext())
+ {
+ return factory;
+ }
+ else
+ {
+ return __% = ActivationFactory.Get("%.%");
+ }
+ }
+}
+)",
+ objrefname,
+ objrefname,
+ objrefname,
+ objrefname,
+ classType.TypeNamespace(),
+ classType.TypeName());
+ }
+
+ void write_static_objref_definition(writer& w, std::string_view const& vftblType, TypeDef const& staticsType, TypeDef const& classType)
+ {
if (settings.netstandard_compat)
- {
- auto cache_vftbl_type = w.write_temp("ABI.%.%.Vftbl",
- class_type.TypeNamespace(),
- cache_type_name);
- auto cache_interface =
- w.write_temp(
- R"(%<%>)",
- factoryAs,
- cache_vftbl_type);
+ {
+ auto objrefname = w.write_temp("%", bind(staticsType));
w.write(R"(
-internal sealed class _% : ABI.%.%
+private static volatile ObjectReference<%> __%;
+private static ObjectReference<%> Make__%()
{
-public _%() : base(%()) { }
-%
-internal static % Instance => _instance;
+ global::System.Threading.Interlocked.CompareExchange(ref __%, ActivationFactory.Get<%>("%.%", %.IID), null);
+ return __%;
}
+private static ObjectReference<%> % => __% ?? Make__%();
)",
- cache_type_name,
- class_type.TypeNamespace(),
- cache_type_name,
- cache_type_name,
- cache_interface,
- instance,
- cache_type_name);
+ vftblType,
+ objrefname,
+ vftblType,
+ objrefname,
+ objrefname,
+ vftblType,
+ classType.TypeNamespace(),
+ classType.TypeName(),
+ bind(staticsType, typedef_name_type::StaticAbiClass, true),
+ objrefname,
+ vftblType,
+ objrefname,
+ objrefname,
+ objrefname);
}
else
{
+ auto objrefname = w.write_temp("%", bind(staticsType));
w.write(R"(
-internal sealed class _%
+private static volatile FactoryObjectReference<%> __%;
+private static FactoryObjectReference<%> %
{
-private IObjectReference _obj;
-public _%()
-{
-_obj = %(%.IID);
-}
-
-%
-internal static % Instance => (%)_instance;
+ get
+ {
+ var factory = __%;
+ if (factory != null && factory.IsObjectInContext())
+ {
+ return factory;
+ }
+ else
+ {
+ return __% = ActivationFactory.Get<%>("%.%", %.IID);
+ }
+ }
}
)",
- cache_type_name,
- cache_type_name,
- factoryAs,
- bind(class_type, typedef_name_type::StaticAbiClass, true),
- instance,
- cache_type_name,
- cache_type_name);
+ vftblType,
+ objrefname,
+ vftblType,
+ objrefname,
+ objrefname,
+ objrefname,
+ vftblType,
+ classType.TypeNamespace(),
+ classType.TypeName(),
+ bind(staticsType, typedef_name_type::StaticAbiClass, true));
}
+ }
- return w.write_temp("_%.Instance", cache_type_name);
+ template
+ void write_static_abi_class_raw(writer& w, TypeDef const& factory_type)
+ {
+ w.write(R"(
+private static class _%
+{%}
+)",
+ bind(factory_type, typedef_name_type::StaticAbiClass, false),
+ bind_each([&](writer& w, MethodDef const& method)
+ {
+ method_writer(w, factory_type, method);
+ }, factory_type.MethodList()));
}
+ void write_static_composing_factory_method(writer& w, TypeDef const& iface, MethodDef const& method);
+
+ void write_static_abi_method_with_raw_return_type(writer& w, TypeDef const& iface, MethodDef const& method);
+
static std::string get_default_interface_name(writer& w, TypeDef const& type, bool abiNamespace = true, bool forceCCW = false)
{
return w.write_temp("%", bind(get_type_semantics(get_default_interface(type)), abiNamespace ? typedef_name_type::ABI : forceCCW ? typedef_name_type::CCW : typedef_name_type::Projected, false));
@@ -1896,9 +1982,14 @@ internal static % Instance => (%)_instance;
auto default_interface_name = get_default_interface_name(w, class_type);
if (factory_type)
{
- auto cache_object = write_factory_cache_object(w, factory_type, class_type);
- auto platform_attribute = write_platform_attribute_temp(w, factory_type);
+ write_static_abi_class_raw(w, factory_type);
+ auto vftblType = settings.netstandard_compat ?
+ w.write_temp("%.Vftbl", bind(factory_type, typedef_name_type::ABI, true)) :
+ "IUnknownVftbl";
+ write_static_objref_definition(w, vftblType, factory_type, class_type);
+ auto cache_object = w.write_temp("%", bind(factory_type));
+ auto platform_attribute = write_platform_attribute_temp(w, factory_type);
for (auto&& method : factory_type.MethodList())
{
method_signature signature{ method };
@@ -1906,7 +1997,7 @@ internal static % Instance => (%)_instance;
{
w.write(R"(
%public %(%) : this(((Func<%>)(() => {
-IntPtr ptr = (%.%(%));
+IntPtr ptr = (_%.%(%%%));
try
{
return %(ComWrappersSupport.GetObjectReferenceForInterface(ptr));
@@ -1922,8 +2013,10 @@ MarshalInspectable