diff --git a/src/WinRT.Runtime/ComWrappersSupport.cs b/src/WinRT.Runtime/ComWrappersSupport.cs index d1b312cdd..9a4703b03 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.cs @@ -526,7 +526,12 @@ private static Func CreateCustomTypeMappingFactory( }; } - internal static Func CreateTypedRcwFactory(Type implementationType, string runtimeClassName = null) + internal static Func CreateTypedRcwFactory(Type implementationType) + { + return CreateTypedRcwFactory(implementationType, null); + } + + internal static Func CreateTypedRcwFactory(Type implementationType, string runtimeClassName) { // If runtime class name is empty or "Object", then just use IInspectable. if (implementationType == null || implementationType == typeof(object)) diff --git a/src/WinRT.Runtime/ComWrappersSupport.net5.cs b/src/WinRT.Runtime/ComWrappersSupport.net5.cs index cc5bba3fb..c5dfff457 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.net5.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.net5.cs @@ -198,7 +198,7 @@ public static void InitializeComWrappers(ComWrappers wrappers = null) ComWrappers = wrappers; } - internal static Func GetTypedRcwFactory(Type implementationType) => TypedObjectFactoryCacheForType.GetOrAdd(implementationType, classType => CreateTypedRcwFactory(classType)); + internal static Func GetTypedRcwFactory(Type implementationType) => TypedObjectFactoryCacheForType.GetOrAdd(implementationType, CreateTypedRcwFactory); public static bool RegisterTypedRcwFactory(Type implementationType, Func rcwFactory) => TypedObjectFactoryCacheForType.TryAdd(implementationType, rcwFactory); diff --git a/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs b/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs index eaf315244..e9dafb749 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.netstandard2.0.cs @@ -32,7 +32,7 @@ public static T CreateRcwForComObject(IntPtr ptr) return CreateRcwForComObject(ptr, true); } - internal static Func GetTypedRcwFactory(Type implementationType) => TypedObjectFactoryCacheForType.GetOrAdd(implementationType, classType => CreateTypedRcwFactory(classType)); + internal static Func GetTypedRcwFactory(Type implementationType) => TypedObjectFactoryCacheForType.GetOrAdd(implementationType, CreateTypedRcwFactory); private static T CreateRcwForComObject(IntPtr ptr, bool tryUseCache) { @@ -63,7 +63,7 @@ private static T CreateRcwForComObject(IntPtr ptr, bool tryUseCache) else { Type runtimeClassType = GetRuntimeClassForTypeCreation(inspectable, typeof(T)); - runtimeWrapper = runtimeClassType == null ? inspectable : TypedObjectFactoryCacheForType.GetOrAdd(runtimeClassType, classType => CreateTypedRcwFactory(classType))(inspectable); + runtimeWrapper = runtimeClassType == null ? inspectable : TypedObjectFactoryCacheForType.GetOrAdd(runtimeClassType, CreateTypedRcwFactory)(inspectable); } } else if (identity.TryAs(out var weakRef) == 0) @@ -132,7 +132,7 @@ public static bool TryUnwrapObject(object o, out IObjectReference objRef) return TryUnwrapObject(del.Target, out objRef); } - var objRefFunc = TypeObjectRefFuncCache.GetOrAdd(o.GetType(), (type) => + var objRefFunc = TypeObjectRefFuncCache.GetOrAdd(o.GetType(), static (type) => { ObjectReferenceWrapperAttribute objRefWrapper = type.GetCustomAttribute(); if (objRefWrapper is object) diff --git a/src/WinRT.Runtime/IWinRTObject.net5.cs b/src/WinRT.Runtime/IWinRTObject.net5.cs index c5a46603a..e244908f5 100644 --- a/src/WinRT.Runtime/IWinRTObject.net5.cs +++ b/src/WinRT.Runtime/IWinRTObject.net5.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -318,9 +319,11 @@ IObjectReference GetObjectReferenceForTypeFallback(RuntimeTypeHandle type) ConcurrentDictionary AdditionalTypeData { get; } + [Obsolete("Use the 'AdditionalTypeData' property instead.")] + [EditorBrowsable(EditorBrowsableState.Never)] object GetOrCreateTypeHelperData(RuntimeTypeHandle type, Func helperDataFactory) { - return AdditionalTypeData.GetOrAdd(type, (type) => helperDataFactory()); + throw new NotSupportedException("'GetOrCreateTypeHelperData(RuntimeTypeHandle, Func)' is not supported, use 'AdditionalTypeData' instead."); } } } \ No newline at end of file diff --git a/src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt b/src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt index 889396efd..b03392525 100644 --- a/src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt +++ b/src/WinRT.Runtime/MatchingRefApiCompatBaseline.txt @@ -235,4 +235,6 @@ CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.Unconditional TypesMustExist : Type 'WinRT.WinRTRuntimeClassNameAttribute' does not exist in the reference but it does exist in the implementation. MembersMustExist : Member 'public void WinRT.ComWrappersSupport.RegisterTypeRuntimeClassNameLookup(System.Func)' does not exist in the reference but it does exist in the implementation. CannotRemoveAttribute : Attribute 'System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute' exists on 'WinRT.Projections.FindCustomHelperTypeMapping(System.Type, System.Boolean)' in the implementation but not the reference. -Total Issues: 237 +CannotRemoveAttribute : Attribute 'System.ComponentModel.EditorBrowsableAttribute' exists on 'WinRT.IWinRTObject.GetOrCreateTypeHelperData(System.RuntimeTypeHandle, System.Func)' in the implementation but not the reference. +CannotRemoveAttribute : Attribute 'System.ObsoleteAttribute' exists on 'WinRT.IWinRTObject.GetOrCreateTypeHelperData(System.RuntimeTypeHandle, System.Func)' in the implementation but not the reference. +Total Issues: 239 diff --git a/src/WinRT.Runtime/Projections/Bindable.net5.cs b/src/WinRT.Runtime/Projections/Bindable.net5.cs index f0ccf3334..e26e7eeed 100644 --- a/src/WinRT.Runtime/Projections/Bindable.net5.cs +++ b/src/WinRT.Runtime/Projections/Bindable.net5.cs @@ -578,8 +578,8 @@ internal static ObjectReference ObjRefFromAbi(IntPtr thisPtr) private static FromAbiHelper _AbiHelper(IWinRTObject _this) { - return (FromAbiHelper)_this.GetOrCreateTypeHelperData(typeof(global::System.Collections.IEnumerable).TypeHandle, - () => new FromAbiHelper((global::System.Collections.IEnumerable)_this)); + return (FromAbiHelper)_this.AdditionalTypeData.GetOrAdd(typeof(global::System.Collections.IEnumerable).TypeHandle, + static (_, _this) => new FromAbiHelper((global::System.Collections.IEnumerable)_this), _this); } unsafe global::Microsoft.UI.Xaml.Interop.IBindableIterator global::Microsoft.UI.Xaml.Interop.IBindableIterable.First() @@ -1286,8 +1286,8 @@ internal static ObjectReference ObjRefFromAbi(IntPtr thisPtr) internal static FromAbiHelper _VectorToList(IWinRTObject _this) { - return (FromAbiHelper)_this.GetOrCreateTypeHelperData(typeof(global::System.Collections.IList).TypeHandle, - () => new FromAbiHelper((global::Microsoft.UI.Xaml.Interop.IBindableVector)_this)); + return (FromAbiHelper)_this.AdditionalTypeData.GetOrAdd(typeof(global::System.Collections.IList).TypeHandle, + static (_, _this) => new FromAbiHelper((global::Microsoft.UI.Xaml.Interop.IBindableVector)_this), _this); } unsafe object global::Microsoft.UI.Xaml.Interop.IBindableVector.GetAt(uint index) diff --git a/src/WinRT.Runtime/Projections/CollectionHybrid.net5.cs b/src/WinRT.Runtime/Projections/CollectionHybrid.net5.cs index 68e3a18a3..f81a21432 100644 --- a/src/WinRT.Runtime/Projections/CollectionHybrid.net5.cs +++ b/src/WinRT.Runtime/Projections/CollectionHybrid.net5.cs @@ -16,7 +16,7 @@ namespace ABI.System.Collections.Generic [DynamicInterfaceCastableImplementation] interface IReadOnlyCollection : global::System.Collections.Generic.IReadOnlyCollection { - private static global::System.Collections.Generic.IReadOnlyCollection CreateHelper(IWinRTObject _this) + private static global::System.Collections.Generic.IReadOnlyCollection CreateHelper(RuntimeTypeHandle type, IWinRTObject _this) { var genericType = typeof(T); if (genericType.IsGenericType && genericType.GetGenericTypeDefinition() == typeof(global::System.Collections.Generic.KeyValuePair<,>)) @@ -51,9 +51,9 @@ interface IReadOnlyCollection : global::System.Collections.Generic.IReadOnlyC private static global::System.Collections.Generic.IReadOnlyCollection GetHelper(IWinRTObject _this) { - return (global::System.Collections.Generic.IReadOnlyCollection)_this.GetOrCreateTypeHelperData( + return (global::System.Collections.Generic.IReadOnlyCollection)_this.AdditionalTypeData.GetOrAdd( typeof(global::System.Collections.Generic.IReadOnlyCollection).TypeHandle, - () => CreateHelper(_this)); + CreateHelper, _this); } int global::System.Collections.Generic.IReadOnlyCollection.Count @@ -69,7 +69,7 @@ interface IReadOnlyCollection : global::System.Collections.Generic.IReadOnlyC [DynamicInterfaceCastableImplementation] interface ICollection : global::System.Collections.Generic.ICollection { - private static global::System.Collections.Generic.ICollection CreateHelper(IWinRTObject _this) + private static global::System.Collections.Generic.ICollection CreateHelper(RuntimeTypeHandle type, IWinRTObject _this) { var genericType = typeof(T); if (genericType.IsGenericType && genericType.GetGenericTypeDefinition() == typeof(global::System.Collections.Generic.KeyValuePair<,>)) @@ -104,9 +104,9 @@ interface ICollection : global::System.Collections.Generic.ICollection private static global::System.Collections.Generic.ICollection GetHelper(IWinRTObject _this) { - return (global::System.Collections.Generic.ICollection)_this.GetOrCreateTypeHelperData( + return (global::System.Collections.Generic.ICollection)_this.AdditionalTypeData.GetOrAdd( typeof(global::System.Collections.Generic.ICollection).TypeHandle, - () => CreateHelper(_this)); + CreateHelper, _this); } int global::System.Collections.Generic.ICollection.Count @@ -143,7 +143,7 @@ namespace ABI.System.Collections [DynamicInterfaceCastableImplementation] interface ICollection : global::System.Collections.ICollection { - private static global::System.Collections.ICollection CreateHelper(IWinRTObject _this) + private static global::System.Collections.ICollection CreateHelper(RuntimeTypeHandle type, IWinRTObject _this) { var iList = typeof(global::System.Collections.IList); if (_this.IsInterfaceImplemented(iList.TypeHandle, false)) @@ -156,9 +156,9 @@ interface ICollection : global::System.Collections.ICollection private static global::System.Collections.ICollection GetHelper(IWinRTObject _this) { - return (global::System.Collections.ICollection)_this.GetOrCreateTypeHelperData( + return (global::System.Collections.ICollection)_this.AdditionalTypeData.GetOrAdd( typeof(global::System.Collections.ICollection).TypeHandle, - () => CreateHelper(_this)); + CreateHelper, _this); } int global::System.Collections.ICollection.Count