C# feature sync: extension
types
#542
Labels
Area-API
The issue is bound with APIs.
C# feature sync
The issue is bound with C#.
Kind-feature request
The issue is about the feature request.
Milestone
C# language design team wants to introduce a new feature called
extension
, a new type kind in C# type system.What is the feature?
This feature will allow you extending nearly everything. In C# 3, we have a feature called "Extension Methods", which can define a method that can be invoked like a normal instance:
Then you can use this method, just like the type
int
contains this method:Begin with C# 13, the feature expands the rule, to extend nearly all member kinds of a type:
Although constructors cannot be extended, this feature is still "good enough" for our coding environment.
I will sync the solution, using this feature to extend all types if worth.
To-do list
object
ReinterpretCast<>
: Cast the object to the other type without memory bits change, same asUnsafe.As<,>
.operator true
andoperator false
: Determine whether a reference is notnull
.string
operator *(string, int)
: Repeats the string multiple times (return astring[]
).operator /(string, int)
: Split the string to multiple sub-strings of the specified length.operator /(string, char)
: Split the string using the specified character separator.operator /(string, string)
: Split the string using the specified string separator.char
operator *(char, int)
: Repeats the character multiple times.byte
,sbyte
,ushort
,short
,uint
,int
,ulong
,long
,nint
andnuint
this[int index]
: Gets the bit at the specified index.GetEnumerator
: Iterates on each bit position.operator true
andoperator false
: Check whether the value is not 0.T.MinValue
andT.MaxValue
: Defines the minimal and maximum value.T.All
: Defines all flags combined for an enumeration type markedFlagsAttribute
.T.None
: Introduces the field that holds the default value.Reinterpret<TBase, TResult>
: Converts the enumeration field of typeTBase
toTResult
, with whose name is same; equivalent toEnum.Parse<TResult>(field.ToString())
.sbyte
,byte
,short
,ushort
,int
,uint
,long
,ulong
,nint
andnuint
Fallback
: Equalssizeof(TInteger) << 3
, meaning the return value ofTrailingZeroCount(TInteger)
on value equals 0IEnumerable
andIEnumerable<T>
this[int index]
: CallsElementAt
.Count
: CallsCount()
.Slice
: Slices the collection, also be used in slice operator..
.operator *
: CallsAggregate
.IGetSubsetMethod<TSelf, TSource>
:operator &(in TSelf, int)
: CallsGetSubsetsExact
.operator |(in TSelf, int)
: CallsGetSubsetsLower
.List<T>
operator +
: CallsAdd
.operator -
: CallsRemove
.implicit operator ReadOnlySpan<T>
: Implicit cast toReadOnlySpan<T>
.implicit operator Span<T>
: Implicit cast toSpan<T>
.StringBuilder
operator >>
: Print formatted text from builder.operator <<
: Additem.ToString
into bulider.explicit operator: in T -> T*
The text was updated successfully, but these errors were encountered: