DeprecatedAttribute vs. ObsoleteAttribute,
Definition comparison ObsoleteAttribute
[SerializableAttribute][AttributeUsageAttribute(AttributeTargets.Class
| AttributeTargets.Struct
| AttributeTargets.Enum
| AttributeTargets.Constructor
| AttributeTargets.Method
| AttributeTargets.Property
| AttributeTargets.Field
| AttributeTargets.Event
| AttributeTargets.Interface
| AttributeTargets.Delegate, Inherited = false)][ComVisibleAttribute(true)]public sealed class ObsoleteAttribute : Attribute
ObsoleteAttribute is applicable to all program elements attributes t assemblies, modules, parameters, and return values. Marking an element as obsolete informs users that the element will be removed in future versions of the product.
The ObsoleteAttribute class except des two properties:
-
Message. the string assigned to the Message property is emitted by the compiler when the attribute target is used in code. the string shocould note that the attribute target is obsolete and, if possible, provide some workaround or programmatic alternative.
-
IsError. This is a Boolean value that indicates to the compiler whether using the ObsoleteAttribute attribute shocould cause it to emit an error (IsError isTrue) Or a warning (IsError isFalse).
For more information about using attributes, see Extending Metadata Using Attributes.
DeprecatedAttribute
public sealed class DeprecatedAttribute : Attribute
Literal comparison
Deprecated: Express disapproval.
Obsolete: No longer produced or used; out of date.
Some people have explained the two analogy in HTML.
It is recommended that you don't use deprecated elements, because they will likely not be supported in the future, whereas obsolete elements have already been discontinued from use.
MSDN explanation
Directly applying the Windows.Foundation.Metadata.DeprecatedAttribute attribute to managed code is not recommended, because this export occurs automatically.
When you create a Windows Metadata library (. winmd file), the ObsoleteAttribute is exported as both the ObsoleteAttribute and theWindows. foundation. metadata. deprecatedAttribute attribute if only the ObsoleteAttribute is present in source code. the ObsoleteAttribute is transformed toDeprecatedAttributeAs follows:
-
IfMessageAndErrorArguments are both present,MessageIs assigned toDeprecatedAttributeMessageArgument. An error valueTrueMaps to DeprecationType. Remove, andErrorValueFalseMaps to DeprecationType. Deprecate.
-
IfMessageArgument is not supplied in the ObsoleteAttribute, its default value inDeprecatedAttributeIs"Element_nameIs deprecated ", whereElement_nameIs the name of the target program element to which the attribute is applied.
-
IfErrorArgument is not present in the ObsoleteAttribute, its default value inDeprecatedAttributeIs DeprecationType. Deprecate.
Personal Understanding
Differences:
They belong to different frameworks :(The deprecatedattri namespace is Windows. Foundation. Metadata and
The namespace of ObsoleteAttribute isSystem
)
DeprecatedAttribute is supported only after window8.x.
ObsoleteAttribute is introduced in. netfraemwork 1.1
Reference
DeprecatedAttribute
ObsoleteAttribute
Obsolete vs. Deprecated HTML