1
<Type Name="ObjectCoda" FullName="Cadenza.ObjectCoda">
2
  <TypeSignature Language="C#" Value="public static class ObjectCoda" />
3
  <TypeSignature Language="ILAsm" Value=".class public auto ansi abstract sealed beforefieldinit ObjectCoda extends System.Object" />
4
  <AssemblyInfo>
5
    <AssemblyName>Cadenza</AssemblyName>
6
    <AssemblyVersion>0.1.0.0</AssemblyVersion>
7
  </AssemblyInfo>
8
  <Base>
9
    <BaseTypeName>System.Object</BaseTypeName>
10
  </Base>
11
  <Interfaces />
12
  <Docs>
13
    <summary>Extension methods on <see cref="T:System.Object" />.</summary>
14
    <remarks>
15
    </remarks>
16
  </Docs>
17
  <Members>
18
    <Member MemberName="Just&lt;T&gt;">
19
      <MemberSignature Language="C#" Value="public static Cadenza.Maybe&lt;T&gt; Just&lt;T&gt; (this T self);" />
20
      <MemberSignature Language="ILAsm" Value=".method public static hidebysig valuetype Cadenza.Maybe`1&lt;!!T&gt; Just&lt;T&gt;(!!T self) cil managed" />
21
      <MemberType>Method</MemberType>
22
      <AssemblyInfo>
23
        <AssemblyVersion>0.1.0.0</AssemblyVersion>
24
      </AssemblyInfo>
25
      <ReturnValue>
26
        <ReturnType>Cadenza.Maybe&lt;T&gt;</ReturnType>
27
      </ReturnValue>
28
      <TypeParameters>
29
        <TypeParameter Name="T" />
30
      </TypeParameters>
31
      <Parameters>
32
        <Parameter Name="self" Type="T" RefType="this" />
33
      </Parameters>
34
      <Docs>
35
        <typeparam name="T">
36
          The type to convert into a <see cref="T:Cadenza.Maybe{T}" />.
37
        </typeparam>
38
        <param name="self">
39
          A value of type <typeparamref name="T" /> to convert into a 
40
          <see cref="T:Cadenza.Maybe{T}" />.
41
        </param>
42
        <summary>
43
          Create a new <see cref="T:Cadenza.Maybe{T}" /> instance
44
          initialized to a specified value.  The returned value will not be 
45
          <see cref="F:Cadenza.Maybe{T}.Nothing" />.
46
        </summary>
47
        <returns>
48
          <para>
49
            A new <see cref="T:Cadenza.Maybe{T}" /> instance
50
            initialized to a specified value.
51
          </para>
52
          <para>
53
            The returned value will not be 
54
            <see cref="F:Cadenza.Maybe{T}.Nothing" />.
55
          </para>
56
        </returns>
57
        <remarks>
58
          <para>
59
            Use this method when you want to ensure that 
60
            <see cref="T:Cadenza.Maybe{T}" /> instance is created in which
61
            <see cref="P:Cadenza.Maybe{T}.Value" /> will not throw.
62
          </para>
63
        </remarks>
64
        <exception cref="T:System.ArgumentNullException">
65
          <typeparamref name="T" /> is a reference type and
66
          <paramref name="self" /> is <see langword="null" />.
67
        </exception>
68
        <altmember cref="M:Cadenza.ObjectCoda.ToMaybe``1(``0)" />
69
      </Docs>
70
    </Member>
71
    <Member MemberName="Match&lt;TSource,TResult&gt;">
72
      <MemberSignature Language="C#" Value="public static TResult Match&lt;TSource,TResult&gt; (this TSource self, Func&lt;TSource,Cadenza.Maybe&lt;TResult&gt;&gt;[] matchers);" />
73
      <MemberSignature Language="ILAsm" Value=".method public static hidebysig !!TResult Match&lt;TSource, TResult&gt;(!!TSource self, class System.Func`2&lt;!!TSource, valuetype Cadenza.Maybe`1&lt;!!TResult&gt;&gt;[] matchers) cil managed" />
74
      <MemberType>Method</MemberType>
75
      <AssemblyInfo>
76
        <AssemblyVersion>0.1.0.0</AssemblyVersion>
77
      </AssemblyInfo>
78
      <ReturnValue>
79
        <ReturnType>TResult</ReturnType>
80
      </ReturnValue>
81
      <TypeParameters>
82
        <TypeParameter Name="TSource" />
83
        <TypeParameter Name="TResult" />
