Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded sources: cswinrt #1009

Merged
merged 20 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Authoring/WinRT.Host.Shim/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Concurrent;
using System.Reflection;

#if !NETSTANDARD2_0
#if NET
using System.Runtime.Loader;
[assembly: global::System.Runtime.Versioning.SupportedOSPlatform("Windows")]
#endif
Expand Down Expand Up @@ -56,7 +56,7 @@ public static unsafe int GetActivationFactory(IntPtr hstrTargetAssembly, IntPtr
}
}

#if NETSTANDARD2_0
#if !NET
private static class ActivationLoader
{
public static Assembly LoadAssembly(string targetAssembly) => Assembly.LoadFrom(targetAssembly);
Expand Down
2 changes: 1 addition & 1 deletion src/Projections/Test/Module.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#if !NETSTANDARD2_0
#if NET
[assembly: global::System.Runtime.Versioning.SupportedOSPlatform("Windows")]
#endif
2 changes: 1 addition & 1 deletion src/Projections/TestHost.ProbeByClass/Module.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#if !NETSTANDARD2_0
#if NET
[assembly: global::System.Runtime.Versioning.SupportedOSPlatform("Windows")]
#endif
2 changes: 1 addition & 1 deletion src/Projections/Windows/Module.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#if !NETSTANDARD2_0
#if NET
[assembly: global::System.Runtime.Versioning.SupportedOSPlatform("Windows")]
#endif
2 changes: 1 addition & 1 deletion src/Tests/AuthoringTest/Module.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#if !NETSTANDARD2_0
#if NET
[assembly: global::System.Runtime.Versioning.SupportedOSPlatform("Windows")]
#endif
17 changes: 13 additions & 4 deletions src/WinRT.Runtime/AgileReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

namespace WinRT
{
public class AgileReference : IDisposable
#if EMBED
internal
#else
public
#endif
class AgileReference : IDisposable
{
private readonly static Guid CLSID_StdGlobalInterfaceTable = new(0x00000323, 0, 0, 0xc0, 0, 0, 0, 0, 0, 0, 0x46);
private readonly static Lazy<IGlobalInterfaceTable> Git = new Lazy<IGlobalInterfaceTable>(() => GetGitTable());
private readonly IAgileReference _agileReference;
private readonly IntPtr _cookie;
private bool disposed;

public unsafe AgileReference(IObjectReference instance)
public unsafe AgileReference(IObjectReference instance)
{
if(instance?.ThisPtr == null)
{
Expand Down Expand Up @@ -43,7 +48,6 @@ public unsafe AgileReference(IObjectReference instance)
MarshalInterface<IAgileReference>.DisposeAbi(agileReference);
}
}

public IObjectReference Get() => _cookie == IntPtr.Zero ? _agileReference?.Resolve(typeof(IUnknownVftbl).GUID) : Git.Value?.GetInterfaceFromGlobal(_cookie, typeof(IUnknownVftbl).GUID);

protected virtual void Dispose(bool disposing)
Expand Down Expand Up @@ -99,7 +103,12 @@ public void Dispose()
}
}

public sealed class AgileReference<T> : AgileReference
#if EMBED
internal
#else
public
#endif
sealed class AgileReference<T> : AgileReference
where T : class
{
public unsafe AgileReference(IObjectReference instance)
Expand Down
25 changes: 19 additions & 6 deletions src/WinRT.Runtime/Attributes.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace WinRT
{
[EditorBrowsable(EditorBrowsableState.Never)]
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class ProjectedRuntimeClassAttribute : Attribute
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
#if EMBED
internal
#else
public
#endif
sealed class ProjectedRuntimeClassAttribute : Attribute
{
public ProjectedRuntimeClassAttribute(string defaultInterfaceProp)
{
Expand All @@ -25,7 +28,12 @@ public ProjectedRuntimeClassAttribute(Type defaultInterface)

[EditorBrowsable(EditorBrowsableState.Never)]
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class ObjectReferenceWrapperAttribute : Attribute
#if EMBED
internal
#else
public
#endif
sealed class ObjectReferenceWrapperAttribute : Attribute
{
public ObjectReferenceWrapperAttribute(string objectReferenceField)
{
Expand All @@ -40,7 +48,12 @@ public ObjectReferenceWrapperAttribute(string objectReferenceField)
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Delegate | AttributeTargets.Struct | AttributeTargets.Enum, Inherited = false, AllowMultiple = false)]
public sealed class WindowsRuntimeTypeAttribute : Attribute
#if EMBED
internal
#else
public
#endif
sealed class WindowsRuntimeTypeAttribute : Attribute
{
public WindowsRuntimeTypeAttribute(string sourceMetadata = null)
{
Expand Down
13 changes: 7 additions & 6 deletions src/WinRT.Runtime/CastExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using WinRT.Interop;

namespace WinRT
{
public static class CastExtensions
#if EMBED
internal
#else
public
#endif
static class CastExtensions
{
/// <summary>
/// Cast a WinRT object to an interface type it implements in its implementation
Expand Down Expand Up @@ -103,7 +104,7 @@ private static IObjectReference GetRefForObject(object value)

private static bool TryGetComposedRefForQI(object value, out IObjectReference objRef)
{
#if NETSTANDARD2_0
#if !NET
var getReferenceMethod = value.GetType().GetMethod("GetDefaultReference", BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(typeof(IUnknownVftbl));
if (getReferenceMethod is null)
{
Expand Down
22 changes: 11 additions & 11 deletions src/WinRT.Runtime/ComWrappersSupport.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
using ABI.Microsoft.UI.Xaml.Data;
using ABI.Windows.Foundation;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Linq.Expressions;
using WinRT.Interop;
using ABI.Windows.Foundation;
using ABI.Microsoft.UI.Xaml.Data;

#if !NETSTANDARD2_0
#if NET
using ComInterfaceEntry = System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry;
#endif

#pragma warning disable 0169 // The field 'xxx' is never used
#pragma warning disable 0649 // Field 'xxx' is never assigned to, and will always have its default value

namespace WinRT
{
public static partial class ComWrappersSupport
{
#if EMBED
internal
#else
public
#endif
static partial class ComWrappersSupport
{
private readonly static ConcurrentDictionary<string, Func<IInspectable, object>> TypedObjectFactoryCache = new ConcurrentDictionary<string, Func<IInspectable, object>>(StringComparer.Ordinal);
private readonly static ConditionalWeakTable<object, object> CCWTable = new ConditionalWeakTable<object, object>();
Expand Down
25 changes: 22 additions & 3 deletions src/WinRT.Runtime/ComWrappersSupport.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

namespace WinRT
{
public static partial class ComWrappersSupport
#if EMBED
internal
#else
public
#endif
static partial class ComWrappersSupport
{
// Instance field and property for Singleton pattern: ComWrappers `set` method should be idempotent
private static DefaultComWrappers _instance;
Expand Down Expand Up @@ -43,7 +48,9 @@ private static ComWrappers ComWrappers
if (_comWrappers is null)
{
var comWrappersToSet = DefaultComWrappersInstance;
#if !EMBED
ComWrappers.RegisterForTrackerSupport(comWrappersToSet);
#endif
_comWrappers = comWrappersToSet;
}
}
Expand All @@ -59,7 +66,9 @@ private static ComWrappers ComWrappers
return;
}
var comWrappersToSet = value ?? DefaultComWrappersInstance;
#if !EMBED
ComWrappers.RegisterForTrackerSupport(comWrappersToSet);
#endif
_comWrappers = comWrappersToSet;
}
}
Expand Down Expand Up @@ -206,7 +215,12 @@ private static Func<IInspectable, object> CreateFactoryForImplementationType(str
}
}

public class ComWrappersHelper
#if EMBED
internal
#else
public
#endif
class ComWrappersHelper
{
public unsafe static void Init(
bool isAggregation,
Expand Down Expand Up @@ -355,7 +369,12 @@ public unsafe static void Init(IObjectReference objRef, bool addRefFromTrackerSo
}
}

public class DefaultComWrappers : ComWrappers
#if EMBED
internal
#else
public
#endif
class DefaultComWrappers : ComWrappers
{
private static readonly ConditionalWeakTable<Type, VtableEntries> TypeVtableEntryTable = new ConditionalWeakTable<Type, VtableEntries>();
public static unsafe IUnknownVftbl IUnknownVftbl => Unsafe.AsRef<IUnknownVftbl>(IUnknownVftblPtr.ToPointer());
Expand Down
11 changes: 8 additions & 3 deletions src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

namespace WinRT
{
public static partial class ComWrappersSupport
#if EMBED
internal
#else
public
#endif
static partial class ComWrappersSupport
{
private static ConditionalWeakTable<object, ComCallableWrapper> ComWrapperCache = new ConditionalWeakTable<object, ComCallableWrapper>();

Expand Down Expand Up @@ -285,10 +290,10 @@ internal static T FindObject<T>(IntPtr thisPtr)
GCHandle thisHandle = GCHandle.FromIntPtr(unmanagedObject._gchandlePtr);
return (T)thisHandle.Target;
}
}
}

internal class ComCallableWrapper
{
{
private Dictionary<Guid, IntPtr> _managedQITable;
private GCHandle _qiTableHandle;
private volatile IntPtr _strongHandle;
Expand Down
3 changes: 3 additions & 0 deletions src/WinRT.Runtime/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace WinRT
{
#if EMBED
internal
#endif
static class Context
{
[DllImport("api-ms-win-core-com-l1-1-0.dll")]
Expand Down
12 changes: 7 additions & 5 deletions src/WinRT.Runtime/DerivedComposed.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.ComponentModel;

namespace WinRT
{
Expand All @@ -10,7 +7,12 @@ namespace WinRT
/// as a base class of another composable object.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public class DerivedComposed
#if EMBED
internal
#else
public
#endif
class DerivedComposed
{
public static readonly DerivedComposed Instance = new DerivedComposed();

Expand Down
9 changes: 6 additions & 3 deletions src/WinRT.Runtime/EventRegistrationToken.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace WinRT
{
public struct EventRegistrationToken : IEquatable<EventRegistrationToken>
#if EMBED
internal
#else
public
#endif
struct EventRegistrationToken : IEquatable<EventRegistrationToken>
{
public long Value;

Expand Down
Loading