Information technology — Common Language Infrastructure (CLI) — Technical Report: Common Generics

The CLI standard libraries (ISO/IEC 23271) provide a collection of common types that can be used by multiple languages. With the addition of generics to the CLI, the standard libraries have been extended to include a number of common generic types, in particular, collections. However, at present, these libraries do not include many simple generic types found in a number of different languages. Any language which uses these common types must implement them rather than deferring to the CLI library, thereby reducing language inter-operability. ISO/IEC TR 25438:2006 addresses this issue by providing a number of these common types.

Technologies de l'information — Infrastructure commune de langage (ICL) — Rapport technique: Génériques communs

General Information

Status
Published
Publication Date
27-Jul-2006
Current Stage
9093 - International Standard confirmed
Start Date
30-Oct-2013
Completion Date
14-Feb-2026

Overview - ISO/IEC TR 25438:2006 (Common Generics for CLI)

ISO/IEC TR 25438:2006 is a Technical Report for the Common Language Infrastructure (CLI) that proposes a set of common generic types to improve language inter‑operation on CLI platforms. The report identifies gaps in the CLI standard libraries (ISO/IEC 23271) where many simple, widely used generic types are missing and provides a standardized collection - including tuples, function/action delegates, optional and either types, and a Unit filler type. The collection is experimental and accompanied by a reference C# implementation (CommonGenericsLibrary.cs) and binaries (see http://kahu.zoot.net.nz/ecma).

Key topics and technical content

  • Generic tuples (product types)
    • Standard generic tuple types are specified for sizes 2 through 10 to provide consistent product-type representations across languages.
  • Function and procedure delegates
    • Standard generic delegate types for functions (returning a value) and actions/procedures (no return value) are defined (e.g., System.Function, System.Action family).
  • Optional type
    • A generic System.Optional structure that represents presence/absence of a value - distinct from System.Nullable - with comparison, conversion and helper methods.
  • Either type
    • A System.Either<A,B> structure that holds a value of one of two possible types and indicates which is present.
  • Unit (filler) type
    • A one-value type (Unit) intended for use where a generic parameter must exist but no meaningful value is required.
  • Utility types and helpers
    • Delegate conversion utilities (DelegateCast), tuple operations, equality/hashcode semantics and other method-level specifications are included to ensure consistent behavior.

Practical applications and who should use it

  • Language designers and implementers targeting the CLI (for example, languages hosted on .NET/CLI) can adopt these standard generics to avoid re‑implementing basic generic types and improve cross-language interoperability.
  • Library authors can rely on a common set of generic primitives (tuples, Optionals, Eithers, delegates) to provide predictable APIs for consumers across multiple languages.
  • Runtime and tooling developers (compilers, code analyzers, interop tools) benefit from standard semantics for delegates, equality, hashing and conversions.
  • Teams modernizing APIs will find the optional/either patterns useful for clearer null/absence handling and error/result modeling.

Related standards

  • ISO/IEC 23271 - Common Language Infrastructure (main CLI standard) - TR 25438 proposes extensions to the CLI library set.
  • Ecma TR/89 - Original Ecma proposal (TR/89) from which this Technical Report was prepared.

This Technical Report improves generic programming support in the CLI by standardizing small, commonly reused generic types that facilitate higher‑order programming and language inter‑operation.

Buy Documents

Technical report

ISO/IEC TR 25438:2006 - Information technology -- Common Language Infrastructure (CLI) -- Technical Report: Common Generics

English language (63 pages)
sale 15% off
Preview
sale 15% off
Preview
Technical report

ISO/IEC TR 25438:2006 - Information technology -- Common Language Infrastructure (CLI) -- Technical Report: Common Generics

English language (63 pages)
sale 15% off
Preview
sale 15% off
Preview

Get Certified

Connect with accredited certification bodies for this standard

BSI Group

BSI (British Standards Institution) is the business standards company that helps organizations make excellence a habit.

UKAS United Kingdom Verified

NYCE

Mexican standards and certification body.

EMA Mexico Verified

Sponsored listings

Frequently Asked Questions

ISO/IEC TR 25438:2006 is a technical report published by the International Organization for Standardization (ISO). Its full title is "Information technology — Common Language Infrastructure (CLI) — Technical Report: Common Generics". This standard covers: The CLI standard libraries (ISO/IEC 23271) provide a collection of common types that can be used by multiple languages. With the addition of generics to the CLI, the standard libraries have been extended to include a number of common generic types, in particular, collections. However, at present, these libraries do not include many simple generic types found in a number of different languages. Any language which uses these common types must implement them rather than deferring to the CLI library, thereby reducing language inter-operability. ISO/IEC TR 25438:2006 addresses this issue by providing a number of these common types.

