Class TagManager
TagManager facilitates a common implementation of tagging for Constructs.
Inheritance
Namespace: Amazon.CDK
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class TagManager : DeputyBase
Syntax (vb)
Public Class TagManager
Inherits DeputyBase
Remarks
Normally, you do not need to use this class, as the CloudFormation specification
will indicate which resources are taggable. However, sometimes you will need this
to make custom resources taggable. Used tagManager.renderedTags
to obtain a
value that will resolve to the tags at synthesis time.
Examples
class MyConstruct : Resource, ITaggable
{
public readonly void Tags = new TagManager(TagType.KEY_VALUE, "Whatever::The::Type");
public MyConstruct(Construct scope, string id) : base(scope, id)
{
new CfnResource(this, "Resource", new CfnResourceProps {
Type = "Whatever::The::Type",
Properties = new Dictionary<string, object> {
// ...
{ "Tags", Tags.RenderedTags }
}
});
}
}
Synopsis
Constructors
TagManager(TagType, String, Object, ITagManagerOptions) | |
TagManager(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
TagManager(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Properties
RenderedTags | A lazy value that represents the rendered tags at synthesis time. |
TagPropertyName | The property name for tag values. |
Methods
ApplyTagAspectHere(String[], String[]) | Determine if the aspect applies here. |
HasTags() | Returns true if there are any tags defined. |
IsTaggable(Object) | Check whether the given construct is Taggable. |
IsTaggableV2(Object) | Check whether the given construct is ITaggableV2. |
Of(Object) | Return the TagManager associated with the given construct, if any. |
RemoveTag(String, Double) | Removes the specified tag from the array if it exists. |
RenderTags(Object) | Renders tags into the proper format based on TagType. |
SetTag(String, String, Nullable<Double>, Nullable<Boolean>) | Adds the specified tag to the array of tags. |
TagValues() | Render the tags in a readable format. |
Constructors
TagManager(TagType, String, Object, ITagManagerOptions)
public TagManager(TagType tagType, string resourceTypeName, object initialTags = null, ITagManagerOptions options = null)
Parameters
- tagType TagType
- resourceTypeName System.String
- initialTags System.Object
- options ITagManagerOptions
TagManager(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected TagManager(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
TagManager(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected TagManager(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Properties
RenderedTags
A lazy value that represents the rendered tags at synthesis time.
public virtual IResolvable RenderedTags { get; }
Property Value
Remarks
If you need to make a custom construct taggable, use the value of this
property to pass to the tags
property of the underlying construct.
TagPropertyName
The property name for tag values.
public virtual string TagPropertyName { get; }
Property Value
System.String
Remarks
Normally this is tags
but some resources choose a different name. Cognito
UserPool uses UserPoolTags
Methods
ApplyTagAspectHere(String[], String[])
Determine if the aspect applies here.
public virtual bool ApplyTagAspectHere(string[] include = null, string[] exclude = null)
Parameters
- include System.String[]
- exclude System.String[]
Returns
System.Boolean
Remarks
Looks at the include and exclude resourceTypeName arrays to determine if the aspect applies here
HasTags()
Returns true if there are any tags defined.
public virtual bool HasTags()
Returns
System.Boolean
IsTaggable(Object)
Check whether the given construct is Taggable.
public static bool IsTaggable(object construct)
Parameters
- construct System.Object
Returns
System.Boolean
IsTaggableV2(Object)
Check whether the given construct is ITaggableV2.
public static bool IsTaggableV2(object construct)
Parameters
- construct System.Object
Returns
System.Boolean
Of(Object)
Return the TagManager associated with the given construct, if any.
public static TagManager Of(object construct)
Parameters
- construct System.Object
Returns
RemoveTag(String, Double)
Removes the specified tag from the array if it exists.
public virtual void RemoveTag(string key, double priority)
Parameters
- key System.String
The tag to remove.
- priority System.Double
The priority of the remove operation.
RenderTags(Object)
Renders tags into the proper format based on TagType.
public virtual object RenderTags(object combineWithTags = null)
Parameters
- combineWithTags System.Object
Returns
System.Object
Remarks
This method will eagerly render the tags currently applied. In
most cases, you should be using tagManager.renderedTags
instead,
which will return a Lazy
value that will resolve to the correct
tags at synthesis time.
SetTag(String, String, Nullable<Double>, Nullable<Boolean>)
Adds the specified tag to the array of tags.
public virtual void SetTag(string key, string value, Nullable<double> priority = null, Nullable<bool> applyToLaunchedInstances = null)
Parameters
- key System.String
- value System.String
- priority System.Nullable<System.Double>
- applyToLaunchedInstances System.Nullable<System.Boolean>
TagValues()
Render the tags in a readable format.
public virtual IDictionary<string, string> TagValues()
Returns
System.Collections.Generic.IDictionary<System.String, System.String>