JsonPointer.Net
More extensions on .
Gets a collection-oriented hash code by combining the hash codes of its elements.
The type of element.
The collection of elements.
A singular integer value that represents the collection.
This can be used to correctly compare the contents of collections.
Represents a JSON Pointer IAW RFC 6901.
The empty pointer.
Gets the number of segments in the pointer.
Gets a segment value by index.
The index.
The indicated segment value as a span.
Returns an enumerator that iterates through the collection.
An enumerator that can be used to iterate through the collection.
Returns an enumerator that iterates through the collection.
An enumerator that can be used to iterate through the collection.
Parses a JSON Pointer from a string.
The source string.
A JSON Pointer.
does not contain a valid pointer or contains a pointer of the wrong kind.
Parses a JSON Pointer from a string.
The source string.
A JSON Pointer.
is null.
does not contain a valid pointer or contains a pointer of the wrong kind.
Parses a JSON Pointer from a string.
The source string.
The resulting pointer.
`true` if the parse was successful; `false` otherwise.
is null.
Parses a JSON Pointer from a string.
The source string.
The resulting pointer.
`true` if the parse was successful; `false` otherwise.
is null.
Creates a new JSON Pointer from a collection of segments.
A collection of segments.
The JSON Pointer.
This method creates un-encoded pointers only.
Generates a JSON Pointer from a lambda expression.
The type of the object.
The lambda expression which gives the pointer path.
(optional) Options for creating the pointer.
The JSON Pointer.
Thrown when the lambda expression contains a node that is not a property access or
-valued indexer.
Concatenates a pointer onto the current pointer.
Another pointer.
A new pointer.
Concatenates additional segments onto the current pointer.
The additional segments.
A new pointer.
Creates a new pointer retaining the starting segments.
How many levels to remove from the end of the pointer.
A new pointer.
Creates a new pointer retaining the ending segments.
How many levels to keep from the end of the pointer.
A new pointer.
Evaluates the pointer over a .
The .
The sub-element at the pointer's location, or null if the path does not exist.
Evaluates the pointer over a .
The .
The result, if return value is true; null otherwise
true if a value exists at the indicate path; false otherwise.
Returns the string representation of this instance.
The string representation.
Indicates whether the current object is equal to another object of the same type.
An object to compare with this object.
true if the current object is equal to the other parameter; otherwise, false.
Indicates whether this instance and a specified object are equal.
The object to compare with the current instance.
true if obj and this instance are the same type and represent the same value; otherwise, false.
Returns the hash code for this instance.
A 32-bit signed integer that is the hash code for this instance.
Evaluates equality via .
A JSON Pointer.
A JSON Pointer.
`true` if the pointers are equal; `false` otherwise.
Evaluates inequality via .
A JSON Pointer.
A JSON Pointer.
`false` if the pointers are equal; `true` otherwise.
Converter for .
Reads and converts the JSON to type .
The reader.
The type to convert.
An object that specifies serialization options to use.
The converted value.
Writes a specified value as JSON.
The writer to write to.
The value to convert to JSON.
An object that specifies serialization options to use.
Options for creating pointers using .
Default settings.
Gets or sets the property naming resolver. Default is .
Thrown during parsing when the source string contains invalid JSON Pointer data.
Creates a .
Creates a .
Creates a .
Serves as an intermediary for creating JSON Pointers by segments.
Implicitly casts an to a .
A pointer segment that represents the value.
Implicitly casts a to a .
A pointer segment that represents the value.
JSON Pointer encoding is performed, but URI encoding is not.
Returns the fully qualified type name of this instance.
The fully qualified type name.
Declares a property name resolution which is used to provide a property name.
The property.
The property name
Defines a set of predefined property name resolution methods.
Makes no changes. Properties are generated with the name of the property in code.
Property names to camel case (e.g. `camelCase`).
Property names to pascal case (e.g. `PascalCase`).
Property names to snake case (e.g. `Snake_Case`).
Property names to upper snake case (e.g. `UPPER_SNAKE_CASE`).
Property names to kebab case (e.g. `Kebab-Case`).
Property names to upper kebab case (e.g. `UPPER-KEBAB-CASE`).
Represents a Relative JSON Pointer IAW draft-handrews-relative-json-pointer-02
The null pointer. Indicates no navigation should occur.
Gets whether the pointer is an index query, which returns the index within the parent rather than the value.
Gets the number of parent (root) steps to take.
Gets the number of lateral steps to take. Applicable only for arrays.
Gets the pointer to follow after taking steps upward.
Creates the null pointer.
Creates an index query pointer.
A Relative JSON Pointer.
Creates an index query pointer.
The index manipulator.
A Relative JSON Pointer.
Creates a Relative JSON Pointer from a JSON Pointer and a number of parent steps.
The number of parent steps.
The JSON Pointer.
A Relative JSON Pointer.
Creates a Relative JSON Pointer from a JSON Pointer and a number of parent steps.
The number of parent steps.
The index manipulator.
The JSON Pointer.
A Relative JSON Pointer.
Parses a JSON Pointer segment from a string.
The source string.
A Relative JSON Pointer.
is null.
does not contain a valid relative pointer.
Parses a JSON Pointer from a string.
The source string.
The resulting relative pointer.
`true` if the parse was successful; `false` otherwise.
is null.
Evaluates the relative pointer over a .
The .
The result, if return value is true; null otherwise
true if a value exists at the indicate path; false otherwise.
Returns the fully qualified type name of this instance.
The fully qualified type name.
Converter for .
Reads and converts the JSON to type .
The reader.
The type to convert.
An object that specifies serialization options to use.
The converted value.
Writes a specified value as JSON.
The writer to write to.
The value to convert to JSON.
An object that specifies serialization options to use.
Specifies that null is allowed as an input even if the corresponding type disallows it.
Indicates that the specified method parameter expects a constant.
This can be used to inform tooling that a constant should be used as an argument for the annotated parameter.
Indicates the minimum bound of the expected constant, inclusive.
Indicates the maximum bound of the expected constant, inclusive.
Specifies that null is disallowed as an input even if the corresponding type allows it.
Applied to a method that will never return under any circumstance.
Specifies that the method will not return if the associated Boolean parameter is passed the specified value.
Initializes the attribute with the specified parameter value.
The condition parameter value. Code after the method will be considered unreachable
by diagnostics if the argument to the associated parameter matches this value.
Gets the condition parameter value.
Indicates that an API is experimental and it may change in the future.
This attribute allows call sites to be flagged with a diagnostic that indicates that an experimental
feature is used. Authors can use this attribute to ship preview features in their assemblies.
Initializes a new instance of the class,
specifying the ID that the compiler will use when reporting a use of the API the attribute applies to.
The ID that the compiler will use when reporting a use of the API the attribute applies to.
Gets the ID that the compiler will use when reporting a use of the API the attribute applies to.
The unique diagnostic ID.
The diagnostic ID is shown in build output for warnings and errors.
This property represents the unique ID that can be used to suppress the warnings or errors, if needed.
Gets or sets the URL for corresponding documentation.
The API accepts a format string instead of an actual URL, creating a generic URL that includes the diagnostic ID.
The format string that represents a URL to corresponding documentation.
An example format string is https://contoso.com/obsoletion-warnings/{0}.
Specifies that an output may be null even if the corresponding type disallows it.
Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it.
Initializes the attribute with the specified return value condition.
The return value condition. If the method returns this value, the associated parameter may be null.
Gets the return value condition.
Specifies that the method or property will ensure that the listed field and property members have not-null values.
Initializes the attribute with a field or property member.
The field or property member that is promised to be not-null.
Initializes the attribute with the list of field and property members.
The list of field and property members that are promised to be not-null.
Gets field or property member names.
Specifies that the method or property will ensure that the listed field and property
members have not-null values when returning with the specified return value condition.
Initializes the attribute with the specified return value condition and a field or property member.
The return value condition. If the method returns this value, the associated parameter will not be null.
The field or property member that is promised to be not-null.
Initializes the attribute with the specified return value condition and list of field and property members.
The return value condition. If the method returns this value, the associated parameter will not be null.
The list of field and property members that are promised to be not-null.
Gets the return value condition.
Gets field or property member names.
Specifies that an output will not be null even if the corresponding type allows it.
Specifies that an input argument was not null when the call returns.
Specifies that the output will be non-null if the named parameter is non-null.
Initializes the attribute with the associated parameter name.
The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null.
Gets the associated parameter name.
Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it.
Initializes the attribute with the specified return value condition.
The return value condition. If the method returns this value, the associated parameter will not be null.
Gets the return value condition.
Specifies that this constructor sets all required members for the current type,
and callers do not need to set any required members themselves.
Specifies the syntax used in a string.
Initializes the with the identifier of the syntax used.
The syntax identifier.
Initializes the with the identifier of the syntax used.
The syntax identifier.
Optional arguments associated with the specific syntax employed.
Gets the identifier of the syntax used.
Optional arguments associated with the specific syntax employed.
The syntax identifier for strings containing composite formats for string formatting.
The syntax identifier for strings containing date format specifiers.
The syntax identifier for strings containing date and time format specifiers.
The syntax identifier for strings containing format specifiers.
The syntax identifier for strings containing format specifiers.
The syntax identifier for strings containing JavaScript Object Notation (JSON).
The syntax identifier for strings containing numeric format specifiers.
The syntax identifier for strings containing regular expressions.
The syntax identifier for strings containing time format specifiers.
The syntax identifier for strings containing format specifiers.
The syntax identifier for strings containing URIs.
The syntax identifier for strings containing XML.
Used to indicate a byref escapes and is not scoped.
There are several cases where the C# compiler treats a as implicitly
- where the compiler does not allow the to escape the method.
For example:
- for instance methods.
- parameters that refer to types.
- parameters.
This attribute is used in those instances where the should be allowed to escape.
Applying this attribute, in any form, has impact on consumers of the applicable API. It is necessary for
API authors to understand the lifetime implications of applying this attribute and how it may impact their users.
Indicates that certain members on a specified are accessed dynamically,
for example through .
This allows tools to understand which members are being accessed during the execution
of a program.
This attribute is valid on members whose type is or .
When this attribute is applied to a location of type , the assumption is
that the string represents a fully qualified type name.
When this attribute is applied to a class, interface, or struct, the members specified
can be accessed dynamically on instances returned from calling
on instances of that class, interface, or struct.
If the attribute is applied to a method it's treated as a special case and it implies
the attribute should be applied to the "this" parameter of the method. As such the attribute
should only be used on instance methods of types assignable to System.Type (or string, but no methods
will use it there).
Initializes a new instance of the class
with the specified member types.
The types of members dynamically accessed.
Gets the which specifies the type
of members dynamically accessed.
Specifies the types of members that are dynamically accessed.
This enumeration has a attribute that allows a
bitwise combination of its member values.
Specifies no members.
Specifies the default, parameterless public constructor.
Specifies all public constructors.
Specifies all non-public constructors.
Specifies all public methods.
Specifies all non-public methods.
Specifies all public fields.
Specifies all non-public fields.
Specifies all public nested types.
Specifies all non-public nested types.
Specifies all public properties.
Specifies all non-public properties.
Specifies all public events.
Specifies all non-public events.
Specifies all interfaces implemented by the type.
Specifies all members.
States a dependency that one member has on another.
This can be used to inform tooling of a dependency that is otherwise not evident purely from
metadata and IL, for example a member relied on via reflection.
Initializes a new instance of the class
with the specified signature of a member on the same type as the consumer.
The signature of the member depended on.
Initializes a new instance of the class
with the specified signature of a member on a .
The signature of the member depended on.
The containing .
Initializes a new instance of the class
with the specified signature of a member on a type in an assembly.
The signature of the member depended on.
The full name of the type containing the specified member.
The assembly name of the type containing the specified member.
Initializes a new instance of the class
with the specified types of members on a .
The types of members depended on.
The containing the specified members.
Initializes a new instance of the class
with the specified types of members on a type in an assembly.
The types of members depended on.
The full name of the type containing the specified members.
The assembly name of the type containing the specified members.
Gets the signature of the member depended on.
Either must be a valid string or
must not equal , but not both.
Gets the which specifies the type
of members depended on.
Either must be a valid string or
must not equal , but not both.
Gets the containing the specified member.
If neither nor are specified,
the type of the consumer is assumed.
Gets the full name of the type containing the specified member.
If neither nor are specified,
the type of the consumer is assumed.
Gets the assembly name of the specified type.
is only valid when is specified.
Gets or sets the condition in which the dependency is applicable, e.g. "DEBUG".
Indicates that the specified public static boolean get-only property
guards access to the specified feature.
Analyzers can use this to prevent warnings on calls to code that is
annotated as requiring that feature, when the callsite is guarded by a
call to the property.
Initializes a new instance of the class
with the specified feature type.
The type that represents the feature guarded by the property.
The type that represents the feature guarded by the property.
Indicates that the specified public static boolean get-only property
corresponds to the feature switch specified by name.
IL rewriters and compilers can use this to substitute the return value
of the specified property with the value of the feature switch.
Initializes a new instance of the class
with the specified feature switch name.
The name of the feature switch that provides the value for the specified property.
The name of the feature switch that provides the value for the specified property.
Indicates that the specified member requires assembly files to be on disk.
Initializes a new instance of the class.
Initializes a new instance of the class.
A message that contains information about the need for assembly files to be on disk.
Gets an optional message that contains information about the need for
assembly files to be on disk.
Gets or sets an optional URL that contains more information about the member,
why it requires assembly files to be on disk, and what options a consumer has
to deal with it.
Indicates that the specified method requires the ability to generate new code at runtime,
for example through .
This allows tools to understand which methods are unsafe to call when compiling ahead of time.
Initializes a new instance of the class
with the specified message.
A message that contains information about the usage of dynamic code.
Gets a message that contains information about the usage of dynamic code.
Gets or sets an optional URL that contains more information about the method,
why it requires dynamic code, and what options a consumer has to deal with it.
Indicates that the specified method requires dynamic access to code that is not referenced
statically, for example through .
This allows tools to understand which methods are unsafe to call when removing unreferenced
code from an application.
Initializes a new instance of the class
with the specified message.
A message that contains information about the usage of unreferenced code.
Gets a message that contains information about the usage of unreferenced code.
Gets or sets an optional URL that contains more information about the method,
why it requires unreferenced code, and what options a consumer has to deal with it.
Suppresses reporting of a specific rule violation, allowing multiple suppressions on a
single code artifact.
is different than
in that it doesn't have a
. So it is always preserved in the compiled assembly.
Initializes a new instance of the
class, specifying the category of the tool and the identifier for an analysis rule.
The category for the attribute.
The identifier of the analysis rule the attribute applies to.
Gets the category identifying the classification of the attribute.
The property describes the tool or tool analysis category
for which a message suppression attribute applies.
Gets the identifier of the analysis tool rule to be suppressed.
Concatenated together, the and
properties form a unique check identifier.
Gets or sets the scope of the code that is relevant for the attribute.
The Scope property is an optional argument that specifies the metadata scope for which
the attribute is relevant.
Gets or sets a fully qualified path that represents the target of the attribute.
The property is an optional argument identifying the analysis target
of the attribute. An example value is "System.IO.Stream.ctor():System.Void".
Because it is fully qualified, it can be long, particularly for targets such as parameters.
The analysis tool user interface should be capable of automatically formatting the parameter.
Gets or sets an optional argument expanding on exclusion criteria.
The property is an optional argument that specifies additional
exclusion where the literal metadata target is not sufficiently precise. For example,
the cannot be applied within a method,
and it may be desirable to suppress a violation against a statement in the method that will
give a rule violation, but not against all statements in the method.
Gets or sets the justification for suppressing the code analysis message.
If a .NET Debugger is attached which supports the Debugger.BreakForUserUnhandledException(Exception) API,
this attribute will prevent the debugger from breaking on user-unhandled exceptions when the
exception is caught by a method with this attribute, unless BreakForUserUnhandledException is called.
Types and Methods attributed with StackTraceHidden will be omitted from the stack trace text shown in StackTrace.ToString()
and Exception.StackTrace
Initializes a new instance of the class.
Represent a type can be used to index a collection either from the start or the end.
Index is used by the C# compiler to support the new index syntax
int[] someArray = new int[5] { 1, 2, 3, 4, 5 } ;
int lastElement = someArray[^1]; // lastElement = 5
Construct an Index using a value and indicating if the index is from the start or from the end.
The index value. it has to be zero or positive number.
Indicating if the index is from the start or from the end.
If the Index constructed from the end, index value 1 means pointing at the last element and index value 0 means pointing at beyond last element.
Create an Index pointing at first element.
Create an Index pointing at beyond last element.
Create an Index from the start at the position indicated by the value.
The index value from the start.
Create an Index from the end at the position indicated by the value.
The index value from the end.
Returns the index value.
Indicates whether the index is from the start or the end.
Calculate the offset from the start using the giving collection length.
The length of the collection that the Index will be used with. length has to be a positive value
For performance reason, we don't validate the input length parameter and the returned offset value against negative values.
we don't validate either the returned offset is greater than the input length.
It is expected Index will be used with collections which always have non negative length/count. If the returned offset is negative and
then used to index a collection will get out of range exception which will be same affect as the validation.
Indicates whether the current Index object is equal to another object of the same type.
An object to compare with this object
Indicates whether the current Index object is equal to another Index object.
An object to compare with this object
Returns the hash code for this instance.
Converts integer number to an Index.
Converts the value of the current Index object to its equivalent string representation.
Represent a range has start and end indexes.
Range is used by the C# compiler to support the range syntax.
int[] someArray = new int[5] { 1, 2, 3, 4, 5 };
int[] subArray1 = someArray[0..2]; // { 1, 2 }
int[] subArray2 = someArray[1..^0]; // { 2, 3, 4, 5 }
Represent the inclusive start index of the Range.
Represent the exclusive end index of the Range.
Construct a Range object using the start and end indexes.
Represent the inclusive start index of the range.
Represent the exclusive end index of the range.
Indicates whether the current Range object is equal to another object of the same type.
An object to compare with this object
Indicates whether the current Range object is equal to another Range object.
An object to compare with this object
Returns the hash code for this instance.
Converts the value of the current Range object to its equivalent string representation.
Create a Range object starting from start index to the end of the collection.
Create a Range object starting from first element in the collection to the end Index.
Create a Range object starting from first element to the end.
Calculate the start offset and length of range object using a collection length.
The length of the collection that the range will be used with. length has to be a positive value.
For performance reason, we don't validate the input length parameter against negative values.
It is expected Range will be used with collections which always have non negative length/count.
We validate the range is inside the length scope though.
An attribute that allows parameters to receive the expression of other parameters.
Initializes a new instance of the class.
The condition parameter value.
Gets the parameter name the expression is retrieved from.
Initialize the attribute to refer to the method on the type.
The type of the builder to use to construct the collection.
The name of the method on the builder to use to construct the collection.
must refer to a static method that accepts a single parameter of
type and returns an instance of the collection being built containing
a copy of the data from that span. In future releases of .NET, additional patterns may be supported.
Gets the type of the builder to use to construct the collection.
Gets the name of the method on the builder to use to construct the collection.
This should match the metadata name of the target method.
For example, this might be ".ctor" if targeting the type's constructor.
Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
Creates a new instance of the type.
The name of the feature to indicate.
The name of the compiler feature.
If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand .
The used for the ref structs C# feature.
The used for the required members C# feature.
Indicates which arguments to a method involving an interpolated string handler should be passed to that handler.
Initializes a new instance of the class.
The name of the argument that should be passed to the handler.
may be used as the name of the receiver in an instance method.
Initializes a new instance of the class.
The names of the arguments that should be passed to the handler.
may be used as the name of the receiver in an instance method.
Gets the names of the arguments that should be passed to the handler.
may be used as the name of the receiver in an instance method.
Indicates the attributed type is to be used as an interpolated string handler.
Reserved to be used by the compiler for tracking metadata.
This class should not be used by developers in source code.
Used to indicate to the compiler that a method should be called
in its containing module's initializer.
When one or more valid methods
with this attribute are found in a compilation, the compiler will
emit a module initializer which calls each of the attributed methods.
Certain requirements are imposed on any method targeted with this attribute:
- The method must be `static`.
- The method must be an ordinary member method, as opposed to a property accessor, constructor, local function, etc.
- The method must be parameterless.
- The method must return `void`.
- The method must not be generic or be contained in a generic type.
- The method's effective accessibility must be `internal` or `public`.
The specification for module initializers in the .NET runtime can be found here:
https://github.com/dotnet/runtime/blob/main/docs/design/specs/Ecma-335-Augments.md#module-initializer
Specifies the priority of a member in overload resolution. When unspecified, the default priority is 0.
Initializes a new instance of the class.
The priority of the attributed member. Higher numbers are prioritized, lower numbers are deprioritized. 0 is the default if no attribute is present.
The priority of the member.
Indicates that a method will allow a variable number of arguments in its invocation.
Specifies that a type has required members or that a member is required.
Reserved for use by a compiler for tracking metadata.
This attribute should not be used by developers in source code.
Used to indicate to the compiler that the .locals init flag should not be set in method headers.
Disables the built-in runtime managed/unmanaged marshalling subsystem for
P/Invokes, Delegate types, and unmanaged function pointer invocations.
The built-in marshalling subsystem has some behaviors that cannot be changed due to
backward-compatibility requirements. This attribute allows disabling the built-in
subsystem and instead uses the following rules for P/Invokes, Delegates,
and unmanaged function pointer invocations:
- All value types that do not contain reference type fields recursively (unmanaged in C#) are blittable
- Value types that recursively have any fields that have [StructLayout(LayoutKind.Auto)] are disallowed from interop.
- All reference types are disallowed from usage in interop scenarios.
- SetLastError support in P/Invokes is disabled.
- varargs support is disabled.
- LCIDConversionAttribute support is disabled.
Provides access to an inaccessible member of a specific type.
This attribute may be applied to an extern static method.
The implementation of the extern static method annotated with
this attribute will be provided by the runtime based on the information in
the attribute and the signature of the method that the attribute is applied to.
The runtime will try to find the matching method or field and forward the call
to it. If the matching method or field is not found, the body of the extern
method will throw or .
Only the specific type defined will be examined for inaccessible members. The type hierarchy
is not walked looking for a match.
For ,
,
,
and , the type of
the first argument of the annotated extern method identifies the owning type.
The value of the first argument is treated as this pointer for instance fields and methods.
The first argument must be passed as ref for instance fields and methods on structs.
The value of the first argument is not used by the implementation for static fields and methods.
Return type is considered for the signature match. modreqs and modopts are initially not considered for
the signature match. However, if an ambiguity exists ignoring modreqs and modopts, a precise match
is attempted. If an ambiguity still exists is thrown.
By default, the attributed method's name dictates the name of the method/field. This can cause confusion
in some cases since language abstractions, like C# local functions, generate mangled IL names. The
solution to this is to use the nameof mechanism and define the property.
public void Method(Class c)
{
PrivateMethod(c);
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = nameof(PrivateMethod))]
extern static void PrivateMethod(Class c);
}
Instantiates an
providing access to a member of kind .
The kind of the target to which access is provided.
Gets the kind of member to which access is provided.
Gets or sets the name of the member to which access is provided.
The name defaults to the annotated method name if not specified.
The name must be unset/null for .
Specifies the kind of target to which an is providing access.
Provide access to a constructor.
Provide access to a method.
Provide access to a static method.
Provide access to a field.
Provide access to a static field.
Initializes a new instance of the class.
Initializes a new instance of the class with the specified message.
An optional message associated with this attribute instance.
Returns the optional message associated with this attribute instance.
Returns the optional URL associated with this attribute instance.
Marks APIs that were obsoleted in a given operating system version.
Primarily used by OS bindings to indicate APIs that should not be used anymore.
Records the operating system (and minimum version) that supports an API. Multiple attributes can be
applied to indicate support on multiple operating systems.
Callers can apply a
or use guards to prevent calls to APIs on unsupported operating systems.
A given platform should only be specified once.
Annotates a custom guard field, property or method with a supported platform name and optional version.
Multiple attributes can be applied to indicate guard for multiple supported platforms.
Callers can apply a to a field, property or method
and use that field, property or method in a conditional or assert statements in order to safely call platform specific APIs.
The type of the field or property should be boolean, the method return type should be boolean in order to be used as platform guard.
Records the platform that the project targeted.
Marks APIs that were removed in a given operating system version.
Primarily used by OS bindings to indicate APIs that are only available in
earlier versions.
Annotates the custom guard field, property or method with an unsupported platform name and optional version.
Multiple attributes can be applied to indicate guard for multiple unsupported platforms.
Callers can apply a to a field, property or method
and use that field, property or method in a conditional or assert statements as a guard to safely call APIs unsupported on those platforms.
The type of the field or property should be boolean, the method return type should be boolean in order to be used as platform guard.
Indicates that the instance's storage is sequentially replicated "length" times.
This attribute can be used to annotate a type with a single field.
The runtime will replicate that field in the actual type layout as many times as is specified.
Here's an example of how an inline array type with 8 values can be declared:
[InlineArray(8)]
struct Float8InlineArray
{
private float _value;
}
Creates a new instance with the specified length.
The number of sequential fields to replicate in the inline array type.
Gets the number of sequential fields to replicate in the inline array type.
An attribute used to indicate a GC transition should be skipped when making an unmanaged function call.
Example of a valid use case. The Win32 `GetTickCount()` function is a small performance related function
that reads some global memory and returns the value. In this case, the GC transition overhead is significantly
more than the memory read.
using System;
using System.Runtime.InteropServices;
class Program
{
[DllImport("Kernel32")]
[SuppressGCTransition]
static extern int GetTickCount();
static void Main()
{
Console.WriteLine($"{GetTickCount()}");
}
}
This attribute is ignored if applied to a method without the .
Forgoing this transition can yield benefits when the cost of the transition is more than the execution time
of the unmanaged function. However, avoiding this transition removes some of the guarantees the runtime
provides through a normal P/Invoke. When exiting the managed runtime to enter an unmanaged function the
GC must transition from Cooperative mode into Preemptive mode. Full details on these modes can be found at
https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/clr-code-guide.md#2.1.8.
Suppressing the GC transition is an advanced scenario and should not be done without fully understanding
potential consequences.
One of these consequences is an impact to Mixed-mode debugging (https://docs.microsoft.com/visualstudio/debugger/how-to-debug-in-mixed-mode).
During Mixed-mode debugging, it is not possible to step into or set breakpoints in a P/Invoke that
has been marked with this attribute. A workaround is to switch to native debugging and set a breakpoint in the native function.
In general, usage of this attribute is not recommended if debugging the P/Invoke is important, for example
stepping through the native code or diagnosing an exception thrown from the native code.
The runtime may load the native library for method marked with this attribute in advance before the method is called for the first time.
Usage of this attribute is not recommended for platform neutral libraries with conditional platform specific code.
The P/Invoke method that this attribute is applied to must have all of the following properties:
* Native function always executes for a trivial amount of time (less than 1 microsecond).
* Native function does not perform a blocking syscall (e.g. any type of I/O).
* Native function does not call back into the runtime (e.g. Reverse P/Invoke).
* Native function does not throw exceptions.
* Native function does not manipulate locks or other concurrency primitives.
Consequences of invalid uses of this attribute:
* GC starvation.
* Immediate runtime termination.
* Data corruption.
Any method marked with can be directly called from
native code. The function token can be loaded to a local variable using the address-of operator
in C# and passed as a callback to a native method.
Methods marked with this attribute have the following restrictions:
* Method must be marked "static".
* Must not be called from managed code.
* Must only have blittable arguments.
Optional. If omitted, the runtime will use the default platform calling convention.
Supplied types must be from the official "System.Runtime.CompilerServices" namespace and
be of the form "CallConvXXX".
Optional. If omitted, no named export is emitted during compilation.
Specifies that the P/Invoke marked with this attribute should be linked in as a WASM import.
See https://webassembly.github.io/spec/core/syntax/modules.html#imports.
Instance constructor.