Remove methods for constructor in ReflectionHelper
.
This commit is contained in:
@@ -13,7 +13,7 @@ namespace Cryville.Common {
|
||||
public static Binder CreateBinderOfType(Type type) {
|
||||
var l = type.GetCustomAttributes(typeof(BinderAttribute), true);
|
||||
if (l.Length > 0) {
|
||||
return (Binder)ReflectionHelper.InvokeEmptyConstructor(
|
||||
return (Binder)Activator.CreateInstance(
|
||||
((BinderAttribute)l[0]).BinderType
|
||||
);
|
||||
}
|
||||
|
@@ -228,7 +228,7 @@ namespace Cryville.Common.Pdt {
|
||||
if (!flag) throw new FormatException("Format directive not found");
|
||||
}
|
||||
object InterpretObject(Type type) {
|
||||
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
||||
var result = Activator.CreateInstance(type);
|
||||
bool pcflag = PairCollection.IsPairCollection(type);
|
||||
while (true) {
|
||||
try { ws(); }
|
||||
|
@@ -8,24 +8,7 @@ namespace Cryville.Common {
|
||||
/// Provides a set of <see langword="static" /> methods for refletion.
|
||||
/// </summary>
|
||||
public static class ReflectionHelper {
|
||||
static readonly Type[] emptyTypeArray = {};
|
||||
/// <summary>
|
||||
/// Gets the parameterless constructor of a type.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>The parameterless constructor of the type.</returns>
|
||||
public static ConstructorInfo GetEmptyConstructor(Type type) {
|
||||
return type.GetConstructor(emptyTypeArray);
|
||||
}
|
||||
static readonly object[] emptyObjectArray = {};
|
||||
/// <summary>
|
||||
/// Invokes the parameterless constructor of a type and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>The created instance.</returns>
|
||||
public static object InvokeEmptyConstructor(Type type) {
|
||||
return GetEmptyConstructor(type).Invoke(emptyObjectArray);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find a member with the specified attribute type in a type.
|
||||
|
@@ -17,7 +17,7 @@ namespace Cryville.Common.Unity.Input {
|
||||
foreach (var t in HandlerRegistries) {
|
||||
try {
|
||||
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
|
||||
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
|
||||
var h = (InputHandler)Activator.CreateInstance(t);
|
||||
_typemap.Add(t, h);
|
||||
_handlers.Add(h);
|
||||
Logger.Log("main", 1, "Input", "Initialized {0}", ReflectionHelper.GetSimpleName(t));
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Buffers;
|
||||
using Cryville.Common.Collections.Specialized;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Crtr.Event {
|
||||
@@ -20,7 +21,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
protected override MotionCache Construct() {
|
||||
var result = new MotionCache();
|
||||
result.Value = (Vector)ReflectionHelper.InvokeEmptyConstructor(_reg.Type);
|
||||
result.Value = (Vector)Activator.CreateInstance(_reg.Type);
|
||||
return result;
|
||||
}
|
||||
protected override void Reset(MotionCache obj) {
|
||||
|
@@ -26,7 +26,7 @@ namespace Cryville.Crtr {
|
||||
[Obsolete]
|
||||
public static class MotionLerper {
|
||||
public static void Lerp<T>(double time, double tt, T tv, double ft, T fv, TransitionType type, float rate, ref T result) where T : Vector {
|
||||
if (fv == null) fv = (T)ReflectionHelper.InvokeEmptyConstructor(tv.GetType());
|
||||
if (fv == null) fv = (T)Activator.CreateInstance(tv.GetType());
|
||||
Lerp((float)((time - ft) / (tt - ft)), fv, tv, type, rate, ref result);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Cryville.Crtr {
|
||||
get { return m_GlobalInitValue.Clone(); }
|
||||
}
|
||||
|
||||
public MotionRegistry(Type type) : this((Vector)ReflectionHelper.InvokeEmptyConstructor(type)) { }
|
||||
public MotionRegistry(Type type) : this((Vector)Activator.CreateInstance(type)) { }
|
||||
|
||||
public MotionRegistry(Vector init) : this(init, init) { }
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace Cryville.Crtr {
|
||||
Value = init
|
||||
}
|
||||
};
|
||||
AbsoluteValue = (Vector)ReflectionHelper.InvokeEmptyConstructor(init.GetType());
|
||||
AbsoluteValue = (Vector)Activator.CreateInstance(init.GetType());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ namespace Cryville.Crtr {
|
||||
Id = node.Id,
|
||||
Time = new Vec1(0),
|
||||
Rate = new Vec1(1),
|
||||
Value = (Vector)ReflectionHelper.InvokeEmptyConstructor(node.Value.GetType())
|
||||
Value = (Vector)Activator.CreateInstance(node.Value.GetType())
|
||||
};
|
||||
}
|
||||
else {
|
||||
|
Reference in New Issue
Block a user