-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
DefaultTypeInspector.cs
911 lines (759 loc) · 25.4 KB
/
DefaultTypeInspector.cs
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
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
#nullable enable
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using HotChocolate.Internal;
using HotChocolate.Types.Relay;
using HotChocolate.Utilities;
using CompDefaultValueAttribute = System.ComponentModel.DefaultValueAttribute;
using TypeInfo = HotChocolate.Internal.TypeInfo;
using static System.Reflection.BindingFlags;
namespace HotChocolate.Types.Descriptors;
/// <summary>
/// The default type inspector implementation that provides helpers to inspect .NET types and
/// infer GraphQL type structures.
/// </summary>
public class DefaultTypeInspector : Convention, ITypeInspector
{
private const string _toString = "ToString";
private const string _getHashCode = "GetHashCode";
private const string _equals = "Equals";
private const string _clone = "<Clone>$";
private readonly TypeCache _typeCache = new();
private readonly Dictionary<MemberInfo, ExtendedMethodInfo> _methods = new();
private readonly ConcurrentDictionary<(Type, bool, bool), MemberInfo[]> _memberCache = new();
private readonly Type? _dataLoaderAttribute;
public DefaultTypeInspector(bool ignoreRequiredAttribute = false)
{
IgnoreRequiredAttribute = ignoreRequiredAttribute;
_dataLoaderAttribute = Type.GetType("HotChocolate.DataLoaderAttribute");
}
/// <summary>
/// Infer type to be non-null if <see cref="RequiredAttribute"/> is found.
/// </summary>
public bool IgnoreRequiredAttribute { get; protected set; }
/// <inheritdoc />
public ReadOnlySpan<MemberInfo> GetMembers(
Type type,
bool includeIgnored = false,
bool includeStatic = false)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
var cacheKey = (type, includeIgnored, includeStatic);
if (_memberCache.TryGetValue(cacheKey, out var cached))
{
return cached;
}
var members = includeStatic
? type.GetMembers(Instance | Static | Public)
: type.GetMembers(Instance | Public);
var temp = ArrayPool<MemberInfo>.Shared.Rent(members.Length);
var next = 0;
foreach (var member in members)
{
if (CanBeHandled(member, includeIgnored))
{
temp[next++] = member;
}
}
var span = temp.AsSpan().Slice(0, next);
var selectedMembers = new MemberInfo[next];
span.CopyTo(selectedMembers);
span.Clear();
_memberCache.TryAdd(cacheKey, selectedMembers);
ArrayPool<MemberInfo>.Shared.Return(temp);
return selectedMembers;
}
/// <inheritdoc />
public virtual bool IsMemberIgnored(MemberInfo member)
{
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
return member.IsDefined(typeof(GraphQLIgnoreAttribute));
}
/// <inheritdoc />
public virtual ITypeReference GetReturnTypeRef(
MemberInfo member,
TypeContext context = TypeContext.None,
string? scope = null,
bool ignoreAttributes = false)
{
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
ITypeReference typeRef = TypeReference.Create(GetReturnType(member), context, scope);
if (!ignoreAttributes &&
TryGetAttribute(member, out GraphQLTypeAttribute? attribute) &&
attribute.TypeSyntax is not null)
{
return TypeReference.Create(attribute.TypeSyntax, context, scope);
}
return typeRef;
}
/// <inheritdoc />
public virtual IExtendedType GetReturnType(
MemberInfo member,
bool ignoreAttributes = false)
{
if (member is null)
{
throw new ArgumentNullException(nameof(member));
}
IExtendedType returnType = ExtendedType.FromMember(member, _typeCache);
return ignoreAttributes
? returnType
: ApplyTypeAttributes(returnType, member);
}
/// <inheritdoc />
public ITypeReference GetArgumentTypeRef(
ParameterInfo parameter,
string? scope = null,
bool ignoreAttributes = false)
{
if (parameter is null)
{
throw new ArgumentNullException(nameof(parameter));
}
ITypeReference typeRef = TypeReference.Create(
GetArgumentType(
parameter,
ignoreAttributes),
TypeContext.Input,
scope);
if (!ignoreAttributes &&
TryGetAttribute(parameter, out GraphQLTypeAttribute? attribute) &&
attribute.TypeSyntax is not null)
{
return TypeReference.Create(attribute.TypeSyntax, TypeContext.Input, scope);
}
return typeRef;
}
/// <inheritdoc />
public IExtendedType GetArgumentType(
ParameterInfo parameter,
bool ignoreAttributes = false)
{
if (parameter is null)
{
throw new ArgumentNullException(nameof(parameter));
}
var argumentType = GetArgumentTypeInternal(parameter);
return ignoreAttributes
? argumentType
: ApplyTypeAttributes(argumentType, parameter);
}
private IExtendedType GetArgumentTypeInternal(ParameterInfo parameter)
{
var method = (MethodInfo)parameter.Member;
if (!_methods.TryGetValue(method, out var info))
{
info = ExtendedType.FromMethod(method, _typeCache);
_methods[method] = info;
}
return info.ParameterTypes[parameter];
}
/// <inheritdoc />
public ExtendedTypeReference GetTypeRef(
Type type,
TypeContext context = TypeContext.None,
string? scope = null) =>
TypeReference.Create(GetType(type), context, scope);
/// <inheritdoc />
public IExtendedType GetType(Type type)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
return ExtendedType.FromType(type, _typeCache);
}
/// <inheritdoc />
public IExtendedType GetType(Type type, params bool?[] nullable)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (nullable is null)
{
throw new ArgumentNullException(nameof(nullable));
}
var extendedType = ExtendedType.FromType(type, _typeCache);
return nullable is { Length: > 0 }
? ExtendedType.Tools.ChangeNullability(extendedType, nullable, _typeCache)
: extendedType;
}
/// <inheritdoc />
public IExtendedType GetType(Type type, ReadOnlySpan<bool?> nullable)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
var extendedType = ExtendedType.FromType(type, _typeCache);
return nullable is { Length: > 0 }
? ExtendedType.Tools.ChangeNullability(extendedType, nullable, _typeCache)
: extendedType;
}
/// <inheritdoc />
public virtual IEnumerable<object> GetEnumValues(Type enumType)
{
if (enumType is null)
{
throw new ArgumentNullException(nameof(enumType));
}
if (enumType != typeof(object) && enumType.IsEnum)
{
return Enum.GetValues(enumType).Cast<object>();
}
return Enumerable.Empty<object>();
}
/// <inheritdoc />
public MemberInfo? GetEnumValueMember(object value)
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
var enumType = value.GetType();
if (enumType.IsEnum)
{
return enumType.GetMember(value.ToString()!).FirstOrDefault();
}
return null;
}
public virtual MemberInfo? GetNodeIdMember(Type type)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
foreach (var member in GetMembers(type))
{
if (member.Name.Equals("Id", StringComparison.OrdinalIgnoreCase) ||
member.Name.Equals("GetId", StringComparison.OrdinalIgnoreCase) ||
member.Name.Equals("GetIdAsync", StringComparison.OrdinalIgnoreCase))
{
return member;
}
}
return null;
}
public virtual MethodInfo? GetNodeResolverMethod(Type nodeType, Type? resolverType = null)
{
if (nodeType is null)
{
throw new ArgumentNullException(nameof(nodeType));
}
// if we are inspecting the node type itself the method mus be static and does
// not need to include the node name.
if (resolverType is null)
{
foreach (var member in nodeType.GetMembers(Static | Public | FlattenHierarchy))
{
if (member is MethodInfo m && IsPossibleNodeResolver(m, nodeType))
{
return m;
}
}
return null;
}
// if we have a resolver type on the other hand the load method must
// include the type name and can be an instance method.
// first we will check for static load methods.
MethodInfo? method = null;
foreach (var member in resolverType.GetMembers(Static | Public | FlattenHierarchy))
{
if (member is MethodInfo m && IsPossibleExternalNodeResolver(m, nodeType))
{
method = m;
break;
}
}
if (method is not null)
{
return method;
}
// if there is no static load method we will move on the check
// for instance load methods.
foreach (var member in GetMembers(resolverType))
{
if (member is MethodInfo m && IsPossibleExternalNodeResolver(m, nodeType))
{
return m;
}
}
return null;
}
private static bool IsPossibleNodeResolver(
MemberInfo member,
Type nodeType) =>
member.IsDefined(typeof(NodeResolverAttribute)) ||
member.Name.Equals("Get", StringComparison.OrdinalIgnoreCase) ||
member.Name.Equals("GetAsync", StringComparison.OrdinalIgnoreCase) ||
IsPossibleExternalNodeResolver(member, nodeType);
private static bool IsPossibleExternalNodeResolver(
MemberInfo member,
Type nodeType) =>
member.IsDefined(typeof(NodeResolverAttribute)) ||
member.Name.Equals(
$"Get{nodeType.Name}",
StringComparison.OrdinalIgnoreCase) ||
member.Name.Equals(
$"Get{nodeType.Name}Async",
StringComparison.OrdinalIgnoreCase);
/// <inheritdoc />
public Type ExtractNamedType(Type type)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(NativeType<>))
{
return type;
}
return ExtendedType.Tools.GetNamedType(type) ?? type;
}
/// <inheritdoc />
public bool IsSchemaType(Type type)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
return ExtendedType.Tools.IsSchemaType(type);
}
/// <inheritdoc />
public void ApplyAttributes(
IDescriptorContext context,
IDescriptor descriptor,
ICustomAttributeProvider attributeProvider)
{
var attributes = attributeProvider.GetCustomAttributes(true);
var temp = ArrayPool<DescriptorAttribute>.Shared.Rent(attributes.Length);
var i = 0;
foreach (var attribute in attributeProvider.GetCustomAttributes(true))
{
if (attribute is DescriptorAttribute casted)
{
temp[i++] = casted;
}
}
Array.Sort(temp, 0, i, DescriptorAttributeComparer.Default);
var span = temp.AsSpan().Slice(0, i);
foreach (var attribute in span)
{
attribute.TryConfigure(context, descriptor, attributeProvider);
}
span.Clear();
ArrayPool<DescriptorAttribute>.Shared.Return(temp);
}
private sealed class DescriptorAttributeComparer : IComparer
{
public static DescriptorAttributeComparer Default { get; } = new();
public int Compare(object? x, object? y)
{
if (ReferenceEquals(x, y))
{
return 0;
}
if (y is not DescriptorAttribute attr2)
{
return 1;
}
if (x is not DescriptorAttribute attr1)
{
return -1;
}
return attr1.Order.CompareTo(attr2.Order);
}
}
/// <inheritdoc />
public virtual bool TryGetDefaultValue(ParameterInfo parameter, out object? defaultValue)
{
if (parameter.IsDefined(typeof(CompDefaultValueAttribute)))
{
defaultValue = parameter.GetCustomAttribute<CompDefaultValueAttribute>()!.Value;
return true;
}
if (parameter.HasDefaultValue)
{
defaultValue = parameter.DefaultValue;
return true;
}
defaultValue = null;
return false;
}
/// <inheritdoc />
public virtual bool TryGetDefaultValue(PropertyInfo property, out object? defaultValue)
{
if (TryGetAttribute(property, out CompDefaultValueAttribute? attribute))
{
defaultValue = attribute.Value;
return true;
}
if (TryGetDefaultValueFromConstructor(property, out defaultValue))
{
return true;
}
defaultValue = null;
return false;
}
/// <inheritdoc />
public IExtendedType ChangeNullability(IExtendedType type, params bool?[] nullable)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (nullable is null)
{
throw new ArgumentNullException(nameof(nullable));
}
if (nullable.Length > 32)
{
throw new ArgumentException(
"Types with more than 32 components are not supported.");
}
if (nullable.Length == 0)
{
return type;
}
return ExtendedType.Tools.ChangeNullability(type, nullable, _typeCache);
}
private IExtendedType ChangeNullabilityInternal(IExtendedType type, params bool[] nullable)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (nullable is null)
{
throw new ArgumentNullException(nameof(nullable));
}
if (nullable.Length > 32)
{
throw new ArgumentException(
"Types with more than 32 components are not supported.");
}
if (nullable.Length == 0)
{
return type;
}
Span<bool?> n = stackalloc bool?[nullable.Length];
for (var i = 0; i < n.Length; i++)
{
n[i] = nullable[i];
}
return ExtendedType.Tools.ChangeNullability(type, n, _typeCache);
}
/// <inheritdoc />
public IExtendedType ChangeNullability(IExtendedType type, ReadOnlySpan<bool?> nullable)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
if (nullable.Length > 32)
{
throw new ArgumentException(
"Types with more than 32 components are not supported.");
}
if (nullable.Length == 0)
{
return type;
}
return ExtendedType.Tools.ChangeNullability(type, nullable, _typeCache);
}
/// <inheritdoc />
public bool?[] CollectNullability(IExtendedType type)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
return ExtendedType.Tools.CollectNullability(type);
}
/// <inheritdoc />
public bool CollectNullability(IExtendedType type, Span<bool?> buffer, out int written)
{
if (type is null)
{
throw new ArgumentNullException(nameof(type));
}
return ExtendedType.Tools.CollectNullability(type, buffer, out written);
}
/// <inheritdoc />
public ITypeInfo CreateTypeInfo(Type type) =>
TypeInfo.Create(GetType(type), _typeCache);
/// <inheritdoc />
public ITypeInfo CreateTypeInfo(IExtendedType type) =>
TypeInfo.Create(type, _typeCache);
/// <inheritdoc />
public ITypeFactory CreateTypeFactory(IExtendedType type) =>
TypeInfo.Create(type, _typeCache);
/// <inheritdoc />
public bool TryCreateTypeInfo(
Type type,
[NotNullWhen(true)] out ITypeInfo? typeInfo) =>
TryCreateTypeInfo(GetType(type), out typeInfo);
/// <inheritdoc />
public bool TryCreateTypeInfo(
IExtendedType type,
[NotNullWhen(true)] out ITypeInfo? typeInfo)
{
if (TypeInfo.TryCreate(type, _typeCache, out var t))
{
typeInfo = t;
return true;
}
typeInfo = null;
return false;
}
private IExtendedType ApplyTypeAttributes(
IExtendedType type,
ICustomAttributeProvider attributeProvider)
{
var resultType = type;
var hasGraphQLTypeAttribute = false;
if (TryGetAttribute(attributeProvider, out GraphQLTypeAttribute? typeAttribute) &&
typeAttribute.Type is { } attributeType)
{
hasGraphQLTypeAttribute = true;
resultType = GetType(attributeType);
}
if (TryGetAttribute(attributeProvider, out GraphQLNonNullTypeAttribute? nullAttribute))
{
resultType = ChangeNullabilityInternal(resultType, nullAttribute.Nullable);
}
if (!IgnoreRequiredAttribute &&
!hasGraphQLTypeAttribute &&
TryGetAttribute(attributeProvider, out RequiredAttribute? _))
{
resultType = ChangeNullability(resultType, false);
}
return resultType;
}
private static bool TryGetAttribute<T>(
ICustomAttributeProvider attributeProvider,
[NotNullWhen(true)] out T? attribute)
where T : Attribute
{
if (attributeProvider.IsDefined(typeof(T), true))
{
foreach (var item in attributeProvider.GetCustomAttributes(typeof(T), true))
{
if (item is T casted)
{
attribute = casted;
return true;
}
}
}
attribute = null;
return false;
}
private bool CanBeHandled(MemberInfo member, bool includeIgnored)
{
if (IsSystemMember(member))
{
return false;
}
if (!includeIgnored && IsMemberIgnored(member))
{
return false;
}
if (member.DeclaringType == typeof(object))
{
return false;
}
if (member is PropertyInfo { CanRead: false } ||
member is PropertyInfo { IsSpecialName: true } ||
member is MethodInfo { IsSpecialName: true })
{
return false;
}
if (member is PropertyInfo property)
{
return CanHandleReturnType(member, property.PropertyType) &&
property.GetIndexParameters().Length == 0;
}
if (member is MethodInfo method && CanHandleReturnType(member, method.ReturnType))
{
foreach (var parameter in method.GetParameters())
{
if (!CanHandleParameter(parameter))
{
return false;
}
}
if (_dataLoaderAttribute is not null &&
method.IsDefined(_dataLoaderAttribute))
{
return false;
}
return true;
}
return false;
}
private static bool CanHandleReturnType(MemberInfo member, Type returnType)
{
if (returnType == typeof(void) ||
returnType == typeof(Task) ||
returnType == typeof(ValueTask))
{
return false;
}
if (returnType == typeof(object) ||
returnType == typeof(Task<object>) ||
returnType == typeof(ValueTask<object>))
{
return HasConfiguration(member);
}
if (typeof(IAsyncResult).IsAssignableFrom(returnType))
{
if (returnType.IsGenericType)
{
var returnTypeDefinition = returnType.GetGenericTypeDefinition();
if (returnTypeDefinition == typeof(ValueTask<>) ||
returnTypeDefinition == typeof(Task<>))
{
return true;
}
}
return false;
}
// All other types may cause errors and need to have an explicit configuration.
if (typeof(ITypeSystemMember).IsAssignableFrom(returnType))
{
return HasConfiguration(member);
}
// reflection types should also be excluded by default.
if (typeof(ICustomAttributeProvider).IsAssignableFrom(returnType))
{
return HasConfiguration(member);
}
#if NETSTANDARD2_0
if (returnType.IsByRef)
#else
if (returnType.IsByRefLike ||
returnType.IsByRef)
#endif
{
return false;
}
if (typeof(Delegate).IsAssignableFrom(returnType))
{
return HasConfiguration(member);
}
return true;
}
private static bool CanHandleParameter(ParameterInfo parameter)
{
// schema, object type and object field can be injected into a resolver, so
// we allow these as parameter type.
var parameterType = parameter.ParameterType;
if (typeof(ISchema).IsAssignableFrom(parameterType) ||
typeof(IObjectType).IsAssignableFrom(parameterType) ||
typeof(IOutputField).IsAssignableFrom(parameterType))
{
return true;
}
// All other types may cause errors and need to have an explicit configuration.
if (parameterType == typeof(object) ||
typeof(ITypeSystemMember).IsAssignableFrom(parameterType))
{
return HasConfiguration(parameter);
}
// Async results are not allowed.
if (parameterType == typeof(ValueTask) ||
parameterType == typeof(Task) ||
typeof(IAsyncResult).IsAssignableFrom(parameterType))
{
return false;
}
if (parameterType.IsGenericType)
{
var parameterTypeDefinition = parameterType.GetGenericTypeDefinition();
if (parameterTypeDefinition == typeof(ValueTask<>) ||
parameterTypeDefinition == typeof(Task<>))
{
return false;
}
}
// reflection types should also be excluded by default.
if (typeof(ICustomAttributeProvider).IsAssignableFrom(parameterType))
{
return HasConfiguration(parameter);
}
// by ref and out will never be allowed
if (parameterType.IsByRef ||
#if !NETSTANDARD2_0
parameter.ParameterType.IsByRefLike ||
#endif
parameter.IsOut)
{
return false;
}
if (typeof(Delegate).IsAssignableFrom(parameterType))
{
return HasConfiguration(parameter);
}
return true;
}
private static bool HasConfiguration(ICustomAttributeProvider element)
=> element.IsDefined(typeof(GraphQLTypeAttribute), true) ||
element.IsDefined(typeof(ParentAttribute), true) ||
element.IsDefined(typeof(ServiceAttribute), true) ||
element.IsDefined(typeof(GlobalStateAttribute), true) ||
#pragma warning disable CS0618
element.IsDefined(typeof(ScopedServiceAttribute), true) ||
#pragma warning restore CS0618
element.IsDefined(typeof(ScopedStateAttribute), true) ||
element.IsDefined(typeof(LocalStateAttribute), true) ||
element.IsDefined(typeof(DescriptorAttribute), true);
private static bool IsSystemMember(MemberInfo member)
{
if (member is MethodInfo m &&
(m.Name.EqualsOrdinal(_toString) ||
m.Name.EqualsOrdinal(_getHashCode) ||
m.Name.EqualsOrdinal(_equals) ||
m.Name.EqualsOrdinal(_clone)))
{
return true;
}
return false;
}
private bool TryGetDefaultValueFromConstructor(
PropertyInfo property,
out object? defaultValue)
{
defaultValue = null;
var constructors = property.DeclaringType!.GetConstructors();
if (constructors.Length == 1)
{
foreach (var parameter in constructors[0].GetParameters())
{
if (parameter.Name.EqualsOrdinal(property.Name))
{
return TryGetDefaultValue(parameter, out defaultValue);
}
}
}
return false;
}
}