84
      </TypeParameters>
85
      <Parameters>
86
        <Parameter Name="self" Type="TSource" RefType="this" />
87
        <Parameter Name="matchers" Type="System.Func&lt;TSource,Cadenza.Maybe&lt;TResult&gt;&gt;[]">
88
          <Attributes>
89
            <Attribute>
90
              <AttributeName>System.ParamArray</AttributeName>
91
            </Attribute>
92
          </Attributes>
93
        </Parameter>
94
      </Parameters>
95
      <Docs>
96
        <typeparam name="TSource">The source type.</typeparam>
97
        <typeparam name="TResult">The result type.</typeparam>
98
        <param name="self">
99
          A value of type <typeparamref name="TSource" /> to convert to 
100
          <typeparamref name="TResult" />.
101
        </param>
102
        <param name="matchers">
103
          A <see cref="T:System.Func{TSource,Cadenza.Maybe{TResult}}" />
104
          array containing the conversion routines to try, in order, to
105
          convert <paramref name="self" /> into a 
106
          <typeparamref name="TResult" />.
107
        </param>
108
        <summary>
109
          Converts the <typeparamref name="TSource" /> instance 
110
          <paramref name="self" /> into a <typeparamref name="TResult" />.
111
        </summary>
112
        <returns>
113
          A value of type <typeparamref name="TResult" />, as returned by one
114
          of the conversion delegates in <paramref name="matchers" />.
115
        </returns>
116
        <remarks>
117
          <block subset="none" type="behaviors">
118
            <para>
119
              <paramref name="self" /> is converted into a 
120
              <typeparamref name="TResult" /> instance by trying each
121
              <see cref="T:System.Func{TSource,Cadenza.Maybe{TResult}}" />
122
              within <paramref name="matchers" />.
123
            </para>
124
            <para>
125
              This method returns the value of
126
              where <see cref="P:Cadenza.Maybe{TResult}.Value" /> 
127
              for the first delegate to return a
128
              <see cref="T:Cadenza.Maybe{TResult}" /> instance
129
              where <see cref="P:Cadenza.Maybe{TResult}.HasValue" />
130
              is <see langword="true" />.
131
            </para>
132
            <para>
133
              If no 
134
              <see cref="T:System.Func{TSource,Cadenza.Maybe{TResult}}" />
135
              returns a 
136
              <see cref="T:Cadenza.Maybe{TResult}" /> instance
137
              where <see cref="P:Cadenza.Maybe{TResult}.HasValue" />
138
              is <see langword="true" />, then an
139
              <see cref="T:System.InvalidOperationException" /> is thrown.
140
            </para>
141
          </block>
142
          <code lang="C#" src="../../Test/Cadenza/ObjectCodaTest.cs#Match">Assert.AreEqual ("foo",
143
	"foo".Match (
144
		s =&gt; Maybe.When (s.Length != 3, "bar!"),
145
		s =&gt; s.Just ()));
146
Assert.AreEqual ("bar!",
147
	5.Match (
148
		v =&gt; Maybe.When (v != 3, "bar!"),
149
		v =&gt; v.ToString ().Just()));
150
var m = new Func&lt;string, Maybe&lt;int&gt;&gt;[] {
151
	v =&gt; Maybe.When (v == "bar",    1),
152
	v =&gt; Maybe.When (v.Length == 5, 2),
153
	v =&gt; (-1).Just (),
154
};
155
Assert.AreEqual (1, "bar".Match (m));
156
Assert.AreEqual (2, "12345".Match (m));
157
Assert.AreEqual (-1, "*default*".Match (m));
158
</code>
159
        </remarks>
160
        <exception cref="T:System.ArgumentNullException">
161
          <paramref name="matchers" /> is <see langword="null" />.
162
        </exception>
163
        <exception cref="T:System.InvalidOperationException">
164
          None of the 
165
          <see cref="T:System.Func{TSource,Cadenza.Maybe{TResult}}" />
166
          delegates within <paramref name="matchers" /> returned a 
167
          <see cref="T:Cadenza.Maybe{TResult}" /> instance where
168
          <see cref="P:Cadenza.Maybe{TResult}.HasValue" /> was
169
          <see langword="true" />.
170
        </exception>
171
        <altmember cref="M:Cadenza.Maybe.When``1(System.Boolean,``0)" />
172
        <altmember cref="M:Cadenza.Maybe.When``1(System.Boolean,System.Func{``0})" />
173
      </Docs>
174
    </Member>