The CLI standard libraries (ISO/IEC 23271) provide a collection of common types that can be used by multiple languages. With the addition of generics to the CLI, the standard libraries have been extended to include a number of common generic types, in particular, collections. However, at present, these libraries do not include many simple generic types found in a number of different languages. Any language which uses these common types must implement them rather than deferring to the CLI library, thereby reducing language inter-operability. ISO/IEC TR 25438:2006 addresses this issue by providing a number of these common types.

ISO/IEC TR 25438:2006 is classified under the following ICS (International Classification for Standards) categories: 35.060 - Languages used in information technology. The ICS classification helps identify the subject area and facilitates finding related standards.

ISO/IEC TR 25438:2006 is available in PDF format for immediate download after purchase. The document can be added to your cart and obtained through the secure checkout process. Digital delivery ensures instant access to the complete standard document.

Standards Content (Sample)


TECHNICAL ISO/IEC
REPORT TR
First edition
2006-08-01
Information technology — Common
Language Infrastructure (CLI) —
Technical Report: Common Generics
Technologies de l'information — Infrastructure commune de
langage (ICL) — Rapport technique: Génériques communs

Reference number
©
ISO/IEC 2006
PDF disclaimer
PDF files may contain embedded typefaces. In accordance with Adobe's licensing policy, such files may be printed or viewed but shall
not be edited unless the typefaces which are embedded are licensed to and installed on the computer performing the editing. In
downloading a PDF file, parties accept therein the responsibility of not infringing Adobe's licensing policy. The ISO Central Secretariat
accepts no liability in this area.
Adobe is a trademark of Adobe Systems Incorporated.
Details of the software products used to create the PDF file(s) constituting this document can be found in the General Info relative to
the file(s); the PDF-creation parameters were optimized for printing. Every care has been taken to ensure that the files are suitable for
use by ISO member bodies. In the unlikely event that a problem relating to them is found, please inform the Central Secretariat at the
address given below.
This CD-ROM contains:
1) the publication ISO/IEC TR 25438:2006 in portable document format (PDF), which can be viewed
using Adobe® Acrobat® Reader; and
2) the electronic attachment CommonGenericsLibrary.cs, a reference implementation written in C#.
Adobe and Acrobat are trademarks of Adobe Systems Incorporated.

©  ISO/IEC 2006
All rights reserved. Unless otherwise specified, no part of this CD-ROM may be reproduced, stored in a retrieval system or transmitted in
any form or by any means without prior permission from ISO. Requests for permission to reproduce this product should be addressed to
ISO copyright office • Case postale 56
...


TECHNICAL ISO/IEC
REPORT TR
First edition
2006-08-01
Information technology — Common
Language Infrastructure (CLI) —
Technical Report: Common Generics
Technologies de l'information — Infrastructure commune de
langage (ICL) — Rapport technique: Génériques communs

Reference number
©
ISO/IEC 2006
PDF disclaimer
This PDF file may contain embedded typefaces. In accordance with Adobe's licensing policy, this file may be printed or viewed but
shall not be edited unless the typefaces which are embedded are licensed to and installed on the computer performing the editing. In
downloading this file, parties accept therein the responsibility of not infringing Adobe's licensing policy. The ISO Central Secretariat
accepts no liability in this area.
Adobe is a trademark of Adobe Systems Incorporated.
Details of the software products used to create this PDF file can be found in the General Info relative to the file; the PDF-creation
parameters were optimized for printing. Every care has been taken to ensure that the file is suitable for use by ISO member bodies. In
the unlikely event that a problem relating to it is found, please inform the Central Secretariat at the address given below.

©  ISO/IEC 2006
All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized in any form or by any means,
electronic or mechanical, including photocopying and microfilm, without permission in writing from either ISO at the address below or
ISO's member body in the country of the requester.
ISO copyright office
Case postale 56 • CH-1211 Geneva 20
Tel. + 41 22 749 01 11
Fax + 41 22 749 09 47
E-mail copyright@iso.org
Web www.iso.org
Published in Switzerland
ii © ISO/IEC 2006 – All rights reserved

