class SandboxSystemExtensions

in global :: Sandbox

😔 No documentation found.


public static void InvokeWithWarning( Action action )

Call an action, swallow any exceptions with a warning

public static long FromBase36( string input )

Decode the Base36 Encoded string into a number

public static int GetEpoch( DateTime d )

Returns the UNIX time stamp - number of seconds since 1st of January, 1970.

public static DateTime ToDateTime( int seconds )

Converts UNIX time stamp to a DateTime object.

  • seconds UNIX time stamp in seconds.

public static DateTime ToDateTime( long seconds )

🤡 Doc inheritance is not yet supported.

No summary.

public static string Humanize( DateTime dateTime )

Convert date into a human readable relative time string.

public static string Humanize( DateTimeOffset dateTime )

Convert date into a human readable relative time string.

public static string Humanize( TimeOnly dateTime )

Convert date into a human readable relative time string.

public static string Humanize( DateOnly dateTime )

Convert date into a human readable relative time string.

public static string Humanize( TimeSpan dateTime, int precision = 1 )

Convert date into a human readable relative time string.

public static string FormatSeconds( long secs )

Formats the given value in format "1w2d3h4m5s". Will not display 0 values.

  • secs Time to format, in seconds.

public static string FormatSeconds( ulong secs )

🤡 Doc inheritance is not yet supported.

No summary.

public static string FormatSecondsLong( long secs )

Formats the given value in format "4 weeks, 3 days, 2 hours and 1 minutes". Will not display 0 values. Will not display seconds if value is more than 1 hour.

  • secs Time to format, in seconds.

public static string FormatSecondsLong( ulong secs )

🤡 Doc inheritance is not yet supported.

No summary.

public static string FormatNumberShort( long num )

"1500" becomes "1,500", "15 000" becomes "15K", "15 000 000" becomes "15KK", etc.

public static string FormatNumberShort( ulong num )

🤡 Doc inheritance is not yet supported.

No summary.

public static int UnsignedMod( int a, int b )

Does what you expected to happen when you did "a % b", that is, handles negative values by returning a positive number from the end.

public static int BitsSet( int i )

Returns the number of bits set in an integer. This us usually used for flags to count the amount of flags set.

public static string Plural( int a, string single, string plural )

Return single if 1 else plural

public static string FormatWithSuffix( int num )

Change 1 to 1st, 2 to 2nd etc

public static string KiloFormat( int num )

Format a large number into "1045M", "56K"

public static string KiloFormat( long num )

Format a large number into "1045M", "56K"

public static string Humanize( TimeSpan timespan, bool shortVersion = False, bool minutes = True, bool hours = True, bool days = True )

Humanize a timespan into "x hours", "x seconds"

public static string ToMetric( int input, int decimals = 2 )

Convert 1100 to 1.1k

public static bool IsPowerOfTwo( int x )

Return true if the number is a power of two (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, etc)

public static string ToMetric( long input, int decimals = 2 )

Convert 1100 to 1.1k

public static string ToMetric( double input, int decimals = 2 )

Convert 1100 to 1.1k

public static string ToMetric( float input, int decimals = 2 )

Convert 1100 to 1.1k

public static double Double( Random self, double min, double max )

Returns a double between min and max

public static float Float( Random self )

Returns a random float between 0 and 1

public static float Float( Random self, float min, float max )

Returns a random float between min and max

public static float Float( Random self, float max )

Returns a random float between 0 and max (or 1)

public static double Double( Random self, double max = 1 )

Returns a random double between 0 and max (or 1)

public static int Int( Random self, int min, int max )

Returns a random int between min and max (inclusive)

public static int Int( Random self, int max )

Returns a random int between 0 and max (inclusive)

public static Color Color( Random self )

Returns a random Color

public static Rotation Rotation( Random self )

Returns a uniformly random rotation.

public static Angles Angles( Random self )

Returns the angles of a uniformly random rotation.

public static float Gaussian( Random self, float mean = 0, float stdDev = 1 )

Sample from a Gaussian distribution with a given mean and standard deviation.

public static Vector2 VectorInSquare( Random self, float extents = 1 )

Uniformly samples a 2D position from a square with coordinates in the range - to +.

public static Vector3 VectorInCube( Random self, float extents = 1 )

Uniformly samples a 3D position from a cube with coordinates in the range - to +.

public static Vector3 VectorInCube( Random self, ref BBox box )

Uniformly samples a 3D position from a cube

public static Vector2 VectorInCircle( Random self, float radius = 1 )

Uniformly samples a 2D position from all points with distance at most from the origin.

public static Vector3 VectorInSphere( Random self, float radius = 1 )