175
    <Member MemberName="ToMaybe&lt;T&gt;">
176
      <MemberSignature Language="C#" Value="public static Cadenza.Maybe&lt;T&gt; ToMaybe&lt;T&gt; (this T self);" />
177
      <MemberSignature Language="ILAsm" Value=".method public static hidebysig valuetype Cadenza.Maybe`1&lt;!!T&gt; ToMaybe&lt;T&gt;(!!T self) cil managed" />
178
      <MemberType>Method</MemberType>
179
      <AssemblyInfo>
180
        <AssemblyVersion>0.1.0.0</AssemblyVersion>
181
      </AssemblyInfo>
182
      <ReturnValue>
183
        <ReturnType>Cadenza.Maybe&lt;T&gt;</ReturnType>
184
      </ReturnValue>
185
      <TypeParameters>
186
        <TypeParameter Name="T" />
187
      </TypeParameters>
188
      <Parameters>
189
        <Parameter Name="self" Type="T" RefType="this" />
190
      </Parameters>
191
      <Docs>
192
        <typeparam name="T">
193
          The type to convert into a <see cref="T:Cadenza.Maybe{T}" />.
194
        </typeparam>
195
        <param name="self">
196
          A value of type <typeparamref name="T" /> to convert into a 
197
          <see cref="T:Cadenza.Maybe{T}" />.
198
        </param>
199
        <summary>
200
          Create a new <see cref="T:Cadenza.Maybe{T}" /> instance
201
          initialized to a specified value.  The returned value may be 
202
          <see cref="F:Cadenza.Maybe{T}.Nothing" />.
203
        </summary>
204
        <returns>
205
          <para>
206
            A new <see cref="T:Cadenza.Maybe{T}" /> instance
207
            initialized to a specified value.
208
          </para>
209
          <block subset="none" type="note">
210
            The value returned may be 
211
            <see cref="F:Cadenza.Maybe{T}.Nothing" />.
212
          </block>
213
        </returns>
214
        <remarks>
215
          <para>
216
            Use this method when you want to ensure that a possibly invalid
217
            <see cref="T:Cadenza.Maybe{T}" /> instance is created.
218
            If <typeparamref name="T" /> is a reference type and 
219
            <paramref name="self" /> is <see langword="null" />, then
220
            <see cref="F:Cadenza.Maybe{T}.Nothing" /> will be returned;
221
            otherwise, a new <see cref="T:Cadenza.Maybe{T}" /> will be
222
            created containing the value <paramref name="self" />.
223
          </para>
224
        </remarks>
225
        <altmember cref="M:Cadenza.ObjectCoda.Just``1(``0)" />
226
      </Docs>
227
    </Member>
228
    <Member MemberName="TraverseBreadthFirst&lt;TSource,TResult&gt;">
229
      <MemberSignature Language="C#" Value="public static System.Collections.Generic.IEnumerable&lt;TResult&gt; TraverseBreadthFirst&lt;TSource,TResult&gt; (this TSource self, Func&lt;TSource,TResult&gt; valueSelector, Func&lt;TSource,System.Collections.Generic.IEnumerable&lt;TSource&gt;&gt; childrenSelector);" />
230
      <MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Collections.Generic.IEnumerable`1&lt;!!TResult&gt; TraverseBreadthFirst&lt;TSource, TResult&gt;(!!TSource self, class System.Func`2&lt;!!TSource, !!TResult&gt; valueSelector, class System.Func`2&lt;!!TSource, class System.Collections.Generic.IEnumerable`1&lt;!!TSource&gt;&gt; childrenSelector) cil managed" />
231
      <MemberType>Method</MemberType>
232
      <AssemblyInfo>
233
        <AssemblyVersion>0.1.0.0</AssemblyVersion>
234
      </AssemblyInfo>
235
      <ReturnValue>
236
        <ReturnType>System.Collections.Generic.IEnumerable&lt;TResult&gt;</ReturnType>
237
      </ReturnValue>
238
      <TypeParameters>
239
        <TypeParameter Name="TSource" />
240
        <TypeParameter Name="TResult" />
241
      </TypeParameters>
242
      <Parameters>
243
        <Parameter Name="self" Type="TSource" RefType="this" />
244
        <Parameter Name="valueSelector" Type="System.Func&lt;TSource,TResult&gt;" />
245
        <Parameter Name="childrenSelector" Type="System.Func&lt;TSource,System.Collections.Generic.IEnumerable&lt;TSource&gt;&gt;" />
