using System; using System.Reflection.Metadata; using System.Threading; using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE; using Microsoft.CodeAnalysis.Symbols; namespace Microsoft.CodeAnalysis.CSharp.Symbols; internal static class ObsoleteAttributeHelpers { internal static void InitializeObsoleteDataFromMetadata(ref ObsoleteAttributeData data, EntityHandle token, PEModuleSymbol containingModule, bool ignoreByRefLikeMarker, bool ignoreRequiredMemberMarker) { if (data == ObsoleteAttributeData.Uninitialized) { ObsoleteAttributeData obsoleteDataFromMetadata = GetObsoleteDataFromMetadata(token, containingModule, ignoreByRefLikeMarker, ignoreRequiredMemberMarker); Interlocked.CompareExchange(ref data, obsoleteDataFromMetadata, ObsoleteAttributeData.Uninitialized); } } internal static ObsoleteAttributeData GetObsoleteDataFromMetadata(EntityHandle token, PEModuleSymbol containingModule, bool ignoreByRefLikeMarker, bool ignoreRequiredMemberMarker) { return containingModule.Module.TryGetDeprecatedOrExperimentalOrObsoleteAttribute(token, (IAttributeNamedArgumentDecoder)(object)new MetadataDecoder(containingModule), ignoreByRefLikeMarker, ignoreRequiredMemberMarker); } private static ThreeState GetObsoleteContextState(Symbol symbol, bool forceComplete, Func getStateFromSymbol) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Invalid comparison between Unknown and I4 //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Invalid comparison between Unknown and I4 //IL_0032: Unknown result type (might be due to invalid IL or missing references) while ((object)symbol != null) { if ((int)symbol.Kind == 6) { Symbol associatedSymbol = ((FieldSymbol)symbol).AssociatedSymbol; if ((object)associatedSymbol != null) { symbol = associatedSymbol; } } if (forceComplete) { symbol.ForceCompleteObsoleteAttribute(); } ThreeState val = getStateFromSymbol(symbol); if ((int)val != 1) { return val; } symbol = ((!symbol.IsAccessor()) ? symbol.ContainingSymbol : ((MethodSymbol)symbol).AssociatedSymbol); } return (ThreeState)1; } internal static ObsoleteDiagnosticKind GetObsoleteDiagnosticKind(Symbol symbol, Symbol containingMember, bool forceComplete = false) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected I4, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Invalid comparison between Unknown and I4 //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Invalid comparison between Unknown and I4 //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Invalid comparison between Unknown and I4 //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Invalid comparison between Unknown and I4 ObsoleteAttributeKind obsoleteKind = symbol.ObsoleteKind; switch ((int)obsoleteKind) { case 0: if ((int)symbol.ContainingModule.ObsoleteKind == 5 || (int)symbol.ContainingAssembly.ObsoleteKind == 5) { return getDiagnosticKind(containingMember, forceComplete, (Symbol symbol2) => symbol2.ExperimentalState); } if ((int)symbol.ContainingModule.ObsoleteKind == 1 || (int)symbol.ContainingAssembly.ObsoleteKind == 1) { return ObsoleteDiagnosticKind.Lazy; } return ObsoleteDiagnosticKind.NotObsolete; case 4: return ObsoleteDiagnosticKind.Diagnostic; case 5: return getDiagnosticKind(containingMember, forceComplete, (Symbol symbol2) => symbol2.ExperimentalState); case 1: return ObsoleteDiagnosticKind.Lazy; default: return getDiagnosticKind(containingMember, forceComplete, (Symbol symbol2) => symbol2.ObsoleteState); } static ObsoleteDiagnosticKind getDiagnosticKind(Symbol symbol2, bool forceComplete2, Func getStateFromSymbol) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 ThreeState obsoleteContextState = GetObsoleteContextState(symbol2, forceComplete2, getStateFromSymbol); if ((int)obsoleteContextState == 1) { return ObsoleteDiagnosticKind.Diagnostic; } if ((int)obsoleteContextState == 2) { return ObsoleteDiagnosticKind.Suppressed; } return ObsoleteDiagnosticKind.LazyPotentiallySuppressed; } } internal static DiagnosticInfo CreateObsoleteDiagnostic(Symbol symbol, BinderFlags location) { return createObsoleteDiagnostic(symbol, location); static DiagnosticInfo createObsoleteDiagnostic(Symbol symbol2, BinderFlags self) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Invalid comparison between Unknown and I4 //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Invalid comparison between Unknown and I4 //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Expected O, but got Unknown ObsoleteAttributeData val = symbol2.ObsoleteAttributeData ?? symbol2.ContainingModule.ObsoleteAttributeData ?? symbol2.ContainingAssembly.ObsoleteAttributeData; if (val == null) { return null; } if (self.Includes(BinderFlags.SuppressObsoleteChecks)) { return null; } if ((int)val.Kind != 4) { if ((int)val.Kind != 5) { bool flag = self.Includes(BinderFlags.CollectionInitializerAddMethod); string message = val.Message; bool isError = val.IsError; ErrorCode errorCode = ((message == null) ? ((!flag) ? ErrorCode.WRN_DeprecatedSymbol : ErrorCode.WRN_DeprecatedCollectionInitAdd) : (isError ? ((!flag) ? ErrorCode.ERR_DeprecatedSymbolStr : ErrorCode.ERR_DeprecatedCollectionInitAddStr) : ((!flag) ? ErrorCode.WRN_DeprecatedSymbolStr : ErrorCode.WRN_DeprecatedCollectionInitAddStr))); ErrorCode errorCode2 = errorCode; string message2 = val.Message; object[] array = ((message2 == null) ? new object[1] { symbol2 } : new object[2] { symbol2, message2 }); return (DiagnosticInfo)new CustomObsoleteDiagnosticInfo((CommonMessageProvider)(object)MessageProvider.Instance, (int)errorCode2, val, array); } return (DiagnosticInfo)new CustomObsoleteDiagnosticInfo((CommonMessageProvider)(object)MessageProvider.Instance, 9204, val, new object[1] { (object)new FormattedSymbol((ISymbolInternal)(object)symbol2, SymbolDisplayFormat.CSharpErrorMessageFormat) }); } return (DiagnosticInfo)(object)new CSDiagnosticInfo(ErrorCode.WRN_WindowsExperimental, (object)new FormattedSymbol((ISymbolInternal)(object)symbol2, SymbolDisplayFormat.CSharpErrorMessageFormat)); } } internal static bool IsObsoleteDiagnostic(this DiagnosticInfo diagnosticInfo) { switch ((ErrorCode)diagnosticInfo.Code) { case ErrorCode.WRN_DeprecatedSymbol: case ErrorCode.WRN_DeprecatedSymbolStr: case ErrorCode.ERR_DeprecatedSymbolStr: case ErrorCode.WRN_DeprecatedCollectionInitAddStr: case ErrorCode.ERR_DeprecatedCollectionInitAddStr: case ErrorCode.WRN_DeprecatedCollectionInitAdd: case ErrorCode.WRN_WindowsExperimental: case ErrorCode.WRN_Experimental: return true; default: return false; } } }