diff --git a/src/IKVM.CoreLib/Symbols/Reflection/Emit/ReflectionTypeSymbolBuilder.cs b/src/IKVM.CoreLib/Symbols/Reflection/Emit/ReflectionTypeSymbolBuilder.cs index 5ce8a95be..7b9f0fb8a 100644 --- a/src/IKVM.CoreLib/Symbols/Reflection/Emit/ReflectionTypeSymbolBuilder.cs +++ b/src/IKVM.CoreLib/Symbols/Reflection/Emit/ReflectionTypeSymbolBuilder.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.InteropServices; @@ -311,6 +312,66 @@ public void SetCustomAttribute(ICustomAttributeBuilder customBuilder) #endregion + /// + public override IMethodSymbol? GetMethod(string name) + { + if (IsComplete) + return base.GetMethod(name); + else + return GetIncompleteMethods().FirstOrDefault(i => i.Name == name); + } + + /// + public override IMethodSymbol? GetMethod(string name, BindingFlags bindingAttr, ITypeSymbol[] types, ParameterModifier[]? modifiers) + { + if (IsComplete) + return base.GetMethod(name, bindingAttr, types, modifiers); + else + throw new NotImplementedException(); + } + + /// + public override IMethodSymbol? GetMethod(string name, BindingFlags bindingAttr, CallingConventions callConvention, ITypeSymbol[] types, ParameterModifier[]? modifiers) + { + if (IsComplete) + return base.GetMethod(name, bindingAttr, callConvention, types, modifiers); + else + throw new NotImplementedException(); + } + + /// + public override IMethodSymbol[] GetMethods() + { + if (IsComplete) + return base.GetMethods(); + else + return GetIncompleteMethods(); + } + + /// + public override IMethodSymbol[] GetMethods(BindingFlags bindingAttr) + { + if (IsComplete) + return base.GetMethods(bindingAttr); + else + return GetIncompleteMethods(bindingAttr); + } + + /// + /// Gets the set of incomplete methods. + /// + /// + IMethodSymbol[] GetIncompleteMethods(BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance) + { + if (_incompleteMethods == null) + return []; + else + return SymbolUtil.FilterMethods(this, _incompleteMethods, bindingAttr).Cast().ToArray(); + } + + /// + public override bool IsComplete => _type != null; + /// public void Complete() { diff --git a/src/IKVM.CoreLib/Symbols/Reflection/ReflectionTypeSymbolBase.cs b/src/IKVM.CoreLib/Symbols/Reflection/ReflectionTypeSymbolBase.cs index 33c07a976..fbc1bd678 100644 --- a/src/IKVM.CoreLib/Symbols/Reflection/ReflectionTypeSymbolBase.cs +++ b/src/IKVM.CoreLib/Symbols/Reflection/ReflectionTypeSymbolBase.cs @@ -483,49 +483,49 @@ public IMemberSymbol[] GetMembers() } /// - public IMethodSymbol? GetMethod(string name, System.Reflection.BindingFlags bindingAttr) + public virtual IMethodSymbol? GetMethod(string name, System.Reflection.BindingFlags bindingAttr) { return ResolveMethodSymbol(UnderlyingType.GetMethod(name, (BindingFlags)bindingAttr)); } /// - public IMethodSymbol? GetMethod(string name, ITypeSymbol[] types) + public virtual IMethodSymbol? GetMethod(string name, ITypeSymbol[] types) { return ResolveMethodSymbol(UnderlyingType.GetMethod(name, types.Unpack())); } /// - public IMethodSymbol? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types) + public virtual IMethodSymbol? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types) { return ResolveMethodSymbol(UnderlyingType.GetMethod(name, (BindingFlags)bindingAttr, null, types.Unpack(), null)); } /// - public IMethodSymbol? GetMethod(string name) + public virtual IMethodSymbol? GetMethod(string name) { return ResolveMethodSymbol(UnderlyingType.GetMethod(name)); } /// - public IMethodSymbol? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.CallingConventions callConvention, ITypeSymbol[] types, System.Reflection.ParameterModifier[]? modifiers) + public virtual IMethodSymbol? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.CallingConventions callConvention, ITypeSymbol[] types, System.Reflection.ParameterModifier[]? modifiers) { return ResolveMethodSymbol(UnderlyingType.GetMethod(name, (BindingFlags)bindingAttr, null, (CallingConventions)callConvention, types.Unpack(), modifiers?.Unpack())); } /// - public IMethodSymbol? GetMethod(string name, int genericParameterCount, System.Reflection.BindingFlags bindingAttr, System.Reflection.CallingConventions callConvention, ITypeSymbol[] types, System.Reflection.ParameterModifier[]? modifiers) + public virtual IMethodSymbol? GetMethod(string name, int genericParameterCount, System.Reflection.BindingFlags bindingAttr, System.Reflection.CallingConventions callConvention, ITypeSymbol[] types, System.Reflection.ParameterModifier[]? modifiers) { throw new NotImplementedException(); } /// - public IMethodSymbol? GetMethod(string name, int genericParameterCount, System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types, System.Reflection.ParameterModifier[]? modifiers) + public virtual IMethodSymbol? GetMethod(string name, int genericParameterCount, System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types, System.Reflection.ParameterModifier[]? modifiers) { throw new NotImplementedException(); } /// - public IMethodSymbol? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types, System.Reflection.ParameterModifier[]? modifiers) + public virtual IMethodSymbol? GetMethod(string name, System.Reflection.BindingFlags bindingAttr, ITypeSymbol[] types, System.Reflection.ParameterModifier[]? modifiers) { return ResolveMethodSymbol(UnderlyingType.GetMethod(name, (BindingFlags)bindingAttr, null, types.Unpack(), modifiers?.Unpack())); } @@ -537,13 +537,13 @@ public IMemberSymbol[] GetMembers() } /// - public IMethodSymbol[] GetMethods(System.Reflection.BindingFlags bindingAttr) + public virtual IMethodSymbol[] GetMethods(System.Reflection.BindingFlags bindingAttr) { return ResolveMethodSymbols(UnderlyingType.GetMethods((BindingFlags)bindingAttr)); } /// - public IMethodSymbol[] GetMethods() + public virtual IMethodSymbol[] GetMethods() { return ResolveMethodSymbols(UnderlyingType.GetMethods()); }