Table of Contents

Struct AccessRuleTarget

Namespace
Cloudflare.NET.Security.Firewall.Models
Assembly
Cloudflare.NET.dll

Represents the target type for an IP Access Rule's configuration.

Access rule targets define what type of network entity the rule applies to, such as a single IP address, IP range, ASN, or country.

[JsonConverter(typeof(ExtensibleEnumConverter<AccessRuleTarget>))]
public readonly struct AccessRuleTarget : IExtensibleEnum<AccessRuleTarget>, IEquatable<AccessRuleTarget>
Implements
Inherited Members

Examples

// Using a known target with IntelliSense
var target = AccessRuleTarget.Ip;

// Creating a configuration with a specific target
var config = new IpConfiguration("192.0.2.1");

// Using implicit conversion from string
AccessRuleTarget customTarget = "new-target-type";

Remarks

This is an extensible enum that provides IntelliSense for known values while allowing custom values for new target types that may be added to the Cloudflare API in the future.

Use the static properties for known targets (e.g., Ip, IpRange) or create custom values using the constructor or implicit string conversion.

Constructors

AccessRuleTarget(string)

Creates a new AccessRuleTarget with the specified value.

public AccessRuleTarget(string value)

Parameters

value string

The string value representing the target.

Exceptions

ArgumentNullException

Thrown when value is null.

Properties

Asn

Targets an Autonomous System Number (ASN).

public static AccessRuleTarget Asn { get; }

Property Value

AccessRuleTarget

Remarks

Used to block or allow traffic from a specific ASN. Example value: "AS13335"

Country

Targets a two-letter country code.

public static AccessRuleTarget Country { get; }

Property Value

AccessRuleTarget

Remarks

Used to block or allow traffic from a specific country. Example value: "US", "GB", "DE"

Ip

Targets an IPv4 or IPv6 address.

public static AccessRuleTarget Ip { get; }

Property Value

AccessRuleTarget

Remarks

Used to block or allow a single IP address. Example value: "192.0.2.1" or "2001:db8::1"

IpRange

Targets an IP range in CIDR notation.

public static AccessRuleTarget IpRange { get; }

Property Value

AccessRuleTarget

Remarks

Used to block or allow a range of IP addresses. Example value: "192.0.2.0/24" or "2001:db8::/32"

Value

Gets the underlying string value of this target.

public string Value { get; }

Property Value

string

Methods

Create(string)

Creates a new instance of the extensible enum from the specified string value.

public static AccessRuleTarget Create(string value)

Parameters

value string

The string value to wrap.

Returns

AccessRuleTarget

A new instance of AccessRuleTarget containing the specified value.

Equals(AccessRuleTarget)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(AccessRuleTarget other)

Parameters

other AccessRuleTarget

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

Operators

operator ==(AccessRuleTarget, AccessRuleTarget)

Determines whether two AccessRuleTarget values are equal.

public static bool operator ==(AccessRuleTarget left, AccessRuleTarget right)

Parameters

left AccessRuleTarget
right AccessRuleTarget

Returns

bool

implicit operator string(AccessRuleTarget)

Implicitly converts a AccessRuleTarget to its string value.

public static implicit operator string(AccessRuleTarget target)

Parameters

target AccessRuleTarget

The target to convert.

Returns

string

implicit operator AccessRuleTarget(string)

Implicitly converts a string to a AccessRuleTarget.

public static implicit operator AccessRuleTarget(string value)

Parameters

value string

The string value to convert.

Returns

AccessRuleTarget

operator !=(AccessRuleTarget, AccessRuleTarget)

Determines whether two AccessRuleTarget values are not equal.

public static bool operator !=(AccessRuleTarget left, AccessRuleTarget right)

Parameters

left AccessRuleTarget
right AccessRuleTarget

Returns

bool

See Also