Class Annotations
Includes API for attaching annotations such as warning messages to constructs.
Inheritance
Namespace: Amazon.CDK
Assembly: Amazon.CDK.dll
Syntax (csharp)
public class Annotations : DeputyBase
Syntax (vb)
Public Class Annotations
Inherits DeputyBase
Remarks
ExampleMetadata: nofixture infused
Examples
using Amazon.CDK;
using Constructs;
class MyAspect : IAspect
{
public void Visit(IConstruct node)
{
if (node instanceof CfnResource && node.CfnResourceType == "Foo::Bar")
{
Error(node, "we do not want a Foo::Bar resource");
}
}
protected void Error(IConstruct node, string message)
{
Annotations.Of(node).AddError(message);
}
}
class MyStack : Stack
{
public MyStack(Construct scope, string id) : base(scope, id)
{
var stack = new Stack();
new CfnResource(stack, "Foo", new CfnResourceProps {
Type = "Foo::Bar",
Properties = new Dictionary<string, object> {
{ "Fred", "Thud" }
}
});
Aspects.Of(stack).Add(new MyAspect());
}
}
Synopsis
Constructors
Annotations(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Annotations(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Methods
AddDeprecation(String, String) | Adds a deprecation warning for a specific API. |
AddError(String) | Adds an { "error": <message> } metadata entry to this construct. |
AddInfo(String) | Adds an info metadata entry to this construct. |
AddWarning(String) | Adds a warning metadata entry to this construct. |
Of(IConstruct) | Returns the annotations API for a construct scope. |
Constructors
Annotations(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Annotations(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
Annotations(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Annotations(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Methods
AddDeprecation(String, String)
Adds a deprecation warning for a specific API.
public virtual void AddDeprecation(string api, string message)
Parameters
- api System.String
The API being deprecated in the format
module.Class.property
(e.g.@aws-cdk/core.Construct.node
).- message System.String
The deprecation message to display, with information about alternatives.
Remarks
Deprecations will be added only once per construct as a warning and will be
deduplicated based on the api
.
If the environment variable CDK_BLOCK_DEPRECATIONS
is set, this method
will throw an error instead with the deprecation message.
AddError(String)
Adds an { "error": <message> } metadata entry to this construct.
public virtual void AddError(string message)
Parameters
- message System.String
The error message.
Remarks
The toolkit will fail deployment of any stack that has errors reported against it.
AddInfo(String)
Adds an info metadata entry to this construct.
public virtual void AddInfo(string message)
Parameters
- message System.String
The info message.
Remarks
The CLI will display the info message when apps are synthesized.
AddWarning(String)
Adds a warning metadata entry to this construct.
public virtual void AddWarning(string message)
Parameters
- message System.String
The warning message.
Remarks
The CLI will display the warning when an app is synthesized, or fail if run in --strict mode.
Of(IConstruct)
Returns the annotations API for a construct scope.
public static Annotations Of(IConstruct scope)
Parameters
- scope Constructs.IConstruct
The scope.
Returns