IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
Accessor.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3
5{
6
7#if FIRST_PASS == false && EXPORTER == false && IMPORTER == false
8
12 internal abstract partial class Accessor
13 {
14
15 readonly string typeName;
16 readonly AccessorTypeResolver resolver;
17 Type type;
18
25 public Accessor(AccessorTypeResolver resolver, string typeName)
26 {
27 this.resolver = resolver ?? throw new ArgumentNullException(nameof(resolver));
28 this.typeName = typeName ?? throw new ArgumentNullException(nameof(typeName));
29 }
30
34 public Type Type => AccessorUtil.LazyGet(ref type, () => Resolve(typeName));
35
41 protected Type Resolve(string typeName) => typeName != null ? resolver(typeName) : null;
42
49 protected Type Resolve(ref Type type, string typeName) => AccessorUtil.LazyGet(ref type, () => Resolve(typeName));
50
56 public object[] InitArray(int length) => (object[])Array.CreateInstance(Type, length);
57
63 public object[] InitArray(params object[] source)
64 {
65 var a = InitArray(source.Length);
66 Array.Copy(source, a, source.Length);
67 return a;
68 }
69
70 }
71
75 internal abstract partial class Accessor<TObject> : Accessor
76 {
77
83 public Accessor(AccessorTypeResolver resolver, string typeName) :
84 base(resolver, typeName)
85 {
86
87 }
88
95 protected FieldAccessor<TField> GetField<TField>(ref FieldAccessor<TField> accessor, string name) => FieldAccessor<TField>.LazyGet(ref accessor, Type, name);
96
103 protected FieldAccessor<TObject, TField> GetField<TField>(ref FieldAccessor<TObject, TField> accessor, string name) => FieldAccessor<TObject, TField>.LazyGet(ref accessor, Type, name);
104
111 protected PropertyAccessor<TField> GetProperty<TField>(ref PropertyAccessor<TField> accessor, string name) => PropertyAccessor<TField>.LazyGet(ref accessor, Type, name);
112
119 protected PropertyAccessor<TObject, TField> GetProperty<TField>(ref PropertyAccessor<TObject, TField> accessor, string name) => PropertyAccessor<TObject, TField>.LazyGet(ref accessor, Type, name);
120
127 protected MethodAccessor<TDelegate> GetConstructor<TDelegate>(ref MethodAccessor<TDelegate> accessor, params Type[] parameterTypes) where TDelegate : Delegate => MethodAccessor<TDelegate>.LazyGet(ref accessor, Type, ".ctor", typeof(void), parameterTypes);
128
136 protected MethodAccessor<TDelegate> GetMethod<TDelegate>(ref MethodAccessor<TDelegate> accessor, string name, Type returnType, params Type[] parameterTypes) where TDelegate : Delegate => MethodAccessor<TDelegate>.LazyGet(ref accessor, Type, name, returnType, parameterTypes);
137
138 }
139
140#endif
141
142}
IKVM.Reflection.Type Type