Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overload inference for polymorphic operators #1291

Merged
merged 2 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Bonsai.Design/Bonsai.Design.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageTags>Bonsai Design Rx Reactive Extensions</PackageTags>
<UseWindowsForms>true</UseWindowsForms>
<TargetFramework>net462</TargetFramework>
<VersionPrefix>2.7.0</VersionPrefix>
<VersionPrefix>2.7.1</VersionPrefix>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Bonsai.Core\Bonsai.Core.csproj" />
Expand Down
13 changes: 10 additions & 3 deletions Bonsai.Design/TypeMappingEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static IEnumerable<MethodInfo> GetProcessMethods(Type combinatorType)
{
const BindingFlags bindingAttributes = BindingFlags.Instance | BindingFlags.Public;
var combinatorAttributes = combinatorType.GetCustomAttributes(typeof(CombinatorAttribute), true);
if (combinatorAttributes.Length != 1) return Enumerable.Empty<MethodInfo>();
var methodName = ((CombinatorAttribute)combinatorAttributes.Single()).MethodName;
return combinatorType.GetMethods(bindingAttributes).Where(m => m.Name == methodName);
}
Expand All @@ -51,10 +52,16 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide
var intersection = default(HashSet<Type>);
foreach (var successor in builderNode.Successors)
{
var combinatorBuilder = ExpressionBuilder.Unwrap(successor.Target.Value) as CombinatorBuilder;
if (combinatorBuilder == null || combinatorBuilder.Combinator == null) continue;
var combinator = ExpressionBuilder.Unwrap(successor.Target.Value) switch
{
CombinatorBuilder combinatorBuilder => combinatorBuilder.Combinator,
ICustomTypeDescriptor typeDescriptor =>
TypeDescriptor.GetDefaultProperty(typeDescriptor.GetType())?.GetValue(typeDescriptor),
_ => null
};

var inputTypes = from method in GetProcessMethods(combinatorBuilder.Combinator.GetType())
if (combinator == null) continue;
var inputTypes = from method in GetProcessMethods(combinator.GetType())
where !method.IsGenericMethod
let parameters = method.GetParameters()
where parameters.Length > successor.Label.Index &&
Expand Down