Skip to content

Commit 61a655b

Browse files
committed
initialize commit
1 parent 6fc71b0 commit 61a655b

File tree

2 files changed

+238
-0
lines changed

2 files changed

+238
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Diagnostics.CodeAnalysis;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace SourceGeneration.Reflection.Test;
10+
11+
[TestClass]
12+
public class GenericDictionaryTypeMemberTest
13+
{
14+
[TestMethod]
15+
public void GenericDictionary()
16+
{
17+
var typeInfo = SourceReflector.GetRequiredType<GenericDictionaryMemberType>();
18+
19+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.Int))!.IsGenericDictionaryType);
20+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.Object))!.IsGenericDictionaryType);
21+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.NonGenericDictionaryInterface))!.IsGenericDictionaryType);
22+
23+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.Dictionary))!.IsGenericDictionaryType);
24+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.SortedDictionary))!.IsGenericDictionaryType);
25+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.DictionaryInterface))!.IsGenericDictionaryType);
26+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.CustomDictionary))!.IsGenericDictionaryType);
27+
28+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.Dictionary))!.IsGenericEnumerableType);
29+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.SortedDictionary))!.IsGenericEnumerableType);
30+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.DictionaryInterface))!.IsGenericEnumerableType);
31+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericDictionaryMemberType.CustomDictionary))!.IsGenericEnumerableType);
32+
}
33+
}
34+
35+
[SourceReflection]
36+
public class GenericDictionaryMemberType
37+
{
38+
public object? Object { get; set; }
39+
public int Int { get; set; }
40+
public SortedDictionary<string, string>? SortedDictionary { get; set; }
41+
public Dictionary<string, string>? Dictionary { get; set; }
42+
public IDictionary<string, string>? DictionaryInterface { get; set; }
43+
public IDictionary? NonGenericDictionaryInterface { get; set; }
44+
45+
public CustomDictionary? CustomDictionary;
46+
}
47+
48+
public class CustomDictionary : IDictionary<int, object>
49+
{
50+
public object this[int key] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
51+
52+
public ICollection<int> Keys => throw new NotImplementedException();
53+
54+
public ICollection<object> Values => throw new NotImplementedException();
55+
56+
public int Count => throw new NotImplementedException();
57+
58+
public bool IsReadOnly => throw new NotImplementedException();
59+
60+
public void Add(int key, object value)
61+
{
62+
throw new NotImplementedException();
63+
}
64+
65+
public void Add(KeyValuePair<int, object> item)
66+
{
67+
throw new NotImplementedException();
68+
}
69+
70+
public void Clear()
71+
{
72+
throw new NotImplementedException();
73+
}
74+
75+
public bool Contains(KeyValuePair<int, object> item)
76+
{
77+
throw new NotImplementedException();
78+
}
79+
80+
public bool ContainsKey(int key)
81+
{
82+
throw new NotImplementedException();
83+
}
84+
85+
public void CopyTo(KeyValuePair<int, object>[] array, int arrayIndex)
86+
{
87+
throw new NotImplementedException();
88+
}
89+
90+
public IEnumerator<KeyValuePair<int, object>> GetEnumerator()
91+
{
92+
throw new NotImplementedException();
93+
}
94+
95+
public bool Remove(int key)
96+
{
97+
throw new NotImplementedException();
98+
}
99+
100+
public bool Remove(KeyValuePair<int, object> item)
101+
{
102+
throw new NotImplementedException();
103+
}
104+
105+
public bool TryGetValue(int key, [MaybeNullWhen(false)] out object value)
106+
{
107+
throw new NotImplementedException();
108+
}
109+
110+
IEnumerator IEnumerable.GetEnumerator()
111+
{
112+
return GetEnumerator();
113+
}
114+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System.Collections;
2+
using System.Collections.ObjectModel;
3+
4+
namespace SourceGeneration.Reflection.Test;
5+
6+
[TestClass]
7+
public class GenericEnumerableTypeMemberTest
8+
{
9+
[TestMethod]
10+
public void GenericEnumerable()
11+
{
12+
var typeInfo = SourceReflector.GetRequiredType<GenericEnumerableMemberType>();
13+
14+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.Int))!.IsGenericEnumerableType);
15+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.Object))!.IsGenericEnumerableType);
16+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.NonGenericEnumerableInterface))!.IsGenericEnumerableType);
17+
18+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.EnumerableInterface))!.IsGenericEnumerableType);
19+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.ListInterface))!.IsGenericEnumerableType);
20+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.List))!.IsGenericEnumerableType);
21+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.ReadOnlyCollection))!.IsGenericEnumerableType);
22+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.CustomList))!.IsGenericEnumerableType);
23+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.CustomCollection))!.IsGenericEnumerableType);
24+
Assert.IsTrue(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.CustomEnumerable))!.IsGenericEnumerableType);
25+
26+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.EnumerableInterface))!.IsGenericDictionaryType);
27+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.ListInterface))!.IsGenericDictionaryType);
28+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.List))!.IsGenericDictionaryType);
29+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.ReadOnlyCollection))!.IsGenericDictionaryType);
30+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.CustomList))!.IsGenericDictionaryType);
31+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.CustomCollection))!.IsGenericDictionaryType);
32+
Assert.IsFalse(typeInfo.GetFieldOrProperty(nameof(GenericEnumerableMemberType.CustomEnumerable))!.IsGenericDictionaryType);
33+
}
34+
}
35+
36+
[SourceReflection]
37+
public class GenericEnumerableMemberType
38+
{
39+
public object? Object { get; set; }
40+
public int Int { get; set; }
41+
public IEnumerable<string>? EnumerableInterface { get; set; }
42+
public IList<string>? ListInterface { get; set; }
43+
public List<string>? List { get; set; }
44+
public ReadOnlyCollection<string>? ReadOnlyCollection { get; set; }
45+
public IEnumerable? NonGenericEnumerableInterface { get; set; }
46+
47+
public CustomList? CustomList;
48+
public CustomCollection? CustomCollection;
49+
public CustomEnumerable? CustomEnumerable;
50+
}
51+
52+
public class CustomList : CustomCollection, IList<int>
53+
{
54+
public int this[int index] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
55+
56+
public int IndexOf(int item)
57+
{
58+
throw new NotImplementedException();
59+
}
60+
61+
public void Insert(int index, int item)
62+
{
63+
throw new NotImplementedException();
64+
}
65+
66+
public void RemoveAt(int index)
67+
{
68+
throw new NotImplementedException();
69+
}
70+
}
71+
72+
public class CustomCollection : ICollection<int>
73+
{
74+
public int Count => throw new NotImplementedException();
75+
76+
public bool IsReadOnly => throw new NotImplementedException();
77+
78+
public void Add(int item)
79+
{
80+
throw new NotImplementedException();
81+
}
82+
83+
public void Clear()
84+
{
85+
throw new NotImplementedException();
86+
}
87+
88+
public bool Contains(int item)
89+
{
90+
throw new NotImplementedException();
91+
}
92+
93+
public void CopyTo(int[] array, int arrayIndex)
94+
{
95+
throw new NotImplementedException();
96+
}
97+
98+
public IEnumerator<int> GetEnumerator()
99+
{
100+
throw new NotImplementedException();
101+
}
102+
103+
public bool Remove(int item)
104+
{
105+
throw new NotImplementedException();
106+
}
107+
108+
IEnumerator IEnumerable.GetEnumerator()
109+
{
110+
return GetEnumerator();
111+
}
112+
}
113+
public class CustomEnumerable : IEnumerable<int>
114+
{
115+
public IEnumerator<int> GetEnumerator()
116+
{
117+
throw new NotImplementedException();
118+
}
119+
120+
IEnumerator IEnumerable.GetEnumerator()
121+
{
122+
return GetEnumerator();
123+
}
124+
}

0 commit comments

Comments
 (0)