246
      </Parameters>
247
      <Docs>
248
        <typeparam name="TSource">
249
          The type of the root node and intermediate nodes of the tree.
250
        </typeparam>
251
        <typeparam name="TResult">
252
          The type of the object to return.
253
        </typeparam>
254
        <param name="self">
255
          The root of a tree to traverse.
256
        </param>
257
        <param name="valueSelector">
258
          A <see cref="T:System.Func{TSource,TResult}" /> which is used to 
259
          convert tree nodes into <typeparamref name="TResult" /> instances.
260
        </param>
261
        <param name="childrenSelector">
262
          A <see cref="T:System.Func{TSource,System.Collections.Generic.IEnumerable{TSource}}" />
263
          which returns the child nodes of <paramref name="root" />
264
          and all intermediate non-leaf nodes.
265
        </param>
266
        <summary>
267
          Traverse a tree in a breadth-first fashion, converting each 
268
          encountered node.
269
        </summary>
270
        <returns>
271
          A <see cref="T:System.Collections.Generic.IEnumerable{TResult}" />
272
          containing the result of applying <paramref name="valueSelector" />
273
          to all nodes encountered while traversing the tree 
274
          <paramref name="self" /> in a breadth-first fashion.
275
        </returns>
276
        <remarks>
277
          <para>
278
            <paramref name="self" /> is the root node of a tree, wherein each 
279
            node is a data structure containing a value and child nodes.
280
            The value is retrieved via <paramref name="valueSelector" />,
281
            and the children are obtained via 
282
            <paramref name="childrenSelector" />.
283
          </para>
284
          <para>
285
            The tree is traversed in a breadth-first fashion, each encountered
286
            node is provided to <paramref name="valueSelector" />, and the
287
            values are returned.
288
          </para>
289
        </remarks>
290
        <example>
291
          <para>
292
            Given the <c>TreeNode&lt;T&gt;</c> declaration:
293
          </para>
294
          <code lang="C#" src="../../Test/Cadenza/ObjectCodaTest.cs#TreeNode_Declaration">class TreeNode&lt;T&gt;
295
{
296
	public TreeNode ()
297
	{
298
		Children = new TreeNode&lt;T&gt; [0];
299
	}
300
301
	public T Value;
302
	public IEnumerable&lt;TreeNode&lt;T&gt;&gt; Children;
303
}
304
</code>
305
          <para>
306
            <c>TraverseBreadthFirst()</c> is used as:
307
          </para>
308
          <code lang="C#" src="../../Test/Cadenza/ObjectCodaTest.cs#TraverseBreadthFirst">TreeNode&lt;int&gt; root = new TreeNode&lt;int&gt; {
309
	Value = 1, Children = new [] {
310
		new TreeNode&lt;int&gt; { Value = 2 },
311
		new TreeNode&lt;int&gt; {
312
			Value = 3, Children = new [] {
313
				new TreeNode&lt;int&gt; { Value = 5 },
314
			}
315
		},
316
		new TreeNode&lt;int&gt; { Value = 4 },
317
	}
318
};
319
IEnumerable&lt;int&gt; values = root
320
	.TraverseBreadthFirst (x =&gt; x.Value, x =&gt; x.Children);
321
AssertAreSame (new[]{ 1, 2, 3, 4, 5 }, values);
322
</code>
323
        </example>
324
        <exception cref="T:System.ArgumentNullException">
325
          <para>
326
            <paramref name="self" /> is <see langword="null" />.
327
          </para>
328
          <para>-or-</para>
329
          <para>
330
            <paramref name="childrenSelector" /> is <see langword="null" />.
331
          </para>
332
          <para>-or-</para>
333
          <para>
334
            <paramref name="valueSelector" /> is <see langword="null" />.
335
          </para>
336
        </exception>
337
      </Docs>
338
    </Member>
339
    <Member MemberName="TraverseBreadthFirstWithParent&lt;TSource,TResult&gt;">
340
      <MemberSignature Language="C#" Value="public static System.Collections.Generic.IEnumerable&lt;System.Collections.Generic.KeyValuePair&lt;TSource,TResult&gt;&gt; TraverseBreadthFirstWithParent&lt;TSource,TResult&gt; (this TSource self, Func&lt;TSource,TResult&gt; valueSelector, Func&lt;TSource,System.Collections.Generic.IEnumerable&lt;TSource&gt;&gt; childrenSelector);" />
