public static IReflectConstructor SkipConstructor(IConstructorAwareReflectClass claxx , bool skipConstructor, bool testConstructor) { if (!skipConstructor) { return(null); } IReflectConstructor serializableConstructor = claxx.GetSerializableConstructor(); if (serializableConstructor == null) { return(null); } if (!testConstructor || Deploy.csharp) { return(serializableConstructor); } object obj = serializableConstructor.NewInstance((object[])null); if (obj != null) { return(serializableConstructor); } return(null); }
private static object[] NullArgumentsFor(IReflectConstructor constructor) { var paramTypes = constructor.GetParameterTypes(); var @params = new object[paramTypes.Length]; for (var j = 0; j < @params.Length; j++) { @params[j] = paramTypes[j].NullValue(); } return @params; }
private IReflectConstructor[] GetDeclaredConstructors() { ConstructorInfo[] constructors = _type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); IReflectConstructor[] reflectors = new IReflectConstructor[constructors.Length]; for (int i = 0; i < constructors.Length; i++) { reflectors[i] = new NetConstructor(_reflector, constructors[i]); } return reflectors; }
private IReflectConstructor[] GetDeclaredConstructors() { ConstructorInfo[] constructors = _type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); IReflectConstructor[] reflectors = new IReflectConstructor[constructors.Length]; for (int i = 0; i < constructors.Length; i++) { reflectors[i] = new NetConstructor(_reflector, constructors[i]); } return(reflectors); }
private static object[] NullArgumentsFor(IReflectConstructor constructor) { IReflectClass[] paramTypes = constructor.GetParameterTypes(); object[] @params = new object[paramTypes.Length]; for (int j = 0; j < @params.Length; j++) { @params[j] = paramTypes[j].NullValue(); } return(@params); }
private static Tree SortConstructorsByParamsCount(IReflectConstructor[] constructors ) { Tree sortedConstructors = null; // sort constructors by parameter count for (int i = 0; i < constructors.Length; i++) { int parameterCount = constructors[i].GetParameterTypes().Length; sortedConstructors = Tree.Add(sortedConstructors, new TreeIntObject(i + constructors .Length * parameterCount, constructors[i])); } return sortedConstructors; }
private static ReflectConstructorSpec FindConstructor(IReflectClass claxx, Tree sortedConstructors ) { if (sortedConstructors == null) { return(ReflectConstructorSpec.InvalidConstructor); } IEnumerator iter = new TreeNodeIterator(sortedConstructors); while (iter.MoveNext()) { object current = iter.Current; IReflectConstructor constructor = (IReflectConstructor)((TreeIntObject)current)._object; object[] args = NullArgumentsFor(constructor); object res = constructor.NewInstance(args); if (res != null) { return(new ReflectConstructorSpec(constructor, args)); } } return(ReflectConstructorSpec.InvalidConstructor); }
public static ReflectConstructorSpec CreateConstructor(IConstructorAwareReflectClass claxx, Type clazz, IReflectorConfiguration config, IReflectConstructor[] constructors ) { if (claxx == null) { return(ReflectConstructorSpec.InvalidConstructor); } if (claxx.IsAbstract() || claxx.IsInterface()) { return(ReflectConstructorSpec.InvalidConstructor); } if (!Platform4.CallConstructor()) { bool skipConstructor = !config.CallConstructor(claxx); if (!claxx.IsCollection()) { IReflectConstructor serializableConstructor = SkipConstructor(claxx, skipConstructor , config.TestConstructors()); if (serializableConstructor != null) { return(new ReflectConstructorSpec(serializableConstructor, null)); } } } if (!config.TestConstructors()) { return(new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null)); } if (ReflectPlatform.CreateInstance(clazz) != null) { return(new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null)); } Tree sortedConstructors = SortConstructorsByParamsCount(constructors); return(FindConstructor(claxx, sortedConstructors)); }
public static ReflectConstructorSpec CreateConstructor(IConstructorAwareReflectClass claxx, Type clazz, IReflectorConfiguration config, IReflectConstructor[] constructors ) { if (claxx == null) { return ReflectConstructorSpec.InvalidConstructor; } if (claxx.IsAbstract() || claxx.IsInterface()) { return ReflectConstructorSpec.InvalidConstructor; } if (!Platform4.CallConstructor()) { var skipConstructor = !config.CallConstructor(claxx); if (!claxx.IsCollection()) { var serializableConstructor = SkipConstructor(claxx, skipConstructor , config.TestConstructors()); if (serializableConstructor != null) { return new ReflectConstructorSpec(serializableConstructor, null); } } } if (!config.TestConstructors()) { return new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null); } if (ReflectPlatform.CreateInstance(clazz) != null) { return new ReflectConstructorSpec(new PlatformReflectConstructor(clazz), null); } var sortedConstructors = SortConstructorsByParamsCount(constructors); return FindConstructor(claxx, sortedConstructors); }
private ReflectConstructorSpec(TernaryBool canBeInstantiated) { _canBeInstantiated = canBeInstantiated; _constructor = null; }
public ReflectConstructorSpec(IReflectConstructor constructor, object[] args) { _constructor = constructor; _args = args; _canBeInstantiated = TernaryBool.Yes; }
private ReflectConstructorSpec(TernaryBool canBeInstantiated) { _canBeInstantiated = canBeInstantiated; _constructor = null; }
public ReflectConstructorSpec(IReflectConstructor constructor, object[] args) { _constructor = constructor; _args = args; _canBeInstantiated = TernaryBool.Yes; }