Skip to content

Commit e4ad620

Browse files
author
dse
committed
ReflectionBridge extension sources injected. Build fix.
1 parent 4875302 commit e4ad620

File tree

5 files changed

+258
-15
lines changed

5 files changed

+258
-15
lines changed

src/runtime/Python.Runtime.15.csproj

+1-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</PropertyGroup>
3535

3636
<PropertyGroup>
37-
<DefineConstants>$(DefineConstants);PYTHON3; PYTHON35</DefineConstants>
37+
<DefineConstants>$(DefineConstants);REFLECTIONBRIDGE;PYTHON3;PYTHON35</DefineConstants>
3838
</PropertyGroup>
3939

4040
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.5'">
@@ -69,9 +69,4 @@
6969
<Version>4.0.0</Version>
7070
</PackageReference>
7171
</ItemGroup>
72-
73-
<ItemGroup>
74-
<PackageReference Include="ReflectionBridge" Version="0.0.11" />
75-
</ItemGroup>
76-
7772
</Project>

src/runtime/Python.Runtime.csproj

+4-5
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,10 @@
7171
<DebugType>full</DebugType>
7272
</PropertyGroup>
7373
<ItemGroup>
74-
<Reference Include="ReflectionBridge, Version=0.0.11.0, Culture=neutral, processorArchitecture=MSIL">
75-
<HintPath>..\..\packages\ReflectionBridge.0.0.11\lib\net40\ReflectionBridge.dll</HintPath>
76-
<Private>True</Private>
77-
</Reference>
7874
<Reference Include="System" />
7975
</ItemGroup>
8076
<ItemGroup>
77+
<Compile Include="polyfill\ReflectionBridge\ReflectionBridgeExtensions.cs" />
8178
<Compile Include="Properties\AssemblyInfo.cs" />
8279
<Compile Include="..\SharedAssemblyInfo.cs">
8380
<Link>Properties\SharedAssemblyInfo.cs</Link>
@@ -152,13 +149,15 @@
152149
</ItemGroup>
153150
<ItemGroup>
154151
<None Include="..\pythonnet.snk" />
155-
<None Include="packages.config" />
156152
</ItemGroup>
157153
<ItemGroup>
158154
<EmbeddedResource Include="resources\clr.py">
159155
<LogicalName>clr.py</LogicalName>
160156
</EmbeddedResource>
161157
</ItemGroup>
158+
<ItemGroup>
159+
<Content Include="polyfill\ReflectionBridge\LICENSE.txt" />
160+
</ItemGroup>
162161
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
163162
<PropertyGroup>
164163
<TargetAssembly>$(TargetPath)</TargetAssembly>

src/runtime/packages.config

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+