Contents Page
Foreword. v
Introduction . vi
1 Scope . 1
2 Rationale. 1
2.1 Reference vs. value tuples. 1
2.2 Interaction with other standard types. 2
3 Overview . 2
3.1 Tuple types . 2
3.2 Function and procedure types . 2
3.3 Unit . 2
3.4 Optional . 3
3.5 Either. 3
4 Action delegates . 3
4.1 System.Action delegate . 3
4.2 System.Action delegate. 4
4.3 System.Action delegate . 5
4.4 System.Action delegate. 6
4.5 System.Action delegate . 8
5 System.DelegateCast class . 9
5.1 DelegateCast.ToFunction(System.Predicate) method. 10
5.2 DelegateCast.ToPredicate(System.Function) method. 10
5.3 DelegateCast.ToFunction(System.Converter) method. 11
5.4 DelegateCast.ToConverter(System.Function) method. 12
5.5 DelegateCast.ToFunction(System.Comparison) method . 12
5.6 DelegateCast.ToComparison(System.Function) method . 13
6 System.Either Structure . 13
6.1 Either.Equals(System.Object) method. 15
6.2 Either.Equals(Either) method . 16
6.3 Either.First property. 17
6.4 Either.GetHashCode() method.17
6.5 Either.IsFirst property. 18
6.6 Either.IsSecond property. 19
6.7 Either.op_Equality(Either, Either) method. 19
6.8 Either.op_Inequality(Either, Either) method . 20
6.9 Either.Second property. 21
6.10 Either.MakeFirst(A aValue) method. 22
6.11 Either.MakeSecond(B bValue) method . 22
6.12 Either.ToString() method. 23
6.13 Either(A) constructor . 23
6.14 Either(B) constructor . 24
6.15 A Either.op_Explicit(System.Either) method . 25
6.16 B Either.op_Explicit(System.Either) method . 26
6.17 Either.op_Implicit(A) method . 27
6.18 Either.op_Implicit(B) method . 28
7 Function Delegates. 29
7.1 System.Function delegate . 29
7.2 System.Function delegate. 30
7.3 System.Function delegate . 31
© ISO/IEC 2006 – All rights reserved iii

7.4 System.Function delegate. 32
7.5 System.Function delegate . 33
7.6 System.Function delegate . 35
8 System.Optional structure. 36
8.1 Optional(T) constructor. 38
8.2 Optional.CompareTo(System.Object) method. 38
8.3 Optional.CompareTo(Optional) method. 40
8.4 Optional.Equals(System.Object) method. 41
8.5 Optional.Equals(Optional) method. 42
8.6 Optional.FromNullable(Nullable) method. 43
8.7 Optional.FromOptional(System.Optional) method . 44
8.8 Optional.GetHashCode() method.45
8.9 Optional.GetValueOrDefault() method. 45
8.10 Optional.GetValueOrDefault(T) method . 46
8.11 Optional.HasValue property . 46
8.12 Optional.op_Equality(Optional, Optional) method. 47
8.13 Optional.op_Explicit(System.Optional) method . 48
8.14 Optional.op_Implicit(T) method . 49
8.15 Optional.op_Inequality(Optional, Optional) method . 50
8.16 Optional.ToNullable(Optional) method. 51
8.17 Optional.ToOptional(T) method . 51
8.18 Optional.ToString() method. 52
8.19 Optional.Value property. 53
8.20 Optional.INullableValue.Value property . 53
9 Tuple structures System.Tuple … System.Tuple. 54
9.1 Tuple() constructors. 56
9.2 Tuple.Equals(System.Object) method. 56
9.3 Tuple.Equals(Tuple) method. 57
9.4 Tuple.ItemA, Tuple.ItemB, … Tuple.ItemJ field. 58
9.5 Tuple.GetHashCode() method. 58
9.6 Tuple.op_Equality(Tuple, Tuple) method. 59
9.7 Tuple.op_Implicit(KeyValuePair) method . 60
9.8 Tuple.op_Implicit(Tuple) method. 60
9.9 Tuple.op_Inequality(Tuple, Tuple) method . 61
9.10 Tuple.ToString() method. 62
10 System.Unit enum. 62
10.1 Unit.Unit field. 63

iv © ISO/IEC 2006 – All rights reserved

