|
|
@@ -7,9 +7,9 @@ namespace Discord |
|
|
|
{ |
|
|
|
internal static class DynamicIL |
|
|
|
{ |
|
|
|
public static Action<T, T> CreateCloner<T>() |
|
|
|
public static Action<T, T> CreateCopyMethod<T>() |
|
|
|
{ |
|
|
|
var method = new DynamicMethod("CopyFields", null, new[] { typeof(T), typeof(T) }, typeof(T), true); |
|
|
|
var method = new DynamicMethod("CopyTo", null, new[] { typeof(T), typeof(T) }, typeof(T), true); |
|
|
|
var generator = method.GetILGenerator(); |
|
|
|
var typeInfo = typeof(T).GetTypeInfo(); |
|
|
|
|
|
|
@@ -26,14 +26,24 @@ namespace Discord |
|
|
|
return method.CreateDelegate(typeof(Action<T, T>)) as Action<T, T>; |
|
|
|
} |
|
|
|
|
|
|
|
public static void ForEachField(this TypeInfo typeInfo, Action<FieldInfo> fieldProcessor) |
|
|
|
public static void ForEachField(this TypeInfo typeInfo, Action<FieldInfo> func) |
|
|
|
{ |
|
|
|
var baseType = typeInfo.BaseType; |
|
|
|
if (baseType != null) |
|
|
|
ForEachField(baseType.GetTypeInfo(), fieldProcessor); |
|
|
|
baseType.GetTypeInfo().ForEachField(func); |
|
|
|
|
|
|
|
foreach (var field in typeInfo.DeclaredFields.Where(x => !x.IsStatic)) |
|
|
|
fieldProcessor(field); |
|
|
|
func(field); |
|
|
|
} |
|
|
|
public static void ForEachProperty(this TypeInfo typeInfo, Action<PropertyInfo> func) |
|
|
|
{ |
|
|
|
var baseType = typeInfo.BaseType; |
|
|
|
if (baseType != null) |
|
|
|
baseType.GetTypeInfo().ForEachProperty(func); |
|
|
|
|
|
|
|
foreach (var prop in typeInfo.DeclaredProperties.Where(x => |
|
|
|
(!x.CanRead || !x.GetMethod.IsStatic) && (!x.CanWrite || !x.SetMethod.IsStatic))) |
|
|
|
func(prop); |
|
|
|
} |
|
|
|
} |
|
|
|
} |