Skip to main content

CilPrimitiveKind

Enum CilPrimitiveKind 

pub enum CilPrimitiveKind {
Show 23 variants Void, Boolean, Char, I1, U1, I2, U2, I4, U4, I8, U8, R4, R8, I, U, Object, String, Null, TypedReference, ValueType, Var, MVar, Class,
}
Expand description

Classification of all .NET primitive types from ECMA-335.

CilPrimitiveKind provides a complete enumeration of built-in .NET primitive types as defined in the ECMA-335 specification. Each variant corresponds to a specific System type and ELEMENT_TYPE constant.

§ECMA-335 Mapping

This enum directly maps to ELEMENT_TYPE constants (§II.23.1.16):

  • Numeric types (I1, U1, I2, U2, I4, U4, I8, U8, R4, R8)
  • Platform types (I, U for native integers)
  • Character and string types (CHAR, STRING)
  • Special types (VOID, BOOLEAN, OBJECT)
  • Generic parameters (VAR, MVAR)

§Artificial Tokens

Each primitive kind has an associated artificial token (0xF000_XXXX range) for use in type resolution and metadata table operations.

§Examples

use dotscope::metadata::typesystem::CilPrimitiveKind;

// Common primitive types
let int_type = CilPrimitiveKind::I4;    // System.Int32
let bool_type = CilPrimitiveKind::Boolean; // System.Boolean
let str_type = CilPrimitiveKind::String;   // System.String

// Get artificial token
let token = int_type.token();
println!("I4 token: 0x{:08X}", token.value());

Variants§

§

Void

System.Void - represents no value or return type (ELEMENT_TYPE_VOID)

§

Boolean

System.Boolean - true/false value, single byte storage (ELEMENT_TYPE_BOOLEAN)

§

Char

System.Char - Unicode UTF-16 code unit, 16-bit value (ELEMENT_TYPE_CHAR)

§

I1

System.SByte - signed 8-bit integer (-128 to 127) (ELEMENT_TYPE_I1)

§

U1

System.Byte - unsigned 8-bit integer (0 to 255) (ELEMENT_TYPE_U1)

§

I2

System.Int16 - signed 16-bit integer (-32,768 to 32,767) (ELEMENT_TYPE_I2)

§

U2

System.UInt16 - unsigned 16-bit integer (0 to 65,535) (ELEMENT_TYPE_U2)

§

I4

System.Int32 - signed 32-bit integer (-2^31 to 2^31-1) (ELEMENT_TYPE_I4)

§

U4

System.UInt32 - unsigned 32-bit integer (0 to 2^32-1) (ELEMENT_TYPE_U4)

§

I8

System.Int64 - signed 64-bit integer (-2^63 to 2^63-1) (ELEMENT_TYPE_I8)

§

U8

System.UInt64 - unsigned 64-bit integer (0 to 2^64-1) (ELEMENT_TYPE_U8)

§

R4

System.Single - 32-bit IEEE 754 floating point (ELEMENT_TYPE_R4)

§

R8

System.Double - 64-bit IEEE 754 floating point (ELEMENT_TYPE_R8)

§

I

System.IntPtr - platform-specific signed integer (pointer-sized) (ELEMENT_TYPE_I)

§

U

System.UIntPtr - platform-specific unsigned integer (pointer-sized) (ELEMENT_TYPE_U)

§

Object

System.Object - root of the .NET type hierarchy, all types derive from this (ELEMENT_TYPE_OBJECT)

§

String

System.String - immutable sequence of UTF-16 characters (ELEMENT_TYPE_STRING)

§

Null

Null reference constant - used for null literal values in metadata

§

TypedReference

System.TypedReference - compiler-generated type for type-safe variable arguments

§

ValueType

System.ValueType - base class for all value types (structs, enums)

§

Var

Generic type parameter (T, U, etc.) from type definitions (ELEMENT_TYPE_VAR)

§

MVar

Generic method parameter (T, U, etc.) from method definitions (ELEMENT_TYPE_MVAR)

§

Class

General class reference - used for non-primitive reference types (ELEMENT_TYPE_CLASS)

Implementations§

§

impl CilPrimitiveKind

pub fn token(&self) -> Token

Get the artificial token for this primitive type.

