Skip to content

Added side-by-side VS 2017 build with NetStandard 1.5 support. #444

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

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
New .Net 4.5+ reflection API polyfill implemented.
  • Loading branch information
dse committed Mar 28, 2017
commit 96f14f0b83bc7b5d954a8a1c09b67a10d4b92d39
9 changes: 7 additions & 2 deletions src/runtime/Python.Runtime.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -71,6 +71,10 @@
<DebugType>full</DebugType>
</PropertyGroup>
<ItemGroup>
<Reference Include="ReflectionBridge, Version=0.0.11.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ReflectionBridge.0.0.11\lib\net40\ReflectionBridge.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -148,6 +152,7 @@
</ItemGroup>
<ItemGroup>
<None Include="..\pythonnet.snk" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="resources\clr.py">
Expand All @@ -163,4 +168,4 @@
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" />
<Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" />
</Target>
</Project>
</Project>
6 changes: 3 additions & 3 deletions src/runtime/arrayobject.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;

namespace Python.Runtime
Expand Down Expand Up @@ -140,8 +140,8 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
int rank = items.Rank;
int index;
object value;

if (items.IsReadOnly)
if (((IList)items).IsReadOnly)
{
Exceptions.RaiseTypeError("array is read-only");
return -1;
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/classbase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System;
using System.Collections;
using System.Runtime.InteropServices;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{
Expand All @@ -25,7 +26,7 @@ internal ClassBase(Type tp)

internal virtual bool CanSubclass()
{
return !type.IsEnum;
return !type.IsEnum();
}

/// <summary>
Expand Down
11 changes: 6 additions & 5 deletions src/runtime/classderived.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{
Expand Down Expand Up @@ -133,7 +134,7 @@ internal static Type CreateDerivedType(string name,

// if the base type is an interface then use System.Object as the base class
// and add the base type to the list of interfaces this new class will implement.
if (baseType.IsInterface)
if (baseType.IsInterface())
{
interfaces.Add(baseType);
baseClass = typeof(object);
Expand Down Expand Up @@ -309,7 +310,7 @@ private static void AddConstructor(ConstructorInfo ctor, Type baseType, TypeBuil
il.Emit(OpCodes.Ldloc_0);
il.Emit(OpCodes.Ldc_I4, i);
il.Emit(OpCodes.Ldarg, i + 1);
if (parameterTypes[i].IsValueType)
if (parameterTypes[i].IsValueType())
{
il.Emit(OpCodes.Box, parameterTypes[i]);
}
Expand Down Expand Up @@ -387,7 +388,7 @@ private static void AddVirtualMethod(MethodInfo method, Type baseType, TypeBuild
il.Emit(OpCodes.Ldloc_0);
il.Emit(OpCodes.Ldc_I4, i);
il.Emit(OpCodes.Ldarg, i + 1);
if (parameterTypes[i].IsValueType)
if (parameterTypes[i].IsValueType())
{
il.Emit(OpCodes.Box, parameterTypes[i]);
}
Expand Down Expand Up @@ -474,7 +475,7 @@ private static void AddPythonMethod(string methodName, PyObject func, TypeBuilde
il.Emit(OpCodes.Ldloc_0);
il.Emit(OpCodes.Ldc_I4, i);
il.Emit(OpCodes.Ldarg, i + 1);
if (argTypes[i].IsValueType)
if (argTypes[i].IsValueType())
{
il.Emit(OpCodes.Box, argTypes[i]);
}
Expand Down
20 changes: 17 additions & 3 deletions src/runtime/classmanager.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{
Expand Down Expand Up @@ -73,7 +74,11 @@ private static ClassBase CreateClass(Type type)
// lets us check once (vs. on every lookup) in case we need to
// wrap Exception-derived types in old-style classes

#if NETSTANDARD1_5
if (type.GetTypeInfo().ContainsGenericParameters)
#else
if (type.ContainsGenericParameters)
#endif
{
impl = new GenericType(type);
}
Expand All @@ -88,7 +93,7 @@ private static ClassBase CreateClass(Type type)
impl = new ArrayObject(type);
}

else if (type.IsInterface)
else if (type.IsInterface())
{
impl = new InterfaceObject(type);
}
Expand Down Expand Up @@ -236,7 +241,7 @@ private static ClassInfo GetClassInfo(Type type)
}
}

if (type.IsInterface)
if (type.IsInterface())
{
// Interface inheritance seems to be a different animal:
// more contractual, less structural. Thus, a Type that
Expand Down Expand Up @@ -358,12 +363,21 @@ private static ClassInfo GetClassInfo(Type type)
continue;

case MemberTypes.NestedType:
#if NETSTANDARD1_5
tp = ((TypeInfo) mi).AsType();
if (!(tp.IsNestedPublic() || tp.GetTypeInfo().IsNestedFamily ||
tp.GetTypeInfo().IsNestedFamORAssem))
{
continue;
}
#else
tp = (Type)mi;
if (!(tp.IsNestedPublic || tp.IsNestedFamily ||
tp.IsNestedFamORAssem))
{
continue;
}
#endif
// Note the given instance might be uninitialized
ob = GetClass(tp);
ci.members[mi.Name] = ob;
Expand Down
9 changes: 5 additions & 4 deletions src/runtime/classobject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Reflection;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{
Expand Down Expand Up @@ -65,7 +66,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
// Primitive types do not have constructors, but they look like
// they do from Python. If the ClassObject represents one of the
// convertible primitive types, just convert the arg directly.
if (type.IsPrimitive || type == typeof(string))
if (type.IsPrimitive() || type == typeof(string))
{
if (Runtime.PyTuple_Size(args) != 1)
{
Expand All @@ -84,13 +85,13 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw)
return CLRObject.GetInstHandle(result, tp);
}

if (type.IsAbstract)
if (type.IsAbstract())
{
Exceptions.SetError(Exceptions.TypeError, "cannot instantiate abstract class");
return IntPtr.Zero;
}

if (type.IsEnum)
if (type.IsEnum())
{
Exceptions.SetError(Exceptions.TypeError, "cannot instantiate enumeration");
return IntPtr.Zero;
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/constructorbinder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Reflection;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{
Expand Down Expand Up @@ -51,8 +52,8 @@ internal object InvokeRaw(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info)
{
object result;

if (_containingType.IsValueType && !_containingType.IsPrimitive &&
!_containingType.IsEnum && _containingType != typeof(decimal) &&
if (_containingType.IsValueType() && !_containingType.IsPrimitive() &&
!_containingType.IsEnum() && _containingType != typeof(decimal) &&
Runtime.PyTuple_Size(args) == 0)
{
// If you are trying to construct an instance of a struct by
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{
Expand Down Expand Up @@ -136,7 +137,7 @@ internal static IntPtr ToPython(object value, Type type)
return result;
}

if (value is IList && value.GetType().IsGenericType)
if (value is IList && value.GetType().IsGenericType())
{
using (var resultlist = new PyList())
{
Expand Down Expand Up @@ -314,7 +315,7 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
return false;
}

if (value == Runtime.PyNone && !obType.IsValueType)
if (value == Runtime.PyNone && !obType.IsValueType())
{
result = null;
return true;
Expand All @@ -325,7 +326,7 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
return ToArray(value, obType, out result, setError);
}

if (obType.IsEnum)
if (obType.IsEnum())
{
return ToEnum(value, obType, out result, setError);
}
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/delegatemanager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{
Expand Down Expand Up @@ -118,7 +119,7 @@ private Type GetDispatcher(Type dtype)
il.Emit(OpCodes.Ldloc_0);
il.Emit(OpCodes.Ldarg_S, (byte)(c + 1));

if (t.IsValueType)
if (t.IsValueType())
{
il.Emit(OpCodes.Box, t);
}
Expand All @@ -135,7 +136,7 @@ private Type GetDispatcher(Type dtype)
{
il.Emit(OpCodes.Pop);
}
else if (method.ReturnType.IsValueType)
else if (method.ReturnType.IsValueType())
{
il.Emit(OpCodes.Unbox_Any, method.ReturnType);
}
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/genericutil.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/interop.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -342,7 +342,11 @@ static Interop()
// Here we build a mapping of PyTypeObject slot names to the
// appropriate prototype (delegate) type to use for the slot.

#if NETSTANDARD1_5
Type[] items = typeof(Interop).GetTypeInfo().GetNestedTypes();
#else
Type[] items = typeof(Interop).GetNestedTypes();
#endif
Hashtable p = new Hashtable();

for (int i = 0; i < items.Length; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/metatype.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;

namespace Python.Runtime
Expand Down
9 changes: 5 additions & 4 deletions src/runtime/moduleobject.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{
Expand Down Expand Up @@ -108,7 +109,7 @@ public ManagedType GetAttribute(string name, bool guess)
type = AssemblyManager.LookupType(qname);
if (type != null)
{
if (!type.IsPublic)
if (!type.IsPublic())
{
return null;
}
Expand All @@ -134,7 +135,7 @@ public ManagedType GetAttribute(string name, bool guess)
type = AssemblyManager.LookupType(qname);
if (type != null)
{
if (!type.IsPublic)
if (!type.IsPublic())
{
return null;
}
Expand Down Expand Up @@ -238,7 +239,7 @@ internal void InitializeModuleMembers()
StoreAttribute(name, p);
}
}
type = type.BaseType;
type = type.BaseType();
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/runtime/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ReflectionBridge" version="0.0.11" targetFramework="net40" />
</packages>
Loading