341
      <MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Collections.Generic.IEnumerable`1&lt;valuetype System.Collections.Generic.KeyValuePair`2&lt;!!TSource, !!TResult&gt;&gt; TraverseBreadthFirstWithParent&lt;TSource, TResult&gt;(!!TSource self, class System.Func`2&lt;!!TSource, !!TResult&gt; valueSelector, class System.Func`2&lt;!!TSource, class System.Collections.Generic.IEnumerable`1&lt;!!TSource&gt;&gt; childrenSelector) cil managed" />
342
      <MemberType>Method</MemberType>
343
      <AssemblyInfo>
344
        <AssemblyVersion>0.1.0.0</AssemblyVersion>
345
      </AssemblyInfo>
346
      <ReturnValue>
347
        <ReturnType>System.Collections.Generic.IEnumerable&lt;System.Collections.Generic.KeyValuePair&lt;TSource,TResult&gt;&gt;</ReturnType>
348
      </ReturnValue>
349
      <TypeParameters>
350
        <TypeParameter Name="TSource" />
351
        <TypeParameter Name="TResult" />
352
      </TypeParameters>
353
      <Parameters>
354
        <Parameter Name="self" Type="TSource" RefType="this" />
355
        <Parameter Name="valueSelector" Type="System.Func&lt;TSource,TResult&gt;" />
356
        <Parameter Name="childrenSelector" Type="System.Func&lt;TSource,System.Collections.Generic.IEnumerable&lt;TSource&gt;&gt;" />
357
      </Parameters>
358
      <Docs>
359
        <typeparam name="TSource">
360
          The type of the root node and intermediate nodes of the tree.
361
        </typeparam>
362
        <typeparam name="TResult">
363
          The type of the object to return.
364
        </typeparam>
365
        <param name="self">
366
          The root of a tree to traverse.
367
        </param>
368
        <param name="valueSelector">
369
          A <see cref="T:System.Func{TSource,TResult}" /> which is used to 
370
          convert tree nodes into <typeparamref name="TResult" /> instances.
371
        </param>
372
        <param name="childrenSelector">
373
          A <see cref="T:System.Func{TSource,System.Collections.Generic.IEnumerable{TSource}}" />
374
          which returns the child nodes of <paramref name="root" />
375
          and all intermediate non-leaf nodes.
376
        </param>
377
        <summary>
378
          Traverse a tree in a breadth-first fashion, converting each 
379
          encountered node.
380
        </summary>
381
        <returns>
382
          <para>
383
            A <see cref="T:System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{TSource,TResult}}" />
384
            in which each returned
385
            <see cref="P:System.Collections.Generic.KeyValuePair{TSource,TResult}.Value" />
386
            is the result of applying <paramref name="valueSelector" /> to a
387
            node, and
388
            <see cref="P:System.Collections.Generic.KeyValuePair{TSource,TResult}.Key" />
389
            holds the parent of that node.  If the node has no parent (e.g. for
390
            <paramref name="self" />), then 
391
            <see cref="P:System.Collections.Generic.KeyValuePair{TSource,TResult}.Key" />
392
            will contain <c>default(TSource)</c>.
393
          </para>
394
          <para>
395
            Returned 
396
            <see cref="T:System.Collections.Generic.KeyValuePair{TSource,TResult}" />
397
            values come from traversing <paramref name="self" /> in a
398
            breadth-first order.
399
          </para>
400
        </returns>
401
        <remarks>
402
          <para>
403
            <paramref name="self" /> is the root node of a tree, wherein each 
404
            node is a data structure containing a value and child nodes.
405
            The value is retrieved via <paramref name="valueSelector" />,
406
            and the children are obtained via 
407
            <paramref name="childrenSelector" />.
408
          </para>
409
          <para>
410
            The tree is traversed in a breadth-first fashion, each encountered
411
            node is provided to <paramref name="valueSelector" />, and the
412
            values are returned.
413
          </para>
414
        </remarks>
415
        <exception cref="T:System.ArgumentNullException">
416
          <para>
417
            <paramref name="self" /> is <see langword="null" />.
418
          </para>
419
          <para>-or-</para>
420
          <para>
421
            <paramref name="childrenSelector" /> is <see langword="null" />.
422
          </para>
423
          <para>-or-</para>
424
          <para>
425
            <paramref name="valueSelector" /> is <see langword="null" />.
426
          </para>
427
        </exception>
428
      </Docs>
429
    </Member>
430
    <Member MemberName="TraverseDepthFirst&lt;TSource,TResult&gt;">
431
      <MemberSignature Language="C#" Value="public static System.Collections.Generic.IEnumerable&lt;TResult&gt; TraverseDepthFirst&lt;TSource,TResult&gt; (this TSource self, Func&lt;TSource,TResult&gt; valueSelector, Func&lt;TSource,System.Collections.Generic.IEnumerable&lt;TSource&gt;&gt; childrenSelector);" />
432
      <MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Collections.Generic.IEnumerable`1&lt;!!TResult&gt; TraverseDepthFirst&lt;TSource, TResult&gt;(!!TSource self, class System.Func`2&lt;!!TSource, !!TResult&gt; valueSelector, class System.Func`2&lt;!!TSource, class System.Collections.Generic.IEnumerable`1&lt;!!TSource&gt;&gt; childrenSelector) cil managed" />
433
      <MemberType>Method</MemberType>
434
      <AssemblyInfo>
435
        <AssemblyVersion>0.1.0.0</AssemblyVersion>
436
      </AssemblyInfo>
437
      <ReturnValue>
438
        <ReturnType>System.Collections.Generic.IEnumerable&lt;TResult&gt;</ReturnType>
439
      </ReturnValue>
440
      <TypeParameters>
441
        <TypeParameter Name="TSource" />
442
        <TypeParameter Name="TResult" />
443
      </TypeParameters>
444
      <Parameters>
445
        <Parameter Name="self" Type="TSource" RefType="this" />
446
        <Parameter Name="valueSelector" Type="System.Func&lt;TSource,TResult&gt;" />
447
        <Parameter Name="childrenSelector" Type="System.Func&lt;TSource,System.Collections.Generic.IEnumerable&lt;TSource&gt;&gt;" />
448
      </Parameters>
449
      <Docs>
450
        <typeparam name="TSource">
451
          The type of the root node and intermediate nodes of the tree.
452
        </typeparam>
453
        <typeparam name="TResult">
454
          The type of the object to return.
455
        </typeparam>
456
        <param name="self">
457
          The root of a tree to traverse.
458
        </param>
459
        <param name="valueSelector">
460
          A <see cref="T:System.Func{TSource,TResult}" /> which is used to 
461
          convert tree nodes into <typeparamref name="TResult" /> instances.
462
        </param>
463
        <param name="childrenSelector">
464
          A <see cref="T:System.Func{TSource,System.Collections.Generic.IEnumerable{TSource}}" />
465
          which returns the child nodes of <paramref name="root" />
466
          and all intermediate non-leaf nodes.
467
        </param>
468
        <summary>
469
          Traverse a tree in a depth-first fashion, converting each 
470
          encountered node.
471
        </summary>
472
        <returns>
473
          A <see cref="T:System.Collections.Generic.IEnumerable{TResult}" />
474
          containing the result of applying <paramref name="valueSelector" />
475
          to all nodes encountered while traversing the tree 
476
          <paramref name="self" /> in a depth-first fashion.
477
        </returns>
478
        <remarks>
479
          <para>
480
            <paramref name="self" /> is the root node of a tree, wherein each 
481
            node is a data structure containing a value and child nodes.
482
            The value is retrieved via <paramref name="valueSelector" />,
483
            and the children are obtained via 
484
            <paramref name="childrenSelector" />.
485
          </para>
486
          <para>
487
            The tree is traversed in a depth-first fashion, each encountered
488
            node is provided to <paramref name="valueSelector" />, and the
489
            values are returned.
490
          </para>
491
        </remarks>
492
        <example>
493
          <para>
494
            Given the <c>TreeNode&lt;T&gt;</c> declaration:
495
          </para>
496
          <code lang="C#" src="../../Test/Cadenza/ObjectCodaTest.cs#TreeNode_Declaration">class TreeNode&lt;T&gt;
497
{
498
	public TreeNode ()
499
	{
500
		Children = new TreeNode&lt;T&gt; [0];
501
	}
502
503
	public T Value;
504
	public IEnumerable&lt;TreeNode&lt;T&gt;&gt; Children;
505
}
506
</code>
507
          <para>
508
            <c>TraverseDepthFirst()</c> is used as:
509
          </para>
510
          <code lang="C#" src="../../Test/Cadenza/ObjectCodaTest.cs#TraverseDepthFirst">TreeNode&lt;int&gt; root = new TreeNode&lt;int&gt; {
511
	Value = 1, Children = new [] {
512
		new TreeNode&lt;int&gt; { Value = 2 },
513
		new TreeNode&lt;int&gt; {
514
			Value = 3, Children = new [] {
515
				new TreeNode&lt;int&gt; { Value = 5 },
516
			}
517
		},
518
		new TreeNode&lt;int&gt; { Value = 4 },
519
	}
520
};
521
IEnumerable&lt;int&gt; values = root
522
	.TraverseDepthFirst (x =&gt; x.Value, x =&gt; x.Children);
523
AssertAreSame (new[]{ 1, 2, 3, 5, 4 }, values);
524
</code>
525
        </example>
526
        <exception cref="T:System.ArgumentNullException">
527
          <para>
528
            <paramref name="self" /> is <see langword="null" />.
529
          </para>
530
          <para>-or-</para>
531
          <para>
532
            <paramref name="childrenSelector" /> is <see langword="null" />.
533
          </para>
534
          <para>-or-</para>
535
          <para>
536
            <paramref name="valueSelector" /> is <see langword="null" />.
537
          </para>
538
        </exception>
539
      </Docs>
540
    </Member>
541
    <Member MemberName="TraverseDepthFirstWithParent&lt;TSource,TResult&gt;">
542
      <MemberSignature Language="C#" Value="public static System.Collections.Generic.IEnumerable&lt;System.Collections.Generic.KeyValuePair&lt;TSource,TResult&gt;&gt; TraverseDepthFirstWithParent&lt;TSource,TResult&gt; (this TSource self, Func&lt;TSource,TResult&gt; valueSelector, Func&lt;TSource,System.Collections.Generic.IEnumerable&lt;TSource&gt;&gt; childrenSelector);" />
543
      <MemberSignature Language="ILAsm" Value=".method public static hidebysig class System.Collections.Generic.IEnumerable`1&lt;valuetype System.Collections.Generic.KeyValuePair`2&lt;!!TSource, !!TResult&gt;&gt; TraverseDepthFirstWithParent&lt;TSource, TResult&gt;(!!TSource self, class System.Func`2&lt;!!TSource, !!TResult&gt; valueSelector, class System.Func`2&lt;!!TSource, class System.Collections.Generic.IEnumerable`1&lt;!!TSource&gt;&gt; childrenSelector) cil managed" />
544
      <MemberType>Method</MemberType>
545
      <AssemblyInfo>
546
        <AssemblyVersion>0.1.0.0</AssemblyVersion>
547
      </AssemblyInfo>
548
      <ReturnValue>
549
        <ReturnType>System.Collections.Generic.IEnumerable&lt;System.Collections.Generic.KeyValuePair&lt;TSource,TResult&gt;&gt;</ReturnType>
550
      </ReturnValue>
551
      <TypeParameters>
552
        <TypeParameter Name="TSource" />
553
        <TypeParameter Name="TResult" />
554
      </TypeParameters>
555
      <Parameters>
556
        <Parameter Name="self" Type="TSource" RefType="this" />
557
        <Parameter Name="valueSelector" Type="System.Func&lt;TSource,TResult&gt;" />
558
        <Parameter Name="childrenSelector" Type="System.Func&lt;TSource,System.Collections.Generic.IEnumerable&lt;TSource&gt;&gt;" />
559
      </Parameters>
560
      <Docs>
561
        <typeparam name="TSource">
562
          The type of the root node and intermediate nodes of the tree.
563
        </typeparam>
564
        <typeparam name="TResult">
565
          The type of the object to return.
566
        </typeparam>
567
        <param name="self">
568
          The root of a tree to traverse.
569
        </param>
570
        <param name="valueSelector">
571
          A <see cref="T:System.Func{TSource,TResult}" /> which is used to 
572
          convert tree nodes into <typeparamref name="TResult" /> instances.
573
        </param>
574
        <param name="childrenSelector">
575
          A <see cref="T:System.Func{TSource,System.Collections.Generic.IEnumerable{TSource}}" />
576
          which returns the child nodes of <paramref name="root" />
577
          and all intermediate non-leaf nodes.
578
        </param>
579
        <summary>
580
          Traverse a tree in a depth-first fashion, converting each 
581
          encountered node.
582
        </summary>
583
        <returns>
584
          <para>
585
            A <see cref="T:System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{TSource,TResult}}" />
586
            in which each returned
587
            <see cref="P:System.Collections.Generic.KeyValuePair{TSource,TResult}.Value" />
588
            is the result of applying <paramref name="valueSelector" /> to a
589
            node, and
590
            <see cref="P:System.Collections.Generic.KeyValuePair{TSource,TResult}.Key" />
591
            holds the parent of that node.  If the node has no parent (e.g. for
592
            <paramref name="self" />), then 
593
            <see cref="P:System.Collections.Generic.KeyValuePair{TSource,TResult}.Key" />
594
            will contain <c>default(TSource)</c>.
595
          </para>
596
          <para>
597
            Returned 
598
            <see cref="T:System.Collections.Generic.KeyValuePair{TSource,TResult}" />
599
            values come from traversing <paramref name="self" /> in a
600
            breadth-first order.
601
          </para>
602
        </returns>
603
        <remarks>
604
          <para>
605
            <paramref name="self" /> is the root node of a tree, wherein each 
606
            node is a data structure containing a value and child nodes.
607
            The value is retrieved via <paramref name="valueSelector" />,
608
            and the children are obtained via 
609
            <paramref name="childrenSelector" />.
610
          </para>
611
          <para>
612
            The tree is traversed in a depth-first fashion, each encountered
613
            node is provided to <paramref name="valueSelector" />, and the
614
            values are returned.
615
          </para>
616
        </remarks>
617
        <exception cref="T:System.ArgumentNullException">
618
          <para>
619
            <paramref name="self" /> is <see langword="null" />.
620
          </para>
621
          <para>-or-</para>
622
          <para>
623
            <paramref name="childrenSelector" /> is <see langword="null" />.
624
          </para>
625
          <para>-or-</para>
626
          <para>
627
            <paramref name="valueSelector" /> is <see langword="null" />.
628
          </para>
629
        </exception>
630
      </Docs>
631
    </Member>
632
    <Member MemberName="With&lt;TSource,TResult&gt;">
633
      <MemberSignature Language="C#" Value="public static TResult With&lt;TSource,TResult&gt; (this TSource self, Func&lt;TSource,TResult&gt; selector);" />
634
      <MemberSignature Language="ILAsm" Value=".method public static hidebysig !!TResult With&lt;TSource, TResult&gt;(!!TSource self, class System.Func`2&lt;!!TSource, !!TResult&gt; selector) cil managed" />
635
      <MemberType>Method</MemberType>
636
      <AssemblyInfo>
637
        <AssemblyVersion>0.1.0.0</AssemblyVersion>
638
      </AssemblyInfo>
639
      <ReturnValue>
640
        <ReturnType>TResult</ReturnType>
641
      </ReturnValue>
642
      <TypeParameters>
643
        <TypeParameter Name="TSource" />
644
        <TypeParameter Name="TResult" />
645
      </TypeParameters>
646
      <Parameters>
647
        <Parameter Name="self" Type="TSource" RefType="this" />
648
        <Parameter Name="selector" Type="System.Func&lt;TSource,TResult&gt;" />
649
      </Parameters>
650
      <Docs>
651
        <typeparam name="TSource">The type to operate on.</typeparam>
652
        <typeparam name="TResult">The type to return.</typeparam>
653
        <param name="self">
654
          A <typeparamref name="TSource" /> containing the value to manipulate.
655
          This value may be <see langword="null" /> (unlike most other
656
          extension methods).
657
        </param>
658
        <param name="selector">
659
          A <see cref="T:System.Func{TSource,TResult}" /> which will be
660
          invoked with <paramref name="self" /> as a parameter.
661
        </param>
662
        <summary>
663
          Supports chaining otherwise temporary values.
664
        </summary>
665
        <returns>
666
          The value of type <typeparamref name="TResult" /> returned by
667
          <paramref name="selector" />.
668
        </returns>
669
        <remarks>
670
          <para>
671
            <c>With</c> is useful for easily using an intermediate value within
672
            an expression "chain" without requiring an explicit variable
673
            declaration (which is useful for reducing in-scope variables, as no
674
            variable is explicitly declared).
675
          </para>
676
          <code lang="C#" src="../../Test/Cadenza/ObjectCodaTest.cs#With">// sorts the array, then returns the 
677
// element in the middle of the array.
678
Assert.AreEqual (3,
679
	new[]{5, 4, 3, 2, 1}.Sort ()
680
	.With (c =&gt; c.ElementAt (c.Count()/2)));
681
</code>
682
        </remarks>
683
        <exception cref="T:System.ArgumentNullException">
684
          <paramref name="selector" /> is <see langword="null" />.
685
        </exception>
686
      </Docs>
687
    </Member>
688
  </Members>
689
</Type>