Enhanced C#
Language of your choice: library documentation
Nested classes | Public static fields | Static Public Member Functions | List of all members
Loyc.G Class Reference

Contains global functions that don't belong in any specific class. More...


Source file:

Remarks

Contains global functions that don't belong in any specific class.

Note: helper methods for parsing and printing tokens and hex digits have been moved to Loyc.Syntax.ParseHelpers.

Public static fields

static readonly object BoxedFalse = false
 Singleton false cast to object.
 
static readonly object BoxedTrue = true
 Singleton true cast to object.
 
static readonly object BoxedVoid = new @void()
 Singleton void cast to object.
 

Static Public Member Functions

static void Swap< T > (ref T a, ref T b)
 
static bool IsOneOf< T > (this T value, T item1, T item2)
 
static bool IsOneOf< T > (this T value, T item1, T item2, T item3)
 
static bool IsOneOf< T > (this T value, T item1, T item2, T item3, T item4)
 
static bool IsOneOf< T > (this T value, T item1, T item2, T item3, T item4, T item5)
 
static bool IsOneOf< T > (this T value, params T[] set)
 
static T With< T > (this T obj, Action< T > action)
 Calls action(obj), then returns the same object. More...
 
static T With< T > (this T obj, Func< T, T > action)
 Returns action(obj). This is similar to the other overload of this method, except that the action has a return value. More...
 
static Comparison< T > ToComparison< T > ()
 Gets a Comparison<T> for the specified type. More...
 
static Func< T, T, int > ToComparisonFunc< T > ()
 
static Comparison< T > ToComparison< T > (IComparer< T > pred)
 Converts an IComparer<T> to a Comparison<T>. More...
 
static Func< T, T, int > ToComparisonFunc< T > (IComparer< T > pred)
 Converts an IComparer<T> to a Func<T,T,int>. More...
 
static List< string > SplitCommandLineArguments (string listString)
 
static string MakeValidFileName (string text, char?replacement= '_', bool fancy=true)
 Replaces characters in text that are not allowed in file names with the specified replacement character. More...
 
static bool Verify (bool condition)
 Same as Debug.Assert except that the argument is evaluated even in a Release build. More...
 
static string BareHtmlEntityNameForAscii (char c)
 Gets a bare HTML entity name for an ASCII character, or null if there is no entity name for the given character, e.g. '"'=>"quot". More...
 
*</example > *static PushedTLV< T > PushTLV< T > (ThreadLocalVariable< T > variable, T newValue)
 

Member Function Documentation

static string Loyc.G.BareHtmlEntityNameForAscii ( char  c)
inlinestatic

Gets a bare HTML entity name for an ASCII character, or null if there is no entity name for the given character, e.g. '"'=>"quot".

The complete entity name is "&" + GetHtmlEntityNameForAscii(c) + ";". Some HTML entities have multiple names; this function returns one of them. There is a name in this table for all ASCII punctuation characters.

Referenced by Loyc.Ecs.EcsValidators.SanitizeIdentifier().

static string Loyc.G.MakeValidFileName ( string  text,
char?  replacement = '_',
bool  fancy = true 
)
inlinestatic

Replaces characters in text that are not allowed in file names with the specified replacement character.

Parameters
textText to make into a valid filename. The same string is returned if it is valid already.
replacementReplacement character, or null to simply remove bad characters.
fancyWhether to replace quotes and slashes with the non-ASCII characters ” and ⁄.
Returns
A string that can be used as a filename. If the output string would otherwise be empty, returns "_".
static Comparison<T> Loyc.G.ToComparison< T > ( )
inlinestatic

Gets a Comparison<T> for the specified type.

This method is optimized and does not allocate on every call.

Type Constraints
T :IComparable<T> 
static Comparison<T> Loyc.G.ToComparison< T > ( IComparer< T >  pred)
inlinestatic

Converts an IComparer<T> to a Comparison<T>.

static Func<T, T, int> Loyc.G.ToComparisonFunc< T > ( IComparer< T >  pred)
inlinestatic

Converts an IComparer<T> to a Func<T,T,int>.

static bool Loyc.G.Verify ( bool  condition)
inlinestatic

Same as Debug.Assert except that the argument is evaluated even in a Release build.

Referenced by Loyc.Collections.ReversedList< T >.RemoveAll(), Loyc.Collections.MSet< Symbol >.Toggle(), and Loyc.Syntax.Les.Les2Lexer.UnescapeString().

static T Loyc.G.With< T > ( this T  obj,
Action< T >  action 
)
inlinestatic

Calls action(obj), then returns the same object.

Returns
obj

This is the plain-C# equivalent of the with(obj) statement. Compared to the Enhanced C# statement, With() is disadvantageous since it requires a memory allocation to create the closure in many cases, as well as a delegate invocation that probably will not be inlined.

Caution: you cannot mutate mutable structs with this method. Call the other overload of this method if you will be modifying a mutable struct.

Foo(new Person() { Name = "John Doe" }.With(p => p.Commit(dbConnection)));

static T Loyc.G.With< T > ( this T  obj,
Func< T, T >  action 
)
inlinestatic

Returns action(obj). This is similar to the other overload of this method, except that the action has a return value.