Skip to content

Commit c3fc275

Browse files
author
Samuel Abraham
committed
v9.2.2
1 parent 561ef00 commit c3fc275

45 files changed

Lines changed: 1243 additions & 726 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/TypeCache.GraphQL/Extensions/GraphQLExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static FieldType AddField(this IComplexGraphType @this, MethodEntity meth
3737

3838
public static FieldType AddField(this IComplexGraphType @this, MethodEntity method, IFieldResolver resolver)
3939
{
40-
var fieldType = CreateFieldType(method);
40+
var fieldType = CreateFieldType(method, method.Return.ParameterType);
4141
fieldType.Resolver = resolver;
4242
return fieldType;
4343
}
@@ -47,7 +47,7 @@ public static FieldType AddField(this IComplexGraphType @this, StaticMethodEntit
4747

4848
public static FieldType AddField(this IComplexGraphType @this, StaticMethodEntity method, IFieldResolver resolver)
4949
{
50-
var fieldType = CreateFieldType(method);
50+
var fieldType = CreateFieldType(method, method.Return.ParameterType);
5151
fieldType.Resolver = resolver;
5252
return fieldType;
5353
}
@@ -57,7 +57,7 @@ public static FieldType AddFieldStream(this IComplexGraphType @this, MethodEntit
5757

5858
public static FieldType AddFieldStream(this IComplexGraphType @this, MethodEntity method, ISourceStreamResolver resolver)
5959
{
60-
var fieldType = CreateFieldType(method);
60+
var fieldType = CreateFieldType(method, method.Return.ParameterType);
6161
fieldType.StreamResolver = resolver;
6262
return fieldType;
6363
}
@@ -67,7 +67,7 @@ public static FieldType AddFieldStream(this IComplexGraphType @this, StaticMetho
6767

6868
public static FieldType AddFieldStream(this IComplexGraphType @this, StaticMethodEntity method, ISourceStreamResolver resolver)
6969
{
70-
var fieldType = CreateFieldType(method);
70+
var fieldType = CreateFieldType(method, method.Return.ParameterType);
7171
fieldType.StreamResolver = resolver;
7272
return fieldType;
7373
}
@@ -213,7 +213,7 @@ public static Type ToListGraphType(this Type @this)
213213
public static Type ToNonNullGraphType(this Type @this)
214214
=> typeof(NonNullGraphType<>).MakeGenericType(@this);
215215

216-
private static FieldType CreateFieldType(Method method)
216+
private static FieldType CreateFieldType(Method method, Type returnType)
217217
=> new()
218218
{
219219
Arguments = new QueryArguments(method.Parameters
@@ -226,6 +226,6 @@ private static FieldType CreateFieldType(Method method)
226226
Name = (method.Attributes.GraphQLName() ?? method.Name).TrimEndIgnoreCase("Async"),
227227
Description = method.Attributes.GraphQLDescription(),
228228
DeprecationReason = method.Attributes.GraphQLDeprecationReason(),
229-
Type = method.Return.ParameterType.ToGraphQLType(false).ToNonNullGraphType()
229+
Type = returnType.ToGraphQLType(false).ToNonNullGraphType()
230230
};
231231
}

src/TypeCache.GraphQL/Extensions/SchemaExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ public static FieldType AddSqlApiInsertEndpoint<T>(this ISchema @this, IDataSour
10421042
{
10431043
Name = Invariant($"{Type<T>.Attributes.GraphQLName() ?? Type<T>.Name}OrderBy"),
10441044
};
1045-
foreach (var property in Type<T>.Properties.Values.Where(_ => !_.IsStaticGet && !_.IsStaticSet && !_.Attributes.GraphQLIgnore()))
1045+
foreach (var property in Type<T>.Properties.Values.Where(_ => !_.Attributes.GraphQLIgnore()))
10461046
{
10471047
var propertyName = property.Attributes.GraphQLName() ?? property.Name;
10481048
var propertyDeprecationReason = property.Attributes.GraphQLDeprecationReason();

src/TypeCache.GraphQL/Extensions/ServiceCollectionExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using TypeCache.GraphQL.Listeners;
1212
using TypeCache.GraphQL.Types;
1313
using TypeCache.GraphQL.Web;
14+
using TypeCache.Reflection;
1415

1516
namespace TypeCache.GraphQL.Extensions;
1617

@@ -70,10 +71,10 @@ public static IServiceCollection AddGraphQL(this IServiceCollection @this)
7071
/// <param name="options">
7172
/// Place to make calls to:<br/>
7273
/// <c>
73-
/// <see cref="OutputGraphType{T}.AddField(PropertyInfo)"/><br/>
74-
/// <see cref="OutputGraphType{T}.AddField(MethodInfo)"/><br/>
75-
/// <see cref="OutputGraphType{T}.AddField{ITEM}(MethodInfo, Func{T, ITEM[], ITEM})"/>
76-
/// <see cref="OutputGraphType{T}.AddField{ITEM}(MethodInfo, Func{T, ITEM[], ITEM[]})"/>
74+
/// <see cref="OutputGraphType{T}.AddField(PropertyEntity)"/><br/>
75+
/// <see cref="OutputGraphType{T}.AddField(StaticMethodEntity)"/><br/>
76+
/// <see cref="OutputGraphType{T}.AddField{ITEM}(StaticMethodEntity, Func{T, ITEM[], ITEM})"/>
77+
/// <see cref="OutputGraphType{T}.AddField{ITEM}(StaticMethodEntity, Func{T, ITEM[], ITEM[]})"/>
7778
/// </c>
7879
/// </param>
7980
public static IServiceCollection AddGraphQLTypeExtensions<T>(this IServiceCollection @this, Action<OutputGraphType<T>> options)

src/TypeCache.GraphQL/TypeCache.GraphQL.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Nullable>enable</Nullable>
55
<RootNamespace>TypeCache.GraphQL</RootNamespace>
66
<PackageId>TypeCache.GraphQL</PackageId>
7-
<Version>9.2.1</Version>
7+
<Version>9.2.2</Version>
88
<Authors>Samuel Abraham &lt;sam987883@gmail.com&gt;</Authors>
99
<Company>Samuel Abraham &lt;sam987883@gmail.com&gt;</Company>
1010
<Title>TypeCache GraphQL</Title>

src/TypeCache.GraphQL/Types/InputGraphType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public InputGraphType()
1717
this.DeprecationReason = Type<T>.Attributes.GraphQLDeprecationReason();
1818

1919
Type<T>.Properties.Values
20-
.Where(_ => !_.IsStaticGet && !_.IsStaticSet && _.CanRead && _.CanWrite && !_.Attributes.GraphQLIgnore())
20+
.Where(_ => _.CanRead && _.CanWrite && !_.Attributes.GraphQLIgnore())
2121
.ForEach(_ => this.AddField(new()
2222
{
2323
Type = _.ToGraphQLType(true),

src/TypeCache.GraphQL/Types/OutputGraphType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public FieldType AddField<ITEM>(StaticMethodEntity method)
7272
/// The name of the field is the name or <see cref="GraphQLNameAttribute"/> of the <paramref name="method"/>.
7373
/// </summary>
7474
/// <param name="method">The method that loads data for all result items (<typeparamref name="ITEM"/>[]). This method can contain user input query parameters.</param>
75-
/// <param name="getResult">Reduces the data returned by <paramref name="methodInfo"/>.</param>
75+
/// <param name="getResult">Reduces the data returned by <paramref name="method"/>.</param>
7676
public FieldType AddField<ITEM>(StaticMethodEntity method, Func<T, ITEM[], ITEM> getResult)
7777
where ITEM : notnull
7878
{
@@ -103,7 +103,7 @@ public FieldType AddField<ITEM>(StaticMethodEntity method, Func<T, ITEM[], ITEM>
103103
/// The name of the field is the name or <see cref="GraphQLNameAttribute"/> of the <paramref name="method"/>.
104104
/// </summary>
105105
/// <param name="method">The method that loads data for all result items. This method can contain user input query parameters.</param>
106-
/// <param name="getResult">Reduces the data returned by <paramref name="methodInfo"/>.</param>
106+
/// <param name="getResult">Reduces the data returned by <paramref name="method"/>.</param>
107107
public FieldType AddField<ITEM>(StaticMethodEntity method, Func<T, ITEM[], ITEM[]> getResult)
108108
where ITEM : notnull
109109
{

src/TypeCache/Adapters/CollectionAdapter.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,58 @@
66

77
namespace TypeCache.Adapters;
88

9-
internal sealed class CollectionAdapter : ICollection<object>
9+
public class CollectionAdapter : ICollection<object>
1010
{
11-
private readonly object _Collection;
11+
protected readonly object _Collection;
1212

1313
private readonly PropertyEntity _Count;
1414
private readonly PropertyEntity _IsReadOnly;
15-
private readonly MethodSet<MethodEntity> _Add;
16-
private readonly MethodSet<MethodEntity> _Clear;
17-
private readonly MethodSet<MethodEntity> _Contains;
18-
private readonly MethodSet<MethodEntity> _CopyTo;
19-
private readonly MethodSet<MethodEntity> _GetEnumerator;
20-
private readonly MethodSet<MethodEntity> _Remove;
15+
private readonly MethodEntity _Add;
16+
private readonly MethodEntity _Clear;
17+
private readonly MethodEntity _Contains;
18+
private readonly MethodEntity _CopyTo;
19+
private readonly MethodEntity _Remove;
2120

2221
public CollectionAdapter(object collection)
2322
{
23+
collection.ThrowIfNull();
24+
(collection.GetType().Implements(typeof(ICollection<>))).ThrowIfFalse();
25+
2426
this._Collection = collection;
2527

26-
var methods = collection.GetType().Methods();
27-
var properties = collection.GetType().Properties();
28-
29-
this._Count = properties[nameof(Count)];
30-
this._IsReadOnly = properties[nameof(IsReadOnly)];
31-
this._Add = methods[nameof(Add)];
32-
this._Clear = methods[nameof(Clear)];
33-
this._Contains = methods[nameof(Contains)];
34-
this._CopyTo = methods[nameof(CopyTo)];
35-
this._GetEnumerator = methods[nameof(GetEnumerator)];
36-
this._Remove = methods[nameof(Remove)];
28+
var collectionType = collection.GetType().GetInterfaces().First(_ => _.Is(typeof(ICollection<>)));
29+
30+
this._Count = collectionType.Properties()[nameof(Count)];
31+
this._IsReadOnly = collectionType.Properties()[nameof(IsReadOnly)];
32+
this._Add = collectionType.Methods()[nameof(Add)].First();
33+
this._Clear = collectionType.Methods()[nameof(Clear)].First()!;
34+
this._Contains = collectionType.Methods()[nameof(Contains)].First();
35+
this._CopyTo = collectionType.Methods()[nameof(CopyTo)].First();
36+
this._Remove = collectionType.Methods()[nameof(Remove)].First();
3737
}
3838

3939
public int Count => (int)this._Count.GetValue(this._Collection)!;
4040

4141
public bool IsReadOnly => (bool)this._IsReadOnly.GetValue(this._Collection)!;
4242

4343
public void Add(object item)
44-
=> this._Add.Find([item])!.Invoke(this._Collection, item.ToValueTuple());
44+
=> this._Add.Invoke(this._Collection, item.ToValueTuple());
4545

4646
public void Clear()
47-
=> this._Clear.FindWithNoArguments()!.Invoke(this._Collection);
47+
=> this._Clear.Invoke(this._Collection);
4848

4949
public bool Contains(object item)
50-
=> (bool)this._Contains.Find([item])!.Invoke(this._Collection, item.ToValueTuple())!;
50+
=> (bool)this._Contains.Invoke(this._Collection, item.ToValueTuple())!;
5151

5252
public void CopyTo(object[] array, int arrayIndex)
53-
=> this._CopyTo.Find([array, arrayIndex])!.Invoke(this._Collection, [array, arrayIndex]);
53+
=> this.ForEach(item => array[arrayIndex++] = item);
5454

55-
public IEnumerator<object> GetEnumerator()
56-
=> (IEnumerator<object>)this._GetEnumerator.FindWithNoArguments()!.Invoke(this._Collection)!;
55+
public IEnumerator GetEnumerator()
56+
=> ((IEnumerable)this._Collection).GetEnumerator();
5757

58-
public bool Remove(object item)
59-
=> (bool)this._Remove.Find([item])!.Invoke(this._Collection, item.ToValueTuple())!;
58+
IEnumerator<object> IEnumerable<object>.GetEnumerator()
59+
=> ((IEnumerable)this._Collection).OfType<object>().GetEnumerator();
6060

61-
IEnumerator IEnumerable.GetEnumerator()
62-
=> this.GetEnumerator();
61+
public bool Remove(object item)
62+
=> (bool)this._Remove.Invoke(this._Collection, item.ToValueTuple())!;
6363
}
Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,73 @@
11
// Copyright (c) 2021 Samuel Abraham
22

33
using System.Collections;
4+
using System.Collections.Generic;
45
using TypeCache.Extensions;
56
using TypeCache.Reflection;
67

78
namespace TypeCache.Adapters;
89

9-
internal class DictionaryAdapter : IDictionary<object, object>
10+
public class DictionaryAdapter : CollectionAdapter, IDictionary<object, object>
1011
{
1112
private readonly object _Dictionary;
1213

13-
private readonly PropertyEntity _Count;
14-
private readonly PropertyEntity _Item;
15-
private readonly PropertyEntity _IsReadOnly;
14+
private readonly PropertyIndexerEntity _Item;
1615
private readonly PropertyEntity _Keys;
1716
private readonly PropertyEntity _Values;
18-
private readonly MethodSet<MethodEntity> _Add;
19-
private readonly MethodSet<MethodEntity> _Clear;
20-
private readonly MethodSet<MethodEntity> _ContainsKey;
21-
private readonly MethodSet<MethodEntity> _CopyTo;
22-
private readonly MethodSet<MethodEntity> _GetEnumerator;
23-
private readonly MethodSet<MethodEntity> _Remove;
17+
private readonly MethodEntity _Add;
18+
private readonly MethodEntity _ContainsKey;
19+
private readonly MethodEntity _Remove;
2420

2521
public DictionaryAdapter(object dictionary)
22+
: base(dictionary)
2623
{
2724
this._Dictionary = dictionary;
25+
(dictionary.GetType().Implements(typeof(IDictionary<,>))).ThrowIfFalse();
2826

29-
var methods = dictionary.GetType().Methods();
30-
var properties = dictionary.GetType().Properties();
31-
32-
this._Count = properties[nameof(Count)];
33-
this._Item = properties["Item"];
34-
this._IsReadOnly = properties[nameof(IsReadOnly)];
35-
this._Keys = properties[nameof(Keys)];
36-
this._Values = properties[nameof(Values)];
37-
this._Add = methods[nameof(Add)];
38-
this._Clear = methods[nameof(Clear)];
39-
this._ContainsKey = methods[nameof(ContainsKey)];
40-
this._CopyTo = methods[nameof(CopyTo)];
41-
this._GetEnumerator = methods[nameof(GetEnumerator)];
42-
this._Remove = methods[nameof(Remove)];
27+
var dictionaryType = dictionary.GetType().GetInterfaces().First(_ => _.Is(typeof(IDictionary<,>)));
28+
29+
this._Item = dictionaryType.DefaultIndexer()!;
30+
this._Keys = dictionaryType.Properties()[nameof(Keys)];
31+
this._Values = dictionaryType.Properties()[nameof(Values)];
32+
this._Add = dictionaryType.Methods()[nameof(Add)].First(_ => _.Parameters.Count is 2);
33+
this._ContainsKey = dictionaryType.Methods()[nameof(ContainsKey)].First();
34+
this._Remove = dictionaryType.Methods()[nameof(Remove)].First(_ => _.Parameters[0].ParameterType == dictionaryType.GetGenericArguments()[0]);
4335
}
4436

4537
public object this[object key]
4638
{
47-
get => this._Item[ValueTuple.Create(key)].GetValue(this._Dictionary)!;
48-
set => this._Item[ValueTuple.Create(key)].SetValue(this._Dictionary, value);
39+
get => this._Item.GetValue(this._Dictionary, ValueTuple.Create(key))!;
40+
set => this._Item.SetValue(this._Dictionary, ValueTuple.Create(key), value);
4941
}
5042

5143
public ICollection<object> Keys => new CollectionAdapter(this._Keys.GetValue(this._Dictionary)!);
5244

5345
public ICollection<object> Values => new CollectionAdapter(this._Values.GetValue(this._Dictionary)!);
5446

55-
public int Count => (int)_Count.GetValue(this._Dictionary)!;
56-
57-
public bool IsReadOnly => (bool)_IsReadOnly.GetValue(this._Dictionary)!;
58-
5947
public void Add(object key, object value)
60-
=> _ = this._Add.Find([key, value])!.Invoke(this._Dictionary, [key, value]);
48+
=> _ = this._Add.Invoke(this._Dictionary, [key, value]);
6149

6250
public void Add(KeyValuePair<object, object> item)
6351
=> throw new NotImplementedException();
6452

65-
public void Clear()
66-
=> _ = this._Clear.FindWithNoArguments()!.Invoke(this._Dictionary);
67-
6853
public bool Contains(KeyValuePair<object, object> item)
6954
=> throw new NotImplementedException();
7055

7156
public bool ContainsKey(object key)
72-
=> (bool)this._ContainsKey.Find(key.ToValueTuple())!.Invoke(this._Dictionary, [key])!;
57+
=> (bool)this._ContainsKey.Invoke(this._Dictionary, [key])!;
7358

7459
public void CopyTo(KeyValuePair<object, object>[] array, int arrayIndex)
7560
=> throw new NotImplementedException();
7661

77-
public IEnumerator<KeyValuePair<object, object>> GetEnumerator()
62+
IEnumerator<KeyValuePair<object, object>> IEnumerable<KeyValuePair<object, object>>.GetEnumerator()
7863
=> throw new NotImplementedException();
7964

8065
public bool Remove(object key)
81-
=> (bool)this._Remove.Find(key.ToValueTuple())!.Invoke(this._Dictionary, [key])!;
66+
=> (bool)this._Remove.Invoke(this._Dictionary, [key])!;
8267

8368
public bool Remove(KeyValuePair<object, object> item)
8469
=> throw new NotImplementedException();
8570

8671
public bool TryGetValue(object key, [MaybeNullWhen(false)] out object value)
8772
=> throw new NotImplementedException();
88-
89-
IEnumerator IEnumerable.GetEnumerator()
90-
=> (IEnumerator)this._GetEnumerator.FindWithNoArguments()!.Invoke(this._Dictionary)!;
9173
}

0 commit comments

Comments
 (0)