Skip to content

Commit

Permalink
RC for 2.0.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xanathar committed Oct 14, 2016
1 parent 9b81c90 commit 3154416
Show file tree
Hide file tree
Showing 65 changed files with 861 additions and 541 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using MoonSharp.Interpreter.Compatibility;
using MoonSharp.Interpreter.Interop;
using MoonSharp.Interpreter.Loaders;
using NUnit.Framework;
Expand Down Expand Up @@ -298,8 +299,8 @@ public void OverloadTest_WithoutObjects()
var ov = new OverloadedMethodMemberDescriptor("Method1", this.GetType());

// Iterate over the two methods through reflection
foreach(var method in this.GetType().GetMethods(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
.Where(mi => mi.Name == "Method1"))
foreach(var method in Framework.Do.GetMethods(this.GetType())
.Where(mi => mi.Name == "Method1" && mi.IsPrivate && !mi.IsStatic))
{
ov.AddOverload(new MethodMemberDescriptor(method));
}
Expand Down
4 changes: 2 additions & 2 deletions src/MoonSharp.Interpreter.Tests/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public IEnumerable<TestResult> IterateOnTests(string whichTest = null, string[]

foreach (Type t in types)
{
MethodInfo[] tests = t.GetMethods().Where(m => m.GetCustomAttributes(typeof(TestAttribute), true).Any()).ToArray();
MethodInfo[] tests = Framework.Do.GetMethods(t).Where(m => m.GetCustomAttributes(typeof(TestAttribute), true).Any()).ToArray();
//Console_WriteLine("Testing {0} - {1} tests found.", t.Name, tests.Length);

foreach (MethodInfo mi in tests)
Expand Down Expand Up @@ -181,7 +181,7 @@ private static TestResult RunTest(Type t, MethodInfo mi)
};
}

if (expectedEx != null && expectedEx.ExpectedException.IsInstanceOfType(ex))
if (expectedEx != null && Framework.Do.IsInstanceOfType(expectedEx.ExpectedException, ex))
{
return new TestResult()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !(DOTNET_CORE || NETFX_CORE)
#if !NETFX_CORE || DOTNET_CORE

using System;
using System.Collections.Generic;
Expand All @@ -13,96 +13,91 @@ abstract class FrameworkClrBase : FrameworkReflectionBase
BindingFlags BINDINGFLAGS_MEMBER = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
BindingFlags BINDINGFLAGS_INNERCLASS = BindingFlags.Public | BindingFlags.NonPublic;

public override Type GetTypeInfoFromType(Type t)
{
return t;
}

public override MethodInfo GetAddMethod(EventInfo ei)
{
return ei.GetAddMethod(true);
}

public override ConstructorInfo[] GetConstructors(Type type)
{
return type.GetConstructors(BINDINGFLAGS_MEMBER);
return GetTypeInfoFromType(type).GetConstructors(BINDINGFLAGS_MEMBER);
}

public override EventInfo[] GetEvents(Type type)
{
return type.GetEvents(BINDINGFLAGS_MEMBER);
return GetTypeInfoFromType(type).GetEvents(BINDINGFLAGS_MEMBER);
}

public override FieldInfo[] GetFields(Type type)
{
return type.GetFields(BINDINGFLAGS_MEMBER);
return GetTypeInfoFromType(type).GetFields(BINDINGFLAGS_MEMBER);
}

public override Type[] GetGenericArguments(Type type)
{
return type.GetGenericArguments();
return GetTypeInfoFromType(type).GetGenericArguments();
}

public override MethodInfo GetGetMethod(PropertyInfo pi)
{
return pi.GetGetMethod();
return pi.GetGetMethod(true);
}

public override Type[] GetInterfaces(Type t)
{
return t.GetInterfaces();
return GetTypeInfoFromType(t).GetInterfaces();
}

public override MethodInfo GetMethod(Type type, string name)
{
return type.GetMethod(name);
return GetTypeInfoFromType(type).GetMethod(name);
}

public override MethodInfo[] GetMethods(Type type)
{
return type.GetMethods(BINDINGFLAGS_MEMBER);
return GetTypeInfoFromType(type).GetMethods(BINDINGFLAGS_MEMBER);
}

public override Type[] GetNestedTypes(Type type)
{
return type.GetNestedTypes(BINDINGFLAGS_INNERCLASS);
return GetTypeInfoFromType(type).GetNestedTypes(BINDINGFLAGS_INNERCLASS);
}

public override PropertyInfo[] GetProperties(Type type)
{
return type.GetProperties(BINDINGFLAGS_MEMBER);
return GetTypeInfoFromType(type).GetProperties(BINDINGFLAGS_MEMBER);
}

public override PropertyInfo GetProperty(Type type, string name)
{
return type.GetProperty(name);
return GetTypeInfoFromType(type).GetProperty(name);
}

public override MethodInfo GetRemoveMethod(EventInfo ei)
{
return ei.GetRemoveMethod();
return ei.GetRemoveMethod(true);
}

public override MethodInfo GetSetMethod(PropertyInfo pi)
{
return pi.GetSetMethod();
return pi.GetSetMethod(true);
}


public override bool IsAssignableFrom(Type current, Type toCompare)
{
return current.IsAssignableFrom(toCompare);
return GetTypeInfoFromType(current).IsAssignableFrom(toCompare);
}

public override bool IsInstanceOfType(Type t, object o)
{
return t.IsInstanceOfType(o);
return GetTypeInfoFromType(t).IsInstanceOfType(o);
}


public override MethodInfo GetMethod(Type resourcesType, string name, Type[] types)
{
return resourcesType.GetMethod(name, types);
return GetTypeInfoFromType(resourcesType).GetMethod(name, types);
}

public override Type[] GetAssemblyTypes(Assembly asm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using System.Reflection;
using System.Text;

#if DOTNET_CORE || NETFX_CORE
#if DOTNET_CORE
using TTypeInfo = System.Reflection.TypeInfo;
#elif NETFX_CORE
using TTypeInfo = System.Reflection.TypeInfo;
#else
using TTypeInfo = System.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace MoonSharp.Interpreter.Compatibility.Frameworks
{
class FrameworkCurrent : FrameworkClrBase
{
public override Type GetTypeInfoFromType(Type t)
{
return t;
}

public override bool IsDbNull(object o)
{
return o != null && Convert.IsDBNull(o);
Expand Down
106 changes: 4 additions & 102 deletions src/MoonSharp.Interpreter/Compatibility/Frameworks/FrameworkCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,125 +8,27 @@

namespace MoonSharp.Interpreter.Compatibility.Frameworks
{
class FrameworkCurrent : FrameworkReflectionBase
class FrameworkCurrent : FrameworkClrBase
{
public override TypeInfo GetTypeInfoFromType(Type t)
{
return t.GetTypeInfo();
}

private T[] SafeArray<T>(IEnumerable<T> prop)
{
return prop != null ? prop.ToArray() : new T[0];
}

public override MethodInfo GetAddMethod(EventInfo ei)
{
return ei.AddMethod;
}

public override ConstructorInfo[] GetConstructors(Type type)
{
return SafeArray(GetTypeInfoFromType(type).DeclaredConstructors);
}

public override EventInfo[] GetEvents(Type type)
{
return SafeArray(GetTypeInfoFromType(type).DeclaredEvents);
}

public override FieldInfo[] GetFields(Type type)
{
return SafeArray(GetTypeInfoFromType(type).DeclaredFields);
}

public override Type[] GetGenericArguments(Type type)
{
return type.GetTypeInfo().GetGenericArguments();
}

public override MethodInfo GetGetMethod(PropertyInfo pi)
{
return pi.GetGetMethod();
}

public override Type GetInterface(Type type, string name)
{
return GetTypeInfoFromType(type).GetInterface(name);
}

public override Type[] GetInterfaces(Type t)
{
return GetTypeInfoFromType(t).GetInterfaces();
}


public override MethodInfo GetMethod(Type type, string name)
{
return GetTypeInfoFromType(type).GetMethod(name);
}

public override MethodInfo[] GetMethods(Type type)
{
return SafeArray(GetTypeInfoFromType(type).DeclaredMethods);
}

public override Type[] GetNestedTypes(Type type)
{
return SafeArray(GetTypeInfoFromType(type).DeclaredNestedTypes.Select(ti => ti.AsType()));
}

public override PropertyInfo[] GetProperties(Type type)
{
return SafeArray(GetTypeInfoFromType(type).DeclaredProperties);
}

public override PropertyInfo GetProperty(Type type, string name)
{
return GetTypeInfoFromType(type).GetProperty(name);
}

public override MethodInfo GetRemoveMethod(EventInfo ei)
{
return ei.RemoveMethod;
return type.GetTypeInfo().GetInterface(name);
}

public override MethodInfo GetSetMethod(PropertyInfo pi)
{
return pi.SetMethod;
}


public override bool IsAssignableFrom(Type current, Type toCompare)
public override TypeInfo GetTypeInfoFromType(Type t)
{
return current.GetTypeInfo().IsAssignableFrom(toCompare.GetTypeInfo());
return t.GetTypeInfo();
}

public override bool IsDbNull(object o)
{
return o != null && o.GetType().FullName.StartsWith("System.DBNull");
}

public override bool IsInstanceOfType(Type t, object o)
{
return t.GetTypeInfo().IsInstanceOfType(o);
}

public override bool StringContainsChar(string str, char chr)
{
return str.Contains(chr);
}

public override MethodInfo GetMethod(Type resourcesType, string name, Type[] types)
{
return resourcesType.GetTypeInfo().GetMethod(name, types);
}

public override Type[] GetAssemblyTypes(Assembly asm)
{
return asm.GetExportedTypes();
}

}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace MoonSharp.Interpreter.Compatibility.Frameworks
{
class FrameworkCurrent : FrameworkClrBase
{
public override Type GetTypeInfoFromType(Type t)
{
return t;
}

public override bool IsDbNull(object o)
{
return o != null && o.GetType().FullName.StartsWith("System.DBNull");
Expand Down
Loading

0 comments on commit 3154416

Please sign in to comment.