Uniformly samples a 3D position from all points with distance at most from the origin.

public static bool IsBasedOnGenericType( Type src, Type test )

Returns if this type is based on a given generic type.

  • src The type to test.
  • test The type to test against. Typically this will be something like typeof( MyType<> )

public static bool CheckValidationAttributes( PropertyInfo prop, object obj, ref string[] errors, string name = null )

Check all s on this property, and get the error messages if there are any.

  • prop The property whose arguments to test.
  • obj Instance of the object this property is of.
  • errors If returned false, these will be the error messages to display.
  • name Override the property name in error messages.
  • Returns Returns true if all checks have passed or there is no attributes to test, false if there were errors.

public static bool IsInitOnly( PropertyInfo property )

Determine if this property is init-only.

  • property The property to test.
  • Returns Returns true if the property is init-only, false otherwise.

public static string ToSimpleString( Type type, bool includeNamespace = True )

Returns this type's name, with nicer formatting for generic types.

public static string ToSimpleString( MemberInfo member, bool includeNamespace = True )

Returns this member's name qualified by its declaring type, with nicer formatting for generics.

public static string ToSimpleString( Delegate deleg, bool includeNamespace = True )

Returns a nice name for the given delegate, based on the method that implements it.

public static string ReadNullTerminatedString( Stream stream, long offset )

Read a null terminated string from the stream, at given offset.

  • stream The stream to read from.
  • offset Offset where to start reading, from the beginning of the stream.

public static string QuoteSafe( string str, bool optional = False )

Puts quote marks around a string. Internal quotes are backslashed.

public static string HtmlEncode( string str )

🤡 Doc inheritance is not yet supported.

No summary.

public static string UrlEncode( string str )

🤡 Doc inheritance is not yet supported.

No summary.

public static string CollapseWhiteSpace( string str )

Collapse sequences of whitespace into a single whitespace

public static string CollapseSpacesAndPreserveLines( string str )

Collapse sequences of spaces and tabs into a single space, preserving newlines

public static string NormalizeFilename( string str, bool enforceInitialSlash = True )

Puts a filename into the format /path/filename.ext (from path\FileName.EXT)

public static string NormalizeFilename( string str, bool enforceInitialSlash, bool enforceLowerCase )

Puts a filename into the format /path/filename.ext (from path\FileName.EXT)

public static string WithExtension( string path, string ext )

Adds or replaces the extension of to .

  • path A file path with or without an extension.
  • ext A file extension with or without a leading period.

public static string SimplifyPath( string str )

Gets rid of ../'s (from /path/folder/../file.txt to /path/file.txt)

public static string[] SplitQuotesStrings( string input )

in : I am "splitting a" string "because it's fun " out : ["I", "am", "splitting a", "string", "because it's fun"]

public static float ToFloat( string str, float Default = 0 )

Convert to , if not then return .

public static float ToFloatEval( string expression, float Default = 0 )

Convert to . Might be a string formula. This is always going to be slower than a call to .

public static float ToDouble( string str, float Default = 0 )

Convert to , if not then return .

public static double ToDoubleEval( string expression, double Default = 0 )

Convert to . Might be a string formula. This is always going to be slower than a call to .

public static decimal ToDecimal( string str, decimal Default = 0 )

128-bit data type that returns sane results for almost any input. All other numeric types can cast from this.

public static uint ToUInt( string str, int Default = 0 )

Convert to , if not then return .

public static int ToInt( string str, int Default = 0 )

Convert to , if not then return .

public static int ToIntEval( string expression, int Default = 0 )

Convert to . Might be a string formula. This is always going to be slower than a call to .

public static ulong ToULong( string str, ulong Default = 0 )

Convert to , if not then return .

public static long ToLong( string str, long Default = 0 )

Convert to , if not then return .

public static long ToLongEval( string expression, long Default = 0 )

Convert to . Might be a string formula. This is always going to be slower than a call to .

public static bool ToBool( string str )

Try to convert to bool. Inputs can be true, false, yes, no, 0, 1, null (caps insensitive)

public static string Truncate( string str, int maxLength, string appendage = null )

If the string is longer than this amount of characters then truncate it If appendage is defined, it will be appended to the end of truncated strings (ie, "..")

public static string TruncateFilename( string str, int maxLength, string appendage = null )

If the string is longer than this amount of characters then truncate it If appendage is defined, it will be appended to the end of truncated strings (ie, "..")

public static bool Contains( string source, string toCheck, StringComparison comp )

An extended Contains which takes a StringComparison.

public static string Snippet( string source, string find, int padding )

Given a large string, find all occurrences of a substring and return them with padding. This is useful in situations where you're searching for a word in a hug body of text, and want to show how it's used without displaying the whole text.

