This repository was archived by the owner on Apr 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 451
Expand file tree
/
Copy pathFormatter.cs
More file actions
722 lines (603 loc) · 25.5 KB
/
Formatter.cs
File metadata and controls
722 lines (603 loc) · 25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.DotNet.Interactive.Formatting.Csv;
using Microsoft.DotNet.Interactive.Formatting.TabularData;
namespace Microsoft.DotNet.Interactive.Formatting;
public static partial class Formatter
{
private static int _defaultListExpansionLimit;
private static int _recursionLimit;
private static string _defaultMimeType;
// user specification
private static readonly ConcurrentStack<(Type type, HashSet<string> mimeTypes)> _preferredMimeTypes = new();
private static readonly ConcurrentStack<(Type type, string mimeType)> _defaultPreferredMimeTypes = new();
internal static readonly ConcurrentStack<ITypeFormatter> _userTypeFormatters = new();
internal static readonly ConcurrentStack<ITypeFormatter> _defaultTypeFormatters = new();
internal static readonly ConcurrentDictionary<Type, bool> _typesThatHaveBeenCheckedForFormatters = new();
// computed state
private static readonly ConcurrentDictionary<Type, HashSet<string>> _preferredMimeTypesTable = new();
private static readonly ConcurrentDictionary<(Type type, string mimeType), ITypeFormatter> _typeFormattersTable = new();
private static readonly ConcurrentDictionary<Type, Action<FormatContext, object, string>> _genericFormattersTable = new();
/// <summary>
/// Initializes the <see cref="Formatter"/> class.
/// </summary>
static Formatter()
{
ResetToDefault();
}
internal static TextWriter CreateWriter() => new StringWriter(CultureInfo.InvariantCulture);
/// <summary>
/// Gets or sets the limit to the number of items that will be written out in detail from an IEnumerable sequence.
/// </summary>
/// <value>
/// The list expansion limit.
/// </value>
public static int ListExpansionLimit
{
get => _defaultListExpansionLimit;
set
{
if (value < 0)
{
throw new ArgumentException($"{nameof(ListExpansionLimit)} must be at least 0.");
}
_defaultListExpansionLimit = value;
}
}
/// <summary>
/// Gets or sets the string that will be written out for null items.
/// </summary>
/// <value>
/// The null string.
/// </value>
public static string NullString { get; set; }
/// <summary>
/// Gets or sets the limit to how many levels the formatter will recurse into an object graph.
/// </summary>
/// <value>
/// The recursion limit.
/// </value>
public static int RecursionLimit
{
get => _recursionLimit;
set
{
if (value < 0)
{
throw new ArgumentException($"{nameof(RecursionLimit)} must be at least 0.");
}
_recursionLimit = value;
}
}
internal static event Action Clearing;
/// <summary>
/// Resets all formatters and formatter settings to their default values.
/// </summary>
public static void ResetToDefault()
{
DefaultMimeType = HtmlFormatter.MimeType;
ClearComputedState();
_typesThatHaveBeenCheckedForFormatters.Clear();
_userTypeFormatters.Clear();
_preferredMimeTypes.Clear();
_defaultTypeFormatters.Clear();
_defaultPreferredMimeTypes.Clear();
// In the lists of default formatters, the highest priority ones come first,
// so register those last.
_defaultTypeFormatters.PushRange(((IEnumerable<ITypeFormatter>)TabularDataResourceFormatter.DefaultFormatters).Reverse().ToArray());
_defaultTypeFormatters.PushRange(((IEnumerable<ITypeFormatter>)CsvFormatter.DefaultFormatters).Reverse().ToArray());
_defaultTypeFormatters.PushRange(((IEnumerable<ITypeFormatter>)HtmlFormatter.DefaultFormatters).Reverse().ToArray());
_defaultTypeFormatters.PushRange(((IEnumerable<ITypeFormatter>)JsonFormatter.DefaultFormatters).Reverse().ToArray());
_defaultTypeFormatters.PushRange(((IEnumerable<ITypeFormatter>)PlainTextSummaryFormatter.DefaultFormatters).Reverse().ToArray());
_defaultTypeFormatters.PushRange(((IEnumerable<ITypeFormatter>)PlainTextFormatter.DefaultFormatters).Reverse().ToArray());
_defaultTypeFormatters.PushRange(((IEnumerable<ITypeFormatter>)BinaryFormatter.DefaultFormatters).Reverse().ToArray());
_defaultPreferredMimeTypes.Push((typeof(string), PlainTextFormatter.MimeType));
ListExpansionLimit = 20;
RecursionLimit = 6;
NullString = "<null>";
Clearing?.Invoke();
}
internal static void ClearComputedState()
{
_typeFormattersTable.Clear();
_genericFormattersTable.Clear();
_preferredMimeTypesTable.Clear();
}
public static void SetPreferredMimeTypesFor(Type type, params string[] preferredMimeTypes)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (preferredMimeTypes is null
|| preferredMimeTypes.Count( mimeType => !string.IsNullOrWhiteSpace(mimeType)) ==0)
{
throw new ArgumentException("Value cannot be null or whitespace.", nameof(preferredMimeTypes));
}
ClearComputedState();
_preferredMimeTypes.Push((type, new HashSet<string>(preferredMimeTypes)));
}
public static string DefaultMimeType
{
get => _defaultMimeType;
set => _defaultMimeType = value ??
throw new ArgumentNullException(nameof(value));
}
public static IReadOnlyCollection<string> GetPreferredMimeTypesFor(Type type) =>
_preferredMimeTypesTable.GetOrAdd(type ?? typeof(object), FindPreferredMimeTypes);
private class SortByRelevanceAndOrder<T> : IComparer<T>
{
private readonly Func<T, Type> _typeKey;
private readonly Func<T, int> _indexKey;
public SortByRelevanceAndOrder(Func<T, Type> typeKey, Func<T, int> indexKey)
{
_typeKey = typeKey;
_indexKey = indexKey;
}
public int Compare(T inp1, T inp2)
{
var type1 = _typeKey(inp1);
var type2 = _typeKey(inp2);
var isType1RelevantForType2 = type1.IsRelevantFormatterFor(type2);
if (isType1RelevantForType2 && type2.IsRelevantFormatterFor(type1))
{
var index1 = _indexKey(inp1);
var index2 = _indexKey(inp2);
return Comparer<int>.Default.Compare(index1, index2);
}
else if (isType1RelevantForType2)
{
return 1;
}
else
{
return -1;
}
}
}
private static string TryFindPreferredMimeType(Type type, IEnumerable<(Type type, string mimeType)> mimeTypes)
{
// Find the most specific type that specifies a mimeType
var candidates =
mimeTypes
.Where(mimeSpec => mimeSpec.type.IsRelevantFormatterFor(type))
.Select((x, index) => (x.type, x.mimeType, index))
.ToArray();
switch (candidates.Length)
{
case 0:
return null;
case 1:
return candidates[0].mimeType;
default:
Array.Sort(candidates, new SortByRelevanceAndOrder<(Type type, string mimeType, int index)>(tup => tup.type, tup => tup.index));
return candidates[0].mimeType;
}
}
private static HashSet<string> TryFindPreferredMimeTypes(Type type, IEnumerable<(Type type, HashSet<string> mimeTypes)> mimeTypes)
{
// Find the most specific type that specifies a mimeType
var candidates =
mimeTypes
.Where(mimeSpec => mimeSpec.type.IsRelevantFormatterFor(type))
.Select((x, index) => (x.type, x.mimeTypes, index))
.ToArray();
switch (candidates.Length)
{
case 0:
return null;
case 1:
return candidates[0].mimeTypes;
default:
Array.Sort(candidates, new SortByRelevanceAndOrder<(Type type, HashSet<string> mimeTypes, int index)>(tup => tup.type, tup => tup.index));
return candidates[0].mimeTypes;
}
}
private static HashSet<string> FindPreferredMimeTypes(Type type)
{
TryRegisterFromFormatterSources(type);
var preferredMimeTypes = TryFindPreferredMimeTypes(type, _preferredMimeTypes);
if (preferredMimeTypes is not null)
{
return preferredMimeTypes;
}
return new HashSet<string>
{
TryFindPreferredMimeType(type, _defaultPreferredMimeTypes) ??
_defaultMimeType
};
}
public static string ToDisplayString(
this object obj,
string mimeType = PlainTextFormatter.MimeType)
{
if (mimeType is null)
{
throw new ArgumentNullException(nameof(mimeType));
}
using var writer = CreateWriter();
using (var context = new FormatContext(writer))
{
FormatTo(obj, context, mimeType);
}
return writer.ToString();
}
public static string ToDisplayString(
this object obj,
ITypeFormatter formatter)
{
if (formatter is null)
{
throw new ArgumentNullException(nameof(formatter));
}
using var writer = CreateWriter();
using (var context = new FormatContext(writer))
{
formatter.Format(obj, context);
}
return writer.ToString();
}
public static void Format(this ITypeFormatter formatter, object instance, TextWriter writer)
{
using var context = new FormatContext(writer);
formatter.Format(instance, context);
}
/// <summary>Invoke the formatter</summary>
public static void FormatTo<T>(
this T obj,
FormatContext context,
string mimeType)
{
if (obj is not null)
{
var actualType = obj.GetType();
if (typeof(T) != actualType)
{
// in some cases the generic parameter is Object but the object is of a more specific type, in which case get or add a cached accessor to the more specific Formatter<T>.Format method
var genericFormatter = _genericFormattersTable.GetOrAdd(actualType, GetGenericFormatterMethod);
genericFormatter(context, obj, mimeType);
return;
}
}
Formatter<T>.FormatTo(obj, context, mimeType);
}
internal static Action<FormatContext, object, string> GetGenericFormatterMethod(this Type type)
{
var methodInfo = typeof(Formatter<>)
.MakeGenericType(type)
.GetMethod(nameof(Formatter<object>.FormatTo), new[]
{
type,
typeof(FormatContext),
typeof(string)
});
var targetParam = Expression.Parameter(typeof(object), "target");
var contextParam = Expression.Parameter(typeof(FormatContext), "context");
var mimeTypeParam = Expression.Parameter(typeof(string), "mimeType");
var methodCallExpr = Expression.Call(null,
methodInfo,
Expression.Convert(targetParam, type),
contextParam,
mimeTypeParam);
return Expression.Lambda<Action<FormatContext, object, string>>(
methodCallExpr,
contextParam,
targetParam,
mimeTypeParam).Compile();
}
/// <summary>
/// Registers a formatter to be used when formatting.
/// </summary>
public static void Register(ITypeFormatter formatter)
{
if (formatter is null)
{
throw new ArgumentNullException(nameof(formatter));
}
ClearComputedState();
_userTypeFormatters.Push(formatter);
}
/// <summary>
/// Registers a formatter to be used when formatting instances of type <typeparamref name="T" />.
/// </summary>
/// <param name="formatter">The formatter.</param>
/// <param name="mimeType">The MimeType for this formatter. If it is not specified it defaults to <see cref="PlainTextFormatter.MimeType"/></param>
public static void Register<T>(
FormatDelegate<T> formatter,
string mimeType = PlainTextFormatter.MimeType)
{
Register(new AnonymousTypeFormatter<T>(formatter, mimeType));
}
/// <summary>
/// Registers a formatter to be used when formatting instances of type <paramref name="type" />.
/// </summary>
/// <param name="formatter">The formatter.</param>
/// <param name="type">The type the formatter is registered for.</param>
/// <param name="mimeType">The MimeType for this formatter. If it is not specified it defaults to <see cref="PlainTextFormatter.MimeType"/></param>
public static void Register(
Type type,
FormatDelegate<object> formatter,
string mimeType = PlainTextFormatter.MimeType)
{
Register(new AnonymousTypeFormatter<object>(formatter, mimeType, type));
}
/// <summary>
/// Registers a formatter to be used when formatting instances of type <paramref name="type" />.
/// </summary>
/// <param name="formatter">The formatting action.</param>
/// <param name="type">The type the formatter is registered for.</param>
/// <param name="mimeType">The MimeType for this formatter. If it is not specified it defaults to <see cref="PlainTextFormatter.MimeType"/></param>
public static void Register(
Type type,
Action<object, TextWriter> formatter,
string mimeType = PlainTextFormatter.MimeType)
{
Register(new AnonymousTypeFormatter<object>((value, context) =>
{
formatter(value, context.Writer);
return true;
}, mimeType, type));
}
/// <summary>
/// Registers a formatter to be used when formatting instances of type <typeparamref name="T" />.
/// </summary>
/// <param name="formatter">The formatting action.</param>
/// <param name="mimeType">The MimeType for this formatter. If it is not specified it defaults to <see cref="PlainTextFormatter.MimeType"/></param>
public static void Register<T>(
Action<T, TextWriter> formatter,
string mimeType = PlainTextFormatter.MimeType)
{
Register(new AnonymousTypeFormatter<object>((value, context) =>
{
formatter((T)value, context.Writer);
return true;
}, mimeType, typeof(T)));
}
/// <summary>
/// Registers a formatter to be used when formatting instances of type <typeparamref name="T" />.
/// </summary>
/// <param name="formatter">The formatter.</param>
/// <param name="mimeType">The MimeType for this formatter. If it is not specified it defaults to <see cref="PlainTextFormatter.MimeType"/></param>
public static void Register<T>(
Func<T, string> formatter,
string mimeType = PlainTextFormatter.MimeType)
{
Register(new AnonymousTypeFormatter<T>((value, context) =>
{
context.Writer.Write(formatter(value));
return true;
}, mimeType));
}
public static IEnumerable<ITypeFormatter> RegisteredFormatters(bool includeDefaults = true)
{
foreach (var formatter in _userTypeFormatters)
{
yield return formatter;
}
if (includeDefaults)
{
foreach (var formatter in _defaultTypeFormatters)
{
yield return formatter;
}
}
}
public static ITypeFormatter GetPreferredFormatterFor(Type actualType, string mimeType)
{
if (mimeType == null)
{
throw new ArgumentNullException(nameof(mimeType));
}
return _typeFormattersTable
.GetOrAdd(
(actualType, mimeType),
tuple => FindPreferredFormatter(tuple.type, tuple.mimeType));
}
private static ITypeFormatter FindPreferredFormatter(Type actualType, string mimeType)
{
// Try to find a user-specified type formatter, use the most specific type with a matching mime type
if (TryFindPreferredFormatter(actualType, mimeType, _userTypeFormatters) is { } userFormatter)
{
return userFormatter;
}
TryRegisterFromFormatterSources(actualType);
// Try to find a default built-in type formatter, use the most specific type with a matching mime type
if (TryFindPreferredFormatter(actualType, mimeType, _defaultTypeFormatters) is { } defaultFormatter)
{
return defaultFormatter;
}
// Last resort use preferred mimeType
var preferredMimeType = GetPreferredMimeTypesFor(actualType).FirstOrDefault(m => m == mimeType);
if (preferredMimeType != mimeType)
{
throw new ArgumentException($"No formatter is registered for MIME type {mimeType}.");
}
return GetPreferredFormatterFor(actualType, preferredMimeType);
}
private static void TryRegisterFromFormatterSources(Type type)
{
if (_typesThatHaveBeenCheckedForFormatters.ContainsKey(type))
{
return;
}
var foundFormatter = false;
var customAttributes = type.GetCustomAttributes<TypeFormatterSourceAttribute>().ToArray();
if (customAttributes.Length > 0)
{
foundFormatter = TryRegisterFromWellKnownFormatterSources(customAttributes);
}
else
{
foundFormatter = TryRegisterFromConventionBasedFormatterSources();
}
_typesThatHaveBeenCheckedForFormatters.TryAdd(type, foundFormatter);
bool TryRegisterFromWellKnownFormatterSources(TypeFormatterSourceAttribute[] customAttributes)
{
bool foundFormatter = false;
foreach (var formatterSourceAttribute in customAttributes)
{
if (Activator.CreateInstance(formatterSourceAttribute.FormatterSourceType) is not ITypeFormatterSource source)
{
throw new InvalidOperationException($"The formatter source specified on '{type}' does not implement {nameof(ITypeFormatterSource)}");
}
var formatters = source.CreateTypeFormatters();
foreach (var formatter in formatters)
{
_defaultTypeFormatters.Push(formatter);
foundFormatter = true;
}
if (formatterSourceAttribute.PreferredMimeTypes is not null)
{
SetPreferredMimeTypesFor(type, formatterSourceAttribute.PreferredMimeTypes);
}
}
return foundFormatter;
}
bool TryRegisterFromConventionBasedFormatterSources()
{
bool foundFormatter = false;
var attributesByConvention = type.GetCustomAttributes(true).Where(a => a.GetType().Name == nameof(TypeFormatterSourceAttribute));
foreach (var attr in attributesByConvention)
{
if (TryGetPropertyValue<object>(attr, nameof(TypeFormatterSourceAttribute.FormatterSourceType), out var prop) &&
prop is Type formatterSourceType)
{
var formatterSource = Activator.CreateInstance(formatterSourceType);
if (formatterSource.GetType()
.GetMethod(nameof(ITypeFormatterSource.CreateTypeFormatters))
.Invoke(formatterSource, null) is IEnumerable formatters)
{
foreach (var formatterByConvention in formatters)
{
if (TryGetPropertyValue<string>(formatterByConvention, nameof(ITypeFormatter.MimeType), out var mimeTyp))
{
MethodInfo formatMethod = formatterByConvention.GetType().GetMethod(nameof(ITypeFormatter.Format));
var formatterExpr = Expression.Constant(formatterByConvention);
var valueToFormatExpr = Expression.Parameter(typeof(object));
var writerExpr = Expression.Parameter(typeof(TextWriter));
var methodCallExpression = Expression.Call(
formatterExpr,
formatMethod,
new[]
{
valueToFormatExpr,
writerExpr
});
var formatExpr = Expression.Lambda<Func<object, TextWriter, bool>>(
methodCallExpression,
valueToFormatExpr,
writerExpr)
.Compile();
if (!TryGetPropertyValue(formatterByConvention, nameof(ITypeFormatter.Type), out Type formattedType))
{
formattedType = type;
}
var formatter = new AnonymousTypeFormatter<object>(
(value, context) => formatExpr(value, context.Writer),
mimeTyp,
formattedType);
_defaultTypeFormatters.Push(formatter);
foundFormatter = true;
}
}
}
}
if (TryGetPropertyValue<string[]>(attr, nameof(TypeFormatterSourceAttribute.PreferredMimeTypes), out var mimeTypes))
{
SetPreferredMimeTypesFor(type, mimeTypes);
}
}
return foundFormatter;
}
}
internal static ITypeFormatter TryFindPreferredFormatter(Type actualType, string mimeType, IEnumerable<ITypeFormatter> formatters)
{
// Find the most specific type that specifies a mimeType
var candidates =
formatters
.Where(formatter => formatter.MimeType == mimeType && formatter.Type.IsRelevantFormatterFor(actualType))
.Select((x, i) => (formatter: x, index: i))
.ToArray();
switch (candidates.Length)
{
case 0:
return null;
case 1:
return candidates[0].formatter;
default:
Array.Sort(candidates, new SortByRelevanceAndOrder<(ITypeFormatter formatter, int index)>(tup => tup.formatter.Type, tup => tup.index));
// Compose the possible formatters into one formatter, trying each in turn
return new AnonymousTypeFormatter<object>((value, context) =>
{
for (var i = 0; i < candidates.Length; i++)
{
var formatter = candidates[i];
if (formatter.formatter.Format(value, context))
{
return true;
}
}
return false;
}, mimeType, candidates[0].formatter.Type);
}
}
private static IReadOnlyCollection<T> ReadOnlyMemoryToArray<T>(ReadOnlyMemory<T> mem) => mem.Span.ToArray();
internal static readonly MethodInfo FormatReadOnlyMemoryMethod =
typeof(Formatter)
.GetMethods(BindingFlags.NonPublic | BindingFlags.Static)
.Single(m => m.Name == nameof(ReadOnlyMemoryToArray));
private static bool TryGetPropertyValue<T>(object fromObject, string propertyName, out T value)
{
if (fromObject.GetType().GetProperty(propertyName) is { } propInfo &&
propInfo.GetGetMethod() is { } getMethod)
{
object valueObj = getMethod.Invoke(fromObject, null);
if (valueObj is T valueT)
{
value = valueT;
return true;
}
}
value = default;
return false;
}
internal static bool ShouldIncludePropertiesInOutput(this Type type)
{
if (type.IsArray)
{
return false;
}
if (type.IsNestedPrivate) //e.g. RangeIterator
{
return false;
}
if (typeof(ICollection).IsAssignableFrom(type))
{
return false;
}
foreach (var @interface in type.GetTypeInfo().ImplementedInterfaces)
{
if (@interface.IsConstructedGenericType)
{
if (@interface.GetGenericTypeDefinition() == typeof(IOrderedEnumerable<>))
{
return false;
}
if (@interface.GetGenericTypeDefinition() == typeof(IDictionary<,>))
{
return false;
}
}
}
return true;
}
}