2+
MIT License
3+
4+
Copyright (c) 2016 to 2099 Stef Heyenrath
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
using System;
2+
using System.Reflection;
3+
4+
#if REFLECTIONBRIDGE
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
#endif
8+
9+
namespace ReflectionBridge.Extensions
10+
{
11+
public static class ReflectionBridgeExtensions
12+
{
13+
public static Assembly GetAssembly(this Type type)
14+
{
15+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
16+
return type.GetTypeInfo().Assembly;
17+
#else
18+
return type.Assembly;
19+
#endif
20+
}
21+
22+
public static bool IsSealed(this Type type)
23+
{
24+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
25+
return type.GetTypeInfo().IsSealed;
26+
#else
27+
return type.IsSealed;
28+
#endif
29+
}
30+
31+
public static bool IsAbstract(this Type type)
32+
{
33+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
34+
return type.GetTypeInfo().IsAbstract;
35+
#else
36+
return type.IsAbstract;
37+
#endif
38+
}
39+
40+
public static bool IsEnum(this Type type)
41+
{
42+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
43+
return type.GetTypeInfo().IsEnum;
44+
#else
45+
return type.IsEnum;
46+
#endif
47+
}
48+
49+
public static bool IsClass(this Type type)
50+
{
51+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
52+
return type.GetTypeInfo().IsClass;
53+
#else
54+
return type.IsClass;
55+
#endif
56+
}
57+
58+
public static bool IsPrimitive(this Type type)
59+
{
60+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
61+
return type.GetTypeInfo().IsPrimitive;
62+
#else
63+
return type.IsPrimitive;
64+
#endif
65+
}
66+
67+
public static bool IsPublic(this Type type)
68+
{
69+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
70+
return type.GetTypeInfo().IsPublic;
71+
#else
72+
return type.IsPublic;
73+
#endif
74+
}
75+
76+
public static bool IsNestedPublic(this Type type)
77+
{
78+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
79+
return type.GetTypeInfo().IsNestedPublic;
80+
#else
81+
return type.IsNestedPublic;
82+
#endif
83+
}
84+
85+
public static bool IsFromLocalAssembly(this Type type)
86+
{
87+
#if SILVERLIGHT
88+
string assemblyName = type.GetAssembly().FullName;
89+
#else
90+
string assemblyName = type.GetAssembly().GetName().Name;
91+
#endif
92+
93+
try
94+
{
95+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
96+
Assembly.Load(new AssemblyName { Name = assemblyName });
97+
#else
98+
Assembly.Load(assemblyName);
99+
#endif
100+
return true;
101+
}
102+
catch
103+
{
104+
return false;
105+
}
106+
}
107+
108+
public static bool IsGenericType(this Type type)
109+
{
110+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
111+
return type.GetTypeInfo().IsGenericType;
112+
#else
113+
return type.IsGenericType;
114+
#endif
115+
}
116+
117+
public static bool IsInterface(this Type type)
118+
{
119+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
120+
return type.GetTypeInfo().IsInterface;
121+
#else
122+
return type.IsInterface;
123+
#endif
124+
}
125+
126+
public static Type BaseType(this Type type)
127+
{
128+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
129+
return type.GetTypeInfo().BaseType;
130+
#else
131+
return type.BaseType;
132+
#endif
133+
}
134+
135+
public static bool IsValueType(this Type type)
136+
{
137+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
138+
return type.GetTypeInfo().IsValueType;
139+
#else
140+
return type.IsValueType;
141+
#endif
142+
}
143+
144+
public static T GetPropertyValue<T>(this Type type, string propertyName, object target)
145+
{
146+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
147+
PropertyInfo property = type.GetTypeInfo().GetDeclaredProperty(propertyName);
148+
return (T)property.GetValue(target);
149+
#else
150+
return (T)type.InvokeMember(propertyName, BindingFlags.GetProperty, null, target, null);
151+
#endif
152+
}
153+
154+
public static void SetPropertyValue(this Type type, string propertyName, object target, object value)
155+
{
156+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
157+
PropertyInfo property = type.GetTypeInfo().GetDeclaredProperty(propertyName);
158+
property.SetValue(target, value);
159+
#else
160+
type.InvokeMember(propertyName, BindingFlags.SetProperty, null, target, new object[] { value });
161+
#endif
162+
}
163+
164+
public static void SetFieldValue(this Type type, string fieldName, object target, object value)
165+
{
166+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
167+
FieldInfo field = type.GetTypeInfo().GetDeclaredField(fieldName);
168+
if (field != null)
169+
{
170+
field.SetValue(target, value);
171+
}
172+
else
173+
{
174+
type.SetPropertyValue(fieldName, target, value);
175+
}
176+
#else
177+
type.InvokeMember(fieldName, BindingFlags.SetField | BindingFlags.SetProperty, null, target, new object[] { value });
178+
#endif
179+
}
180+
181+
public static void InvokeMethod<T>(this Type type, string methodName, object target, T value)
182+
{
183+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
184+
MethodInfo method = type.GetTypeInfo().GetDeclaredMethod(methodName);
185+
method.Invoke(target, new object[] { value });
186+
#else
187+
type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, target, new object[] { value });
188+
#endif
189+
}
190+
191+
#if REFLECTIONBRIDGE && (!(NET40 || NET35 || NET20 || SILVERLIGHT))
192+
public static IEnumerable<MethodInfo> GetMethods(this Type someType)
193+
{
194+
var t = someType;
195+
while (t != null)
196+
{
197+
var ti = t.GetTypeInfo();
198+
foreach (var m in ti.DeclaredMethods)
199+
yield return m;
200+
t = ti.BaseType;
201+
}
202+
}
203+
204+
public static Type[] GetGenericArguments(this Type type)
205+
{
206+
return type.GetTypeInfo().GenericTypeArguments;
207+
}
208+
209+
/*
210+
public static bool IsAssignableFrom(this Type type, Type otherType)
211+
{
212+
return type.GetTypeInfo().IsAssignableFrom(otherType.GetTypeInfo());
213+
}*/
214+
215+
public static bool IsSubclassOf(this Type type, Type c)
216+
{
217+
return type.GetTypeInfo().IsSubclassOf(c);
218+
}
219+
220+
public static Attribute[] GetCustomAttributes(this Type type)
221+
{
222+
return type.GetTypeInfo().GetCustomAttributes().ToArray();
223+
}
224+
225+
public static Attribute[] GetCustomAttributes(this Type type, Type attributeType, bool inherit)
226+
{
227+
return type.GetTypeInfo().GetCustomAttributes(attributeType, inherit).Cast<Attribute>().ToArray();
228+
}
229+
#endif
230+
}
231+
}

0 commit comments

Comments
 (0)