public static string ToTitleCase( string source )

Convert a variable name to something more user friendly.

public static string RemoveBadCharacters( string str )

Removes bad, invisible characters that are commonly used to exploit. https://en.wikipedia.org/wiki/Zero-width_non-joiner

public static string Base64Encode( string plainText )

Convert to a base64 encoded string

public static string Base64Decode( string base64EncodedData )

Convert from a base64 encoded string

public static object ToType( string str, Type t )

Try to politely convert from a string to another type

public static bool TryToType( string str, Type t, ref object Value )

Try to politely convert from a string to another type

public static int FastHash( string str )

Generate FNV-1a hash from given string.

public static string Columnize( string str, int maxLength, bool right = False )

convert "string" into "string " or " string"

public static bool WildcardMatch( string str, string wildcard )

Returns true if this string matches a wildcard match. Check is case insensitive.

public static string TrimQuoted( string str, bool ignoreSurroundingSpaces = False )

The string might start and end in quotes ( ", ' ), remove those if that is the case.

public static int Distance( string source, string target )

Return the distance between two strings. Useful for ordering strings by similarity

public static bool IsValidTag( string source )

Is this string a valid Tag. This is a way to check if a string is a valid tag, project wide. So our logic is always the same. - not null - between 1 and 32 chars - a-z

public static string GetFilenameSafe( string input )

Make the passed in string filename safe. This replaces any invalid characters with "_".

public static int GetManagedSize( Type t )

Get the managed size of a given type. This matches an IL-level sizeof(t), even if it cannot be determined normally in C#. Note that sizeof(t) != Marshal.SizeOf(t) when t is char or bool.

Remarks: An IL-level sizeof(t) will return sizeof(IntPtr) for reference types, as it refers to the size on stack or in an object, not the size on heap.

public static bool IsValid( IValid obj )

Returns false if object is null or if returns false.

public static IEnumerable<Vector3> TcbSpline( IEnumerable<Vector3> points, int interpolation, float tension, float continuity, float bias )

😔 No documentation found.

public static IEnumerable<Vector3> CatmullRomSpline( IEnumerable<Vector3> points, int interpolation )

😔 No documentation found.

public static string ToRemainingTimeString( TimeSpan span )

😔 No documentation found.

public static string ToRelativeTimeString( TimeSpan span )

😔 No documentation found.

public string ToString( )

😔 No documentation found.

public Type GetType( )

😔 No documentation found.

public int GetHashCode( )

😔 No documentation found.

public static T WithFlag( T value, T flag, bool set )

😔 No documentation found.

public static bool Contains( T value, T flag )

😔 No documentation found.

public static string SizeFormat( int bytes )

😔 No documentation found.

public static string SizeFormat( long bytes )

😔 No documentation found.

public static T Clamp( T input, T min, T max )

😔 No documentation found.

public static string FormatBytes( T input, bool shortFormat = False )

😔 No documentation found.

public static T GetPropertyValue( JsonObject jso, string membername, ref T defaultvalue )

😔 No documentation found.

public static Type GetCommonBaseType( IEnumerable<Type> types )

😔 No documentation found.

public static Task ForEachTaskAsync( IEnumerable<T> source, Func<T,Task> body, int maxRunning = 8, CancellationToken token = null )

😔 No documentation found.

public static Dictionary<TKey,TValue> Clone( Dictionary<TKey,TValue> dict )

😔 No documentation found.

public static TValue GetOrCreate( IDictionary<TKey,TValue> dict, TKey key )

😔 No documentation found.

public static Vector2 Gaussian2D( Random self, Nullable<Vector2> mean = null, Nullable<Vector2> stdDev = null )

😔 No documentation found.

public static Vector3 Gaussian3D( Random self, Nullable<Vector3> mean = null, Nullable<Vector3> stdDev = null )

😔 No documentation found.

public static Vector4 Gaussian4D( Random self, Nullable<Vector4> mean = null, Nullable<Vector4> stdDev = null )

😔 No documentation found.

public static string ToRelativeTimeString( DateTime dateTime )

😔 No documentation found.

public static string ToBase36( T i )

😔 No documentation found.

public static void InvokeWithWarning( Action<T> action, T arg0 )

😔 No documentation found.

public bool Equals( object obj )

😔 No documentation found.

public static T FromArray( Random self, T[] array, T defVal = null )

😔 No documentation found.

public static T FromList( Random self, List<T> array, T defVal = null )

😔 No documentation found.

public static int AsInt( T value )

😔 No documentation found.

public static T GetAttributeOfType( Enum enumVal )

😔 No documentation found.