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

Keep Obsolete and EditorBrowsable attributes consistent between ref and src and DefineConst clean-up #65847

Merged
merged 9 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 4 deletions eng/DefaultGenApiDocIds.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,3 @@ T:System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute
T:System.Runtime.CompilerServices.AsyncMethodBuilderAttribute
T:System.Reflection.DefaultMemberAttribute
T:System.Timers.TimersDescriptionAttribute

// These do not need to be persisted in the implementation
T:System.ComponentModel.EditorBrowsableAttribute
T:System.ObsoleteAttribute
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
// means that the problem is already quite complex and we should not be dealing with it - see
// ComEventsMethod.Invoke

using System.ComponentModel;
using System.Runtime.Versioning;

namespace System.Runtime.InteropServices
Expand All @@ -90,6 +91,7 @@ namespace System.Runtime.InteropServices
/// raised COM objects.
/// </summary>
[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static class ComEventsHelper
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -28,6 +29,7 @@ public static partial class Marshal

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "Trimming doesn't affect types eligible for marshalling. Different exception for invalid inputs doesn't matter.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IntPtr OffsetOf(Type t!!, string fieldName)
{
FieldInfo? f = t.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
Expand All @@ -48,24 +50,32 @@ public static IntPtr OffsetOf(Type t!!, string fieldName)
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr OffsetOfHelper(IRuntimeFieldInfo f);

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("ReadByte(Object, Int32) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static byte ReadByte(object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadByte(nativeHome, offset));
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("ReadInt16(Object, Int32) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static short ReadInt16(object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt16(nativeHome, offset));
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("ReadInt32(Object, Int32) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static int ReadInt32(object ptr, int ofs)
{
return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt32(nativeHome, offset));
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("ReadInt64(Object, Int32) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static long ReadInt64([MarshalAs(UnmanagedType.AsAny), In] object ptr, int ofs)
{
Expand Down Expand Up @@ -106,24 +116,32 @@ private static unsafe T ReadValueSlow<T>(object ptr, int ofs, Func<IntPtr, int,
}
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("WriteByte(Object, Int32, Byte) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteByte(object ptr, int ofs, byte val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, byte value) => WriteByte(nativeHome, offset, value));
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("WriteInt16(Object, Int32, Int16) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt16(object ptr, int ofs, short val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, short value) => Marshal.WriteInt16(nativeHome, offset, value));
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("WriteInt32(Object, Int32, Int32) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt32(object ptr, int ofs, int val)
{
WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, int value) => Marshal.WriteInt32(nativeHome, offset, value));
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("WriteInt64(Object, Int32, Int64) may be unavailable in future releases.")]
[RequiresDynamicCode("Marshalling code for the object might not be available")]
public static void WriteInt64(object ptr, int ofs, long val)
{
Expand Down Expand Up @@ -201,6 +219,8 @@ private static void PrelinkCore(MethodInfo m)
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern /* struct _EXCEPTION_POINTERS* */ IntPtr GetExceptionPointers();

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("GetExceptionCode() may be unavailable in future releases.")]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int GetExceptionCode();

Expand All @@ -211,6 +231,7 @@ private static void PrelinkCore(MethodInfo m)
/// </summary>
[RequiresDynamicCode("Marshalling code for the object might not be available. Use the StructureToPtr<T> overload instead.")]
[MethodImpl(MethodImplOptions.InternalCall)]
[EditorBrowsable(EditorBrowsableState.Never)]
public static extern void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld);

/// <summary>
Expand All @@ -225,6 +246,7 @@ private static void PrelinkCore(MethodInfo m)
/// </summary>
[RequiresDynamicCode("Marshalling code for the object might not be available. Use the DestroyStructure<T> overload instead.")]
[MethodImpl(MethodImplOptions.InternalCall)]
[EditorBrowsable(EditorBrowsableState.Never)]
public static extern void DestroyStructure(IntPtr ptr, Type structuretype);

[MethodImpl(MethodImplOptions.InternalCall)]
Expand Down Expand Up @@ -327,6 +349,7 @@ public static string GetTypeInfoName(ITypeInfo typeInfo!!)
/// Object o should support Type T
/// </summary>
[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IntPtr /* IUnknown* */ GetComInterfaceForObject(object o!!, Type T!!)
{
return GetComInterfaceForObjectNative(o, T, true);
Expand All @@ -341,6 +364,7 @@ public static string GetTypeInfoName(ITypeInfo typeInfo!!)
/// invoke customized QueryInterface or not.
/// </summary>
[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IntPtr /* IUnknown* */ GetComInterfaceForObject(object o!!, Type T!!, CustomQueryInterfaceMode mode)
{
bool bEnableCustomizedQueryInterface = ((mode == CustomQueryInterfaceMode.Allow) ? true : false);
Expand Down Expand Up @@ -390,6 +414,7 @@ public static object GetUniqueObjectForIUnknown(IntPtr unknown)
public static extern object GetTypedObjectForIUnknown(IntPtr /* IUnknown* */ pUnk, Type t);

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o)
{
if (!IsBuiltInComSupported)
Expand Down Expand Up @@ -530,6 +555,7 @@ public static bool SetComObjectData(object obj, object key, object? data)
/// of the specified type. The type must be derived from __ComObject.
/// </summary>
[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
[return: NotNullIfNotNull("o")]
public static object? CreateWrapperOfType(object? o, Type t)
{
Expand Down Expand Up @@ -603,6 +629,7 @@ public static TWrapper CreateWrapperOfType<T, TWrapper>(T? o)
public static extern bool IsTypeVisibleFromCom(Type t);

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr pDstNativeVariant)
{
if (!IsBuiltInComSupported)
Expand All @@ -617,6 +644,7 @@ public static void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr
private static extern void GetNativeVariantForObjectNative(object? obj, /* VARIANT * */ IntPtr pDstNativeVariant);

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant)
{
if (!IsBuiltInComSupported)
Expand All @@ -628,6 +656,7 @@ public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static object? GetObjectForNativeVariant(/* VARIANT * */ IntPtr pSrcNativeVariant)
{
if (!IsBuiltInComSupported)
Expand All @@ -642,6 +671,7 @@ public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant
private static extern object? GetObjectForNativeVariantNative(/* VARIANT * */ IntPtr pSrcNativeVariant);

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T? GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
{
if (!IsBuiltInComSupported)
Expand All @@ -653,6 +683,7 @@ public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static object?[] GetObjectsForNativeVariants(/* VARIANT * */ IntPtr aSrcNativeVariant, int cVars)
{
if (!IsBuiltInComSupported)
Expand All @@ -667,6 +698,7 @@ public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant
private static extern object?[] GetObjectsForNativeVariantsNative(/* VARIANT * */ IntPtr aSrcNativeVariant, int cVars);

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T[] GetObjectsForNativeVariants<T>(IntPtr aSrcNativeVariant, int cVars)
{
if (!IsBuiltInComSupported)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3887,9 +3887,11 @@ private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperType
case DispatchWrapperType.Error:
wrapperType = typeof(ErrorWrapper);
break;
#pragma warning disable 0618 // CurrencyWrapper is obsolete
case DispatchWrapperType.Currency:
wrapperType = typeof(CurrencyWrapper);
break;
#pragma warning restore 0618
case DispatchWrapperType.BStr:
wrapperType = typeof(BStrWrapper);
isString = true;
Expand Down Expand Up @@ -3946,9 +3948,11 @@ private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperType
case DispatchWrapperType.Error:
aArgs[i] = new ErrorWrapper(aArgs[i]);
break;
#pragma warning disable 0618 // CurrencyWrapper is obsolete
case DispatchWrapperType.Currency:
aArgs[i] = new CurrencyWrapper(aArgs[i]);
break;
#pragma warning restore 0618
case DispatchWrapperType.BStr:
aArgs[i] = new BStrWrapper((string)aArgs[i]);
break;
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,14 @@ public Variant(object? obj)
obj = (object)(((ErrorWrapper)obj).ErrorCode);
Debug.Assert(obj != null, "obj != null");
}
#pragma warning disable 0618 // CurrencyWrapper is obsolete
else if (obj is CurrencyWrapper)
{
vt = VarEnum.VT_CY;
obj = (object)(((CurrencyWrapper)obj).WrappedObject);
Debug.Assert(obj != null, "obj != null");
}
#pragma warning restore 0618
else if (obj is BStrWrapper)
{
vt = VarEnum.VT_BSTR;
Expand Down Expand Up @@ -441,7 +443,9 @@ internal static void MarshalHelperCastVariant(object pValue, int vt, ref Variant
3 => /*VT_I4*/ new Variant(iv.ToInt32(provider)),
4 => /*VT_R4*/ new Variant(iv.ToSingle(provider)),
5 => /*VT_R8*/ new Variant(iv.ToDouble(provider)),
#pragma warning disable 0618 // CurrencyWrapper is obsolete
6 => /*VT_CY*/ new Variant(new CurrencyWrapper(iv.ToDecimal(provider))),
#pragma warning restore 0618
7 => /*VT_DATE*/ new Variant(iv.ToDateTime(provider)),
8 => /*VT_BSTR*/ new Variant(iv.ToString(provider)),
#pragma warning disable CA1416 // Validate platform compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Assembly Load(string assemblyString)
return Load(name);
}

[Obsolete("This method has been deprecated. Please use Assembly.Load() instead. https://go.microsoft.com/fwlink/?linkid=14202")]
[Obsolete("Assembly.LoadWithPartialName has been deprecated. Use Assembly.Load() instead.")]
public static Assembly LoadWithPartialName(string partialName)
{
if (partialName == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Runtime.Versioning;

namespace System.Runtime.InteropServices
{
[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static class ComEventsHelper
{
public static void Combine(object rcw, Guid iid, int dispid, Delegate d)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
Expand All @@ -24,6 +25,7 @@ public static int GetHRForException(Exception? e)
public static bool AreComObjectsAvailableForCleanup() => false;

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IntPtr CreateAggregatedObject(IntPtr pOuter, object o)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
Expand All @@ -47,6 +49,7 @@ public static IntPtr CreateAggregatedObject<T>(IntPtr pOuter, T o) where T : not
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static object? CreateWrapperOfType(object? o, Type t)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
Expand All @@ -71,6 +74,7 @@ public static int FinalReleaseComObject(object o)
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IntPtr GetComInterfaceForObject(object o, Type T)
{
if (o is null)
Expand All @@ -87,6 +91,7 @@ public static IntPtr GetComInterfaceForObject(object o, Type T)
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IntPtr GetComInterfaceForObject(object o, Type T, CustomQueryInterfaceMode mode)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
Expand Down Expand Up @@ -122,6 +127,7 @@ public static IntPtr GetIUnknownForObject(object o)
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static unsafe void GetNativeVariantForObject(object? obj, IntPtr pDstNativeVariant)
{
if (pDstNativeVariant == IntPtr.Zero)
Expand Down Expand Up @@ -188,9 +194,11 @@ public static unsafe void GetNativeVariantForObject(object? obj, IntPtr pDstNati
case BStrWrapper value:
data->AsBstr = value.WrappedObject;
break;
#pragma warning disable 0618 // CurrencyWrapper is obsolete
case CurrencyWrapper value:
data->AsCy = value.WrappedObject;
break;
#pragma warning restore 0618
case UnknownWrapper value:
data->AsUnknown = value.WrappedObject;
break;
Expand Down Expand Up @@ -285,6 +293,7 @@ public static unsafe void GetNativeVariantForObject(object? obj, IntPtr pDstNati
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static void GetNativeVariantForObject<T>(T? obj, IntPtr pDstNativeVariant)
{
GetNativeVariantForObject((object?)obj, pDstNativeVariant);
Expand All @@ -303,6 +312,7 @@ public static object GetObjectForIUnknown(IntPtr pUnk)
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static unsafe object? GetObjectForNativeVariant(IntPtr pSrcNativeVariant)
{
if (pSrcNativeVariant == IntPtr.Zero)
Expand Down Expand Up @@ -351,18 +361,21 @@ public static object GetObjectForIUnknown(IntPtr pUnk)

[return: MaybeNull]
[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T GetObjectForNativeVariant<T>(IntPtr pSrcNativeVariant)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static object?[] GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
}

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T[] GetObjectsForNativeVariants<T>(IntPtr aSrcNativeVariant, int cVars)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
Expand Down
Loading