Table of Contents

Class Aspects_

Namespace
Amazon.CDK
Assembly
Amazon.CDK.dll

Aspects can be applied to CDK tree scopes and can operate on the tree before synthesis.

public class Aspects_ : DeputyBase
Inheritance
Aspects_

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());
                }
            }

Remarks

ExampleMetadata: nofixture infused

Properties

Aspects

The list of aspects which were directly applied on this scope.

public virtual IAspect[] Aspects { get; }

Property Value

IAspect[]

Methods

Add(IAspect)

Adds an aspect to apply this scope before synthesis.

public virtual void Add(IAspect aspect)

Parameters

aspect IAspect

The aspect to add.

Of(IConstruct)

Returns the Aspects object associated with a construct scope.

public static Aspects_ Of(IConstruct scope)

Parameters

scope IConstruct

The scope for which these aspects will apply.

Returns

Aspects_