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

Generic extension exception and multiple extension methos for single userdata: fixes #130

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace MoonSharp.Interpreter.Interop.BasicDescriptors
/// </summary>
public abstract class DispatchingUserDataDescriptor : IUserDataDescriptor, IOptimizableDescriptor
{
private int m_ExtMethodsVersion = 0;
private Dictionary<string, IMemberDescriptor> m_MetaMembers = new Dictionary<string, IMemberDescriptor>();
private Dictionary<string, IMemberDescriptor> m_Members = new Dictionary<string, IMemberDescriptor>();

Expand Down Expand Up @@ -236,10 +235,8 @@ public virtual DynValue Index(Script script, object obj, DynValue index, bool is
if (v == null) v = TryIndex(script, obj, Camelify(index.String));
if (v == null) v = TryIndex(script, obj, UpperFirstLetter(Camelify(index.String)));

if (v == null && m_ExtMethodsVersion < UserData.GetExtensionMethodsChangeVersion())
if (v == null)
{
m_ExtMethodsVersion = UserData.GetExtensionMethodsChangeVersion();

v = TryIndexOnExtMethod(script, obj, index.String);
if (v == null) v = TryIndexOnExtMethod(script, obj, UpperFirstLetter(index.String));
if (v == null) v = TryIndexOnExtMethod(script, obj, Camelify(index.String));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,25 @@ private static MethodInfo InstantiateMethodInfo(MethodInfo mi, Type extensionTyp

private static Type GetGenericMatch(Type extensionType, Type extendedType)
{
extensionType = extensionType.GetGenericTypeDefinition();

foreach (Type t in extendedType.GetAllImplementedTypes())
{
if (t.IsGenericType && t.GetGenericTypeDefinition() == extensionType)
{
return t;
}
}

return null;
if (!extensionType.IsGenericParameter)
{
extensionType = extensionType.GetGenericTypeDefinition();

foreach (Type t in extendedType.GetAllImplementedTypes())
{
if (t.IsGenericType && t.GetGenericTypeDefinition() == extensionType)
{
return t;
}
}
}

/*if (extendedType.IsGenericParameter)
{
return extendedType;
}*/

return null;
}

}
Expand Down