Returns a unique artificial token in the 0xF000_XXXX range that can be used to represent this primitive type in metadata operations and type resolution. These tokens do not correspond to actual metadata table entries but provide a consistent identifier for primitive types.

§Token Range

All primitive tokens use the artificial range 0xF000_0001 to 0xF000_0017, which avoids conflicts with actual metadata table tokens.

§Returns

A unique Token for this primitive type

§Examples
use dotscope::metadata::typesystem::CilPrimitiveKind;

let int_token = CilPrimitiveKind::I4.token();
let bool_token = CilPrimitiveKind::Boolean.token();

assert_eq!(int_token.value(), 0xF000_0008);
assert_eq!(bool_token.value(), 0xF000_0002);

pub fn typecode(&self) -> Option<i32>

Maps this primitive kind to a .NET System.TypeCode integer.

Returns the TypeCode enum value for primitive types that have one. Non-primitive kinds (Object, Void, IntPtr, UIntPtr, etc.) return None.

pub fn is_value_type(&self) -> bool

Returns whether this primitive kind represents a .NET value type.

All numeric types, Boolean, Char, IntPtr, UIntPtr, and TypedReference are value types. Void, Object, String, and structural kinds (Class, ValueType, Var, MVar, Null) are not.

pub fn from_byte(type_byte: u8) -> Result<Self>

Parse primitive type from ELEMENT_TYPE byte constant.

Converts an ELEMENT_TYPE constant from ECMA-335 metadata into the corresponding primitive type. This is used when parsing type signatures and metadata tables that contain element type specifications.

§Arguments
  • type_byte - ELEMENT_TYPE constant from metadata (see ECMA-335 §II.23.1.16)
§Returns
  • Ok(CilPrimitiveKind) - Successfully parsed primitive type
  • Err(TypeNotPrimitive) - Byte does not represent a valid primitive type
§Errors

This function will return an error if the provided byte does not correspond to a valid primitive type constant as defined in ECMA-335.

§ELEMENT_TYPE Mapping

Maps standard ELEMENT_TYPE constants to primitive kinds:

  • ELEMENT_TYPE_BOOLEAN (0x02) → Boolean
  • ELEMENT_TYPE_I4 (0x08) → I4
  • ELEMENT_TYPE_STRING (0x0E) → String
  • And so on for all supported primitive types
§Examples
use dotscope::metadata::typesystem::{CilPrimitiveKind, ELEMENT_TYPE};

let bool_kind = CilPrimitiveKind::from_byte(ELEMENT_TYPE::BOOLEAN)?;
assert_eq!(bool_kind, CilPrimitiveKind::Boolean);

let int_kind = CilPrimitiveKind::from_byte(ELEMENT_TYPE::I4)?;
assert_eq!(int_kind, CilPrimitiveKind::I4);

pub const fn as_str(&self) -> &'static str

Returns a stable &'static str identifier for this primitive kind.

The strings follow ILAsm / ECMA-335 §I.8.2.2 conventions and are part of the stable public API — safe to persist (file, database, log line) and to parse. Pointer-sized integers and the structural kinds use the short ILAsm names rather than the C# / System.* aliases:

"void", "bool", "char", "int8", "uint8", "int16", "uint16", "int32", "uint32", "int64", "uint64", "float32", "float64", "native int", "native uint", "object", "string", "null", "typedref", "valuetype", "var", "mvar", "class".

Trait Implementations§

§

impl Clone for CilPrimitiveKind

§

fn clone(&self) -> CilPrimitiveKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Copy for CilPrimitiveKind

§

impl Debug for CilPrimitiveKind

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Display for CilPrimitiveKind

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Eq for CilPrimitiveKind

§

impl From<CilPrimitiveKind> for CilFlavor

§

fn from(kind: CilPrimitiveKind) -> Self

Converts to this type from the input type.
§

impl Hash for CilPrimitiveKind

§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for CilPrimitiveKind

§

fn eq(&self, other: &CilPrimitiveKind) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for CilPrimitiveKind

§

impl TryFrom<CilFlavor> for CilPrimitiveKind

§

type Error = ()

The type returned in the event of a conversion error.
§

fn try_from(flavor: CilFlavor) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

Gets the type name of self
Source§

impl<T> Boilerplate for T
where T: Copy + Send + Sync + Debug + PartialEq + 'static,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: AsAny + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

Source§

fn into_ast(self, _a: &A) -> A

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more