Permalink
Browse files

Move to dotnet5.2

  • Loading branch information...
1 parent 44326df commit 829c12ed6084172b7b3d77db068252727800d4a2 @mgravell committed Nov 24, 2015
@@ -48,7 +48,8 @@
"dependencies": {
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-*",
- "System.Reflection.TypeExtensions": "4.0.1-*"
+ "System.Reflection.TypeExtensions": "4.0.1-*",
+ "System.Runtime": "4.0.21-*"
}
}
}
@@ -24,7 +24,7 @@
"System.Data": "4.0.0.0"
}
},
- "dotnet5.4": {
+ "dotnet5.2": {
"compilationOptions": {
"define": [ "COREFX" ]
},
@@ -39,7 +39,8 @@
"System.Reflection.Emit.ILGeneration": "4.0.1-*",
"System.Reflection.Emit.Lightweight": "4.0.1-*",
"System.Reflection.TypeExtensions": "4.1.0-*",
- "System.Runtime": "4.0.21-*"
+ "System.Runtime": "4.0.21-*",
+ "System.Threading": "4.0.11-*"
}
}
}
@@ -42,7 +42,8 @@
"dependencies": {
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-*",
- "System.Reflection.TypeExtensions": "4.0.1-*"
+ "System.Reflection.TypeExtensions": "4.0.1-*",
+ "System.Runtime": "4.0.21-*"
}
}
}
@@ -13,7 +13,7 @@ public sealed class MemberSet : IEnumerable<Member>, IList<Member>
Member[] members;
internal MemberSet(Type type)
{
- members = type.GetProperties().Cast<MemberInfo>().Concat(type.GetFields().Cast<MemberInfo>()).OrderBy(x => x.Name, StringComparer.Ordinal)
+ members = type.GetProperties().Cast<MemberInfo>().Concat(type.GetFields().Cast<MemberInfo>()).OrderBy(x => x.Name)
.Select(member => new Member(member)).ToArray();
}
/// <summary>
@@ -87,7 +87,11 @@ public bool IsDefined(Type attributeType)
{
if (attributeType == null) throw new ArgumentNullException("attributeType");
#if COREFX
- return member.IsDefined(attributeType);
+ foreach(var attrib in member.CustomAttributes)
+ {
+ if (attrib.AttributeType == attributeType) return true;
+ }
+ return false;
#else
return Attribute.IsDefined(member, attributeType);
#endif
@@ -218,7 +218,7 @@ public override long GetBytes(int i, long fieldOffset, byte[] buffer, int buffer
int available = s.Length - (int)fieldOffset;
if (available <= 0) return 0;
- int count = Math.Min(length, available);
+ int count = TypeHelpers.Min(length, available);
Buffer.BlockCopy(s, (int)fieldOffset, buffer, bufferoffset, count);
return count;
}
@@ -234,7 +234,7 @@ public override long GetChars(int i, long fieldoffset, char[] buffer, int buffer
int available = s.Length - (int)fieldoffset;
if (available <= 0) return 0;
- int count = Math.Min(length, available);
+ int count = TypeHelpers.Min(length, available);
s.CopyTo((int)fieldoffset, buffer, bufferoffset, count);
return count;
}
@@ -330,7 +330,7 @@ public override int GetValues(object[] values)
var current = this.current;
var accessor = this.accessor;
- int count = Math.Min(values.Length, members.Length);
+ int count = TypeHelpers.Min(values.Length, members.Length);
for (int i = 0; i < count; i++) values[i] = accessor[current, members[i]] ?? DBNull.Value;
return count;
}
@@ -18,8 +18,10 @@
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
+#if !COREFX
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("fa8f50b2-45ec-46ee-8c9f-f9794c37c237")]
+#endif
// Version information for an assembly consists of the following four values:
//
@@ -85,6 +85,21 @@ sealed class DynamicAccessor : TypeAccessor
private static ModuleBuilder module;
private static int counter;
+#if COREFX
+ private static readonly object counterLock = new object();
+#endif
+ private static int GetNextCounterValue()
+ {
+#if COREFX
+ lock(counterLock)
+ {
+ return counter++;
+ }
+#else
+ return Interlocked.Increment(ref counter);
+#endif
+ }
+
static readonly MethodInfo tryGetValue = typeof(Dictionary<string, int>).GetMethod("TryGetValue");
private static void WriteMapImpl(ILGenerator il, Type type, List<MemberInfo> members, FieldBuilder mapField, bool allowNonPublicAccessors, bool isGet)
{
@@ -265,7 +280,7 @@ static TypeAccessor CreateNew(Type type, bool allowNonPublicAccessors)
PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
- Dictionary<string, int> map = new Dictionary<string, int>(StringComparer.Ordinal);
+ Dictionary<string, int> map = new Dictionary<string, int>();
List<MemberInfo> members = new List<MemberInfo>(props.Length + fields.Length);
int i = 0;
foreach (var prop in props)
@@ -281,7 +296,7 @@ static TypeAccessor CreateNew(Type type, bool allowNonPublicAccessors)
ConstructorInfo ctor = null;
if (type._IsClass() && !type._IsAbstract())
{
- ctor = type.GetConstructor(Type.EmptyTypes);
+ ctor = type.GetConstructor(TypeHelpers.EmptyTypes);
}
ILGenerator il;
if (!IsFullyPublic(type, props, allowNonPublicAccessors))
@@ -293,7 +308,7 @@ static TypeAccessor CreateNew(Type type, bool allowNonPublicAccessors)
DynamicMethod dynCtor = null;
if (ctor != null)
{
- dynCtor = new DynamicMethod(type.FullName + "_ctor", typeof(object), Type.EmptyTypes, type, true);
+ dynCtor = new DynamicMethod(type.FullName + "_ctor", typeof(object), TypeHelpers.EmptyTypes, type, true);
il = dynCtor.GetILGenerator();
il.Emit(OpCodes.Newobj, ctor);
il.Emit(OpCodes.Ret);
@@ -321,7 +336,7 @@ static TypeAccessor CreateNew(Type type, bool allowNonPublicAccessors)
#else
TypeAttributes attribs = typeof(TypeAccessor).Attributes;
#endif
- TypeBuilder tb = module.DefineType("FastMember_dynamic." + type.Name + "_" + Interlocked.Increment(ref counter),
+ TypeBuilder tb = module.DefineType("FastMember_dynamic." + type.Name + "_" + GetNextCounterValue(),
(attribs | TypeAttributes.Sealed | TypeAttributes.Public) & ~(TypeAttributes.Abstract | TypeAttributes.NotPublic), typeof(RuntimeTypeAccessor));
il = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new[] {
@@ -350,22 +365,22 @@ static TypeAccessor CreateNew(Type type, bool allowNonPublicAccessors)
if (ctor != null)
{
baseMethod = typeof(TypeAccessor).GetProperty("CreateNewSupported").GetGetMethod();
- body = tb.DefineMethod(baseMethod.Name, baseMethod.Attributes, baseMethod.ReturnType, Type.EmptyTypes);
+ body = tb.DefineMethod(baseMethod.Name, baseMethod.Attributes, baseMethod.ReturnType, TypeHelpers.EmptyTypes);
il = body.GetILGenerator();
il.Emit(OpCodes.Ldc_I4_1);
il.Emit(OpCodes.Ret);
tb.DefineMethodOverride(body, baseMethod);
baseMethod = typeof(TypeAccessor).GetMethod("CreateNew");
- body = tb.DefineMethod(baseMethod.Name, baseMethod.Attributes, baseMethod.ReturnType, Type.EmptyTypes);
+ body = tb.DefineMethod(baseMethod.Name, baseMethod.Attributes, baseMethod.ReturnType, TypeHelpers.EmptyTypes);
il = body.GetILGenerator();
il.Emit(OpCodes.Newobj, ctor);
il.Emit(OpCodes.Ret);
tb.DefineMethodOverride(body, baseMethod);
}
baseMethod = typeof(RuntimeTypeAccessor).GetProperty("Type", BindingFlags.NonPublic | BindingFlags.Instance).GetGetMethod(true);
- body = tb.DefineMethod(baseMethod.Name, baseMethod.Attributes & ~MethodAttributes.Abstract, baseMethod.ReturnType, Type.EmptyTypes);
+ body = tb.DefineMethod(baseMethod.Name, baseMethod.Attributes & ~MethodAttributes.Abstract, baseMethod.ReturnType, TypeHelpers.EmptyTypes);
il = body.GetILGenerator();
il.Emit(OpCodes.Ldtoken, type);
il.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle"));
@@ -6,6 +6,12 @@ namespace FastMember
{
internal static class TypeHelpers
{
+#if COREFX
+ public static readonly Type[] EmptyTypes = new Type[0];
+#else
+ public static readonly Type[] EmptyTypes = Type.EmptyTypes;
+#endif
+
public static bool _IsValueType(this Type type)
{
#if COREFX
@@ -56,5 +62,10 @@ public static Type _CreateType(this TypeBuilder type)
return type.CreateType();
#endif
}
+
+ public static int Min(int x, int y)
+ {
+ return x < y ? x : y;
+ }
}
}
@@ -18,7 +18,7 @@
"System.Data": "4.0.0.0"
}
},
- "dotnet5.4": {
+ "dotnet5.2": {
"compilationOptions": {
"define": [ "COREFX" ]
},
@@ -33,7 +33,8 @@
"System.Reflection.Emit.ILGeneration": "4.0.1-*",
"System.Reflection.Emit.Lightweight": "4.0.1-*",
"System.Reflection.TypeExtensions": "4.1.0-*",
- "System.Runtime": "4.0.21-*"
+ "System.Runtime": "4.0.21-*",
+ "System.Threading": "4.0.11-*"
}
}
}
View
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+ <packageSources>
+ <clear />
+ <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
+ </packageSources>
+</configuration>

0 comments on commit 829c12e

Please sign in to comment.