Foreword
ISO (the International Organization for Standardization) and IEC (the International Electrotechnical
Commission) form the specialized system for worldwide standardization. National bodies that are members of
ISO or IEC participate in the development of International Standards through technical committees
established by the respective organization to deal with particular fields of technical activity. ISO and IEC
technical committees collaborate in fields of mutual interest. Other international organizations, governmental
and non-governmental, in liaison with ISO and IEC, also take part in the work. In the field of information
technology, ISO and IEC have established a joint technical committee, ISO/IEC JTC 1.
International Standards are drafted in accordance with the rules given in the ISO/IEC Directives, Part 2.
The main task of the joint technical committee is to prepare International Standards. Draft International
Standards adopted by the joint technical committee are circulated to national bodies for voting. Publication as
an International Standard requires approval by at least 75 % of the national bodies casting a vote.
In exceptional circumstances, the joint technical committee may propose the publication of a Technical Report
of one of the following types:
— type 1, when the required support cannot be obtained for the publication of an International Standard,
despite repeated efforts;
— type 2, when the subject is still under technical development or where for any other reason there is the
future but not immediate possibility of an agreement on an International Standard;
— type 3, when the joint technical committee has collected data of a different kind from that which is
normally published as an International Standard (“state of the art”, for example).
Technical Reports of types 1 and 2 are subject to review within three years of publication, to decide whether
they can be transformed into International Standards. Technical Reports of type 3 do not necessarily have to
be reviewed until the data they provide are considered to be no longer valid or useful.
Attention is drawn to the possibility that some of the elements of this document may be the subject of patent
rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights.
ISO/IEC TR 25438 was prepared by Ecma International (as Ecma TR/89) and was adopted, under a special
“fast-track procedure”, by Joint Technical Committee ISO/IEC JTC 1, Information technology, in parallel with
its approval by national bodies of ISO and IEC.
© ISO/IEC 2006 – All rights reserved v

Introduction
This Technical Report defines a collection of types that are intended to enhance the common language nature
of the CLI, by facilitating language inter-operation. The collection includes generic tuples, functions, actions,
optional value representation, a type that can contain a value of one of two different types, and a utility filler
type.
These types are experimental and will be considered for inclusion in a future version of the CLI International
Standard. A reference implementation, written in C#, is included (see the accompanying file
CommonGenericsLibrary.cs). This implementation source is also available from
http://kahu.zoot.net.nz/ecma. A binary version is also available from that site, along with any updates
to the proposal.
Feedback on these types is encouraged. (Please send comments to ecmacli@zoot.net.nz.)

vi © ISO/IEC 2006 – All rights reserved

TECHNICAL REPORT ISO/IEC TR 25438:2006(E

Information technology — Common Language Infrastructure
(CLI) — Technical Report: Common Generics
1 Scope
The CLI standard libraries (ISO/IEC 23271) provide a collection of common types that can be used by multiple
languages. With the addition of generics to the CLI, the standard libraries have been extended to include a
number of common generic types, in particular, collections. However, at present, these libraries do not include
many simple generic types found in a number of different languages. Any language which uses these
common types must implement them rather than deferring to the CLI library, thereby reducing language inter-
operability. This Technical Report addresses this issue by providing a number of these common types.
Generic tuples (product types) are standard in a number of languages: C++ (template Pair), Ada, Haskell,
and Standard ML (SML). However, languages differ in the number of pre-defined tuple sizes supported by
their standard libraries; e.g. C++ provides just one (Pair) while Haskell provides eight (sizes 2 to 9) and SML
allows any size of tuple. This Technical Report provides nine (sizes 2 to 10).
Generic programming encourages “higher order” programming where generic functions (methods) take
function (delegate) type arguments that have generic types. Examples include Ada’s with and generic
constraints, and function arguments in Haskell and SML. In the CLI, function values are provided in the form
of delegates, so this proposal defines standard generic delegate types for functions (which return a value) and
procedures (which do not).
Another two types that occur in a number of languages are an optional type, which either contains a value of
some other type or an indication that such a value is not present; and an either type, which holds a value of
one of two possible types and an indication of which one is present. This proposal provides both of these.
Note The optional type is similar to, but different from, the type System.Nullable.
Finally, in existing generic languages, a need has been found for a filler type to be used when a particular
generic parameter is not required for a particular use of the generic type. A standard one-value type is often
provided for this purpose, often called Unit or Void. This Technical Report includes such a type.
2 Rationale
2.1 Reference vs. value tuples
In some languages (such as C++ and Ada) tuple types can be value or reference types, while in others (such
as Haskell and SML) they are always reference types. This implementation provides only value type tuples
(which can contain value or reference types). Boxed versions of these types can be used when reference
versions are required. Named boxed types would, of course, help greatly here, but these are not currently
provided by the CLI Standard.
A simple generic type, such as Boxed, can be written to address this issue. Such a type has been made
available in the reference implementation of this proposal. However it is not being considered for
standardization at this time.
© ISO/IEC 2006 – All rights reserved 1

2.2 Interaction with other standard types
The CLI Standard contains six types related to those in this proposal. These are:
System.Action: This type is just the first member of this collection's set of action types. As it is already
standardized it is not included here.
System.Comparison: This type is equivalent to this collection's Function. Conversion methods
are provided.
System.Converter: This type is equivalent to this collection's Function. Conversion methods are
provided.
System.Nullable: This type is a restricted version of this collection's Optional. The difference is that
Nullable is restricted to non-nullable value types, whereas Optional can also wrap reference types and
nullable value types. Both these choices are useful in different applications, so there is no clash between
these two types. This proposal includes operators on the Optional type to convert to/from Nullable
values.
System.Predicate: This type is equivalent to this collection's Function. However as the CLI
does not support type synonyms, these two types are (unfortunately) not equivalent. A separate static class
provides methods to convert between these two types. The methods are in a separate class as additional
methods cannot be declared on delegate types.
System.Collections.Generic.KeyValuePair: This is just a differently named equivalent of this collection's
Tuple. Conversion operators are provided on Tuple to convert to/from KeyValuePair.
3 Overview
3.1 Tuple types
Tuples are provided as value types with public fields, which mirrors their typical usage in current languages.
Overloading on arity is leveraged to provide eight standard tuple types.
The fields are named ItemA, ItemB, …, ItemI. A single n-ary constructor is provided to easily define all fields.
An Equals() method is provided and defined as the component fields being equal according to their Equals()
methods.
The corresponding GetHashCode() method and op_Equality and op_Inequality methods are provided.
ToString() is overridden to provide the typical tuple parenthesized notation.
For tuples of size 2, methods are provided to convert to/from values of type
System.Collections.Generic.KeyValuePair.
3.2 Function and procedure types
Standard delegates are provided for function types (System.Function<>) and procedures (System.Action<>).
Delegates are defined for 0 to 5 argument functions and 0 and 2 to 5 argument procedures. (The single
argument procedure is already included in the CLI Standard.)
3.3 Unit
The Unit type is a filler type. This is useful, for example, when an existing generic type is used, but one of its
type arguments is not required for the particular application.
2 © ISO/IEC 2006 – All rights reserved

3.4 Optional
The Optional
type represents either a value of type A, or the lack of a value. A value of this type is
immutable and provides two constructors, one providing a value, the other for providing no value. Properties
are provided to test for validity and to obtain the value. An exception is thrown if an attempt to access a non-
existent value.
3.5 Either
The Either type represents either a value of type A, or a value of type B. A value of this type is
immutable. Properties are provided to test which type of value is present and to obtain the value. An exception
is thrown if an attempt to access the value of one type is made when a value of the other type is present.
4 Action delegates
4.1 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action
extends System.Delegate
{
.method public hidebysig newslot virtual
instance void Invoke()
}
[C#]
public delegate void Action();
Assembly Info:
• Name:
• Public Key:
• Version:
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
© ISO/IEC 2006 – All rights reserved 3

Summary:
Represents a method that performs an action.
Parameters:
Inherits From: System.Delegate

Library: BCL
Description
A generic delegate type for zero-argument, methods which perform an action (return void).
4.2 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action`2
extends System.Delegate
{
.method public hidebysig newslot virtual
instance void Invoke(!0 argA,
!1 argB)
}
[C#]
public delegate void Action
(A argA,
B argB
);
Assembly Info:
• Name:
• Public Key:
• Version:
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
4 © ISO/IEC 2006 – All rights reserved

Summary:
Represents a method that performs an action using the supplied arguments.
Parameters:
Parameter Description
argA The first argument to the action.
argB The second argument to the action.

Inherits From: System.Delegate

Library: BCL
Description
A generic delegate type for two-argument methods, which perform an action (return void).
4.3 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action`3
extends System.Delegate
{
.method public hidebysig newslot virtual
instance void Invoke(!0 argA,
!1 argB,
!2 argC)
}
[C#]
public delegate void Action
(A argA,
B argB,
C argC
);
Assembly Info:
• Name:
• Public Key:
• Version:
© ISO/IEC 2006 – All rights reserved 5

• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
Summary:
Represents a method that performs an action using the supplied arguments.
Parameters:
Parameter Description
argA
The first argument to the action.
argB
The second argument to the action.
argC
The third argument to the action.

Inherits From: System.Delegate

Library: BCL
Description
A generic delegate type for three-argument methods, which perform an action (return void).
4.4 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action`4
extends System.Delegate
{
.method public hidebysig newslot virtual
instance void Invoke(!0 argA,
!1 argB,
!2 argC,
!3 argD)
}
[C#]
public delegate void Action
(A argA,
B argB,
C argC,
D argD
);
6 © ISO/IEC 2006 – All rights reserved

Assembly Info:
• Name:
• Public Key:
• Version:
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
Summary:
Represents a method that performs an action using the supplied arguments.
Parameters:
Parameter Description
argA The first argument to the action.
argB
The second argument to the action.
argC
The third argument to the action.
argD
The fourth argument to the action.

Inherits From: System.Delegate

Library: BCL
Description
A generic delegate type for four-argument methods, which perform an action (return void).
© ISO/IEC 2006 – All rights reserved 7

4.5 System.Action delegate
[ILAsm]
.class public auto ansi sealed System.Action`5
extends System.Delegate
{
.method public hidebysig newslot virtual
instance void Invoke(!0 argA,
!1 argB,
!2 argC,
!3 argD,
!4 argE)
}
[C#]
public delegate void Action
(A argA,
B argB,
C argC,
D argD,
E argE
);
Assembly Info:
• Name:
• Public Key:
• Version:
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.ICloneable
Summary:
Represents a method that performs an action using the supplied arguments.
8 © ISO/IEC 2006 – All rights reserved

Parameters:
Parameter Description
argA The first argument to the action.
argB The second argument to the action.
argC The third argument to the action.
argD The fourth argument to the action.
argE The fifth argument to the action.

Inherits From: System.Delegate

Library: BCL
Description
A generic delegate type for five-argument methods, which perform an action (return void).
5 System.DelegateCast class
[ILAsm]
.class public abstract sealed beforefieldinit System.DelegateCast
extends System.Object
[C#]
public static class DelegateCast
Assembly Info:
• Name:
• Public Key:
• Version:
• Attributes:
o CLSCompliantAttribute(true)
© ISO/IEC 2006 – All rights reserved 9

Summary
Provides methods for converting between System.Function<> and corresponding System.Predicate ,
System.Converter and System.Comparison delegate types.
Inherits From: System.Object
Library:
Thread Safety: This type is safe for multithreaded operations.

Description
5.1 DelegateCast.ToFunction(System.Predicate) method
[ILAsm]
.method public hidebysig static class Function`2
ToFunction(class Predicate`1 pred)
[C#]
public static Function ToFunction(Predicate pred)
Summary
Constructs a System.Function value equivalent to the given System.Predicate value.
Parameters
Parameter Description
pred The System.Predicate to convert.

Return Value
A System.Function value, functionally equivalent to the System.Predicate argument.
Description
5.2 DelegateCast.ToPredicate(System.Function) method
[ILAsm]
.method public hidebysig static class Predicate`1
ToPredicate(class Function`2 func)
[C#]
public static Predicate ToPredicate(Function func)
10 © ISO/IEC 2006 – All rights reserved

Summary
Constructs a System.Predicate value equivalent to the given System.Function value.
Parameters
Parameter Description
Func
The System.Function to convert.

Return Value
A System.Predicate value functionally equivalent to the System.Function argument.
Description
5.3 DelegateCast.ToFunction(System.Converter) method
[ILAsm]
.method public hidebysig static class Function`2
ToFunction(class Converter`2 conv)
[C#]
public static Function ToFunction(Converter conv)
Summary
Constructs a System.Function value equivalent to the given System.Converter value.
Parameters
Parameter Description
conv The System.Converter to convert.

Return Value
A System.Function value functionally equivalent to the System.Converter argument.
Description
© ISO/IEC 2006 – All rights reserved 11

5.4 DelegateCast.ToConverter(System.Function) method
[ILAsm]
.method public hidebysig static class Converter`2
ToConverter(class Function`2 func)
[C#]
public static Converter ToConverter(Function func)
Summary
Constructs a System.Converter value equivalent to the given System.Function value.
Parameters
Parameter Description
func The System.Function to convert.

Return Value
A System.Converter value functionally equivalent to the System.Function argument.
Description
5.5 DelegateCast.ToFunction(System.Comparison) method
[ILAsm]
.method public hidebysig static class Function`3
ToFunction(class Comparison`1 comp)
[C#]
public static Function ToFunction(Comparison comp)
Summary
Constructs a System.Function value equivalent to the given System.Comparison value.
Parameters
Parameter Description
comp The System.Comparison to convert.

12 © ISO/IEC 2006 – All rights reserved

Return Value
A System.Function value functionally equivalent to the System.Comparison argument.
Description
5.6 DelegateCast.ToComparison(System.Function) method
[ILAsm]
.method public hidebysig static class Comparison`1
ToComparison(class Function`3 func)
[C#]
public static Comparison ToComparison(Function func)
Summary
Constructs a System.Comparison value equivalent to the given System.Function value.
Parameters
Parameter Description
func The System.Function to convert.

Return Value
A System.Comparison value functionally equivalent to the System.Function argument.
Description
6 System.Either Structure
[ILAsm]
.class public sequential serializable sealed Either`2 extends
System.ValueType implements IEquatable`1>
[C#]
public struct Either : IEquatable>
Assembly Info:
• Name:
• Public Key:
© ISO/IEC 2006 – All rights reserved 13

• Version:
• Attributes:
o CLSCompliantAttribute(true)
Implements:
• System.IEquatable>
Summary
Contains a value of type A or a value of type B.
Inherits From: System.ValueType

Library:
Thread Safety: This type is not guaranteed to be safe for multithreaded operations.

Description
The System.Either value type represents either a value of a given type A or a value of a given type B. For
example, an instance of System.Either contains either a System.Int32 value or a
System.String value. Instances of this type are immutable.
An instance of System.Either has four key properties; IsFirst, IsSecond, First, and Second. IsFirst and
IsSecond are used to determine whether the current instance has a value of type A or a value of a given B. They
return true or false, and never throw an exception. First and Second return the value of the instance, provided it is
of the appropriate type (i.e., First or Second are true respectively); otherwise, they throw an exception.
Calling System.Either.IsFirst on an instance that has the default initial value returns true and calling
System.Either.First returns the default value of type A.
See the methods System.Either.MakeFirst and System.Either.MakeSecond for how to create new
instances initialized to values of type A or type B respectively.
See also System.Nullable (for value types T) and System.Optional (for all types T) that
represent either a value of type T or the lack of such a value.
14 © ISO/IEC 2006 – All rights reserved

6.1 Either.Equals(System.Object) method
[ILAsm]
.method public hidebysig virtual bool Equals(object other)
[C#]
public override bool Equals(object other)
Summary
Determines whether the current instance and the specified System.Object represent the same type and
value.
Parameters
Parameter Description
other The System.Object to compare to the current instance.

Return Value
The following table defines the conditions under which the return value is true or false:
Return Value Conditions
other is null or the current instance and other have different
false
types.
false
IsFirst is false and other.IsFirst is true.
false IsFirst is true and other.IsFirst is false.
First.Equals(other.First)
IsFirst is true and other.IsFirst is true
Second.Equals(other.Second)
IsFirst is false and other. IsFirst is false

Description
[Note: This method overrides System.Object.Equals.]
© ISO/IEC 2006 – All rights reserved 15

6.2 Either.Equals(Either) method
[ILAsm]
.method public hidebysig virtual bool Equals(valuetype Either`2 other)
[C#]
public bool Equals(Either other)
Summary
Determines whether the current instance and the specified System.Either represent the same value.
Parameters
Parameter Description
other
The System.Either to compare to the current instance.

Return Value
The following table defines the conditions under which the return value is true or false:
Return Value Conditions
false IsFirst is false and other.IsFirst is true.
false
IsFirst is true and other.IsFirst is false.
First.Equals(other.First)
IsFirst is true and other.IsFirst is true
Second.Equals(other.Second)
IsFirst is false and other. IsFirst is false

Description
[Note: This method implicitly implements the System.IEquatable>.Equals method.]
16 © ISO/IEC 2006 – All rights reserved

6.3 Either.First property
[ILAsm]
.property !0 First()
{
.get instance !0 get_First()
}
.method public hidebysig specialname instance !0 get_First()
[C#]
public A First { get; }
Summary
Gets the value of type A, if any, of the current instance.
Property Value
The value of type A of the current instance.
Behaviors
If System.Either.IsFirst is true, the instance contains a value of type A, and
System.Either.First returns that value. If System.Either.IsFirst is false, the instance has a
value of type B, and an attempt to read System.Either.First results in an exception.
This property is read-only.
Exceptions
Exception Condition
System.InvalidOperationException System.Either.IsFirst is false.
6.4 Either.GetHashCode() method
[ILAsm]
.method public hidebysig virtual int32 GetHashCode()
[C#]
public override int GetHashCode()
Summary
Generates a hash code for the value of the current instance.
© ISO/IEC 2006 – All rights reserved 17

Return Value
A System.Int32 containing the hash code for the value of the current instance is returned.
Description
The algorithm used to generate the hash code is unspecified.

[Note: This method overrides System.Object.GetHashCode.]
6.5 Either.IsFirst property
[ILAsm]
.property bool IsFirst()
{
.get instance bool get_IsFirst()
}
.method public hidebysig specialname instance bool get_IsFirst()
[C#]
bool IsFirst { get; }
Summary
Indicates whether the current instance contains a value of type A.
Property Value
true if the current instance was constructed by a call to MakeFirst or is the default value of Either;
otherwise, false.
Behaviors
If System.Either.IsFirst is true, the instance contains a value of type A,
System.Either.First returns that value, and System.Either.IsSecond returns false. If
System.Either.IsFirst is false, the instance contains a value of type B,
System.Either.IsSecond returns true, and an attempt to read System.Either.First results in a
System.InvalidOperationException exception.
This property is read-only.
18 © ISO/IEC 2006 – All rights reserved

6.6 Either.IsSecond property
[ILAsm]
.property bool IsSecond()
{
.get instance bool get_IsSecond()
}
.method public hidebysig specialname instance bool get_IsSecond()
[C#]
public bool IsSecond { get; }
Summary
Indicates whether the current instance contains a value of type B.
Property Value
true if the current instance was constructed by a call to MakeSecond; otherwise, false.
Behaviors
If System.Either.IsSecond is true, the instance contains a value of type B,
System.Either.Second returns that value, and System.Either.IsFirst returns false. If
System.Either.IsSecond is false, the instance contains a value of type A,
System.Either.IsFirst returns true, and an attempt to read System.Either.Second results in a
System.InvalidOperationException exception.
This property is read-only.
6.7 Either.op_Equality(Either, Either) method
[ILAsm]
.method public hidebysig specialname static
bool op_Equality(valuetype Either`2 left,
valuetype Either`2 right)
[C#]
public static bool operator==(Either left, Either right)
Summary
Determines whether the specified values are equal.
© ISO/IEC 2006 – All rights reserved 19

Parameters
Parameter Description
left The first Either value to compare.
right
The second Either value to compare.

Return Value
The following table defines the conditions under which the return value is true or false:
Conditions
Return Value
left.IsFirst right.IsFirst
left.Second.Equals(right.Second)
false false
false false true
false true false
left.First.Equals(right.First)
true true
Description
6.8 Either.op_Inequality(Either, Either) method
[ILAsm]
.method public hidebysig specialname static
bool op_Inequality(valuetype Either`2 left,
valuetype Either`2 right)
[C#]
public static bool operator!=(Either left, Either right)
Summary
Determines whether the specified values are not equal.
Parameters
Parameter Description
left The first Either value to compare.
right The second Either value to compare.
20 © ISO/IEC 2006 – All rights reserved

Return Value
The following table defines the conditions under which the return value is true or false:
Conditions
Return Value
left.IsFirst right.IsFirst
Not left.Second.Equals(right.Second)
false false
true false true
true true false
Not left.First.Equals(right.First)
true true
Description
6.9 Either.Second property
[ILAsm]
.property !1 Second()
{
.get instance !1 get_Second()
}
.method public hidebysig specialname instance !1 get_Second()
[C#]
public B Second { get; }
Summary
Gets the value of type B, if any, of the current instance.
Property Value
The value of type B of the current instance.
Behaviors
If System.Either.IsSecond is true, the instance contains a value of type B, and
System.Either.Second returns that value. If System.Either.IsSecond is false, the instance has
a value of type A, and an attempt to read System.Either.Second results in an exception.
This property is read-only.
© ISO/IEC 2006 – All rights reserved 21

Exceptions
Exception Condition
System.InvalidOperationException System.Either.IsSecond is false.
6.10 Either.MakeFirst(A aValue) method
[ILAsm]
public hidebysig static valuetype Either`MakeFirst(!0 aValue)
[C#]
public static Either ...

Questions, Comments and Discussion

Ask us and Technical Secretary will try to provide an answer. You can facilitate discussion about the standard in here.

Loading comments...