示例#1
0
        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);
        }
示例#2
0
 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;
 }
示例#3
0
		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;
		}
示例#4
0
 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);
 }
示例#5
0
 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);
 }
示例#6
0
		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;
		}
示例#7
0
        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);
        }
示例#8
0
        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));
        }
示例#9
0
 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);
 }
示例#10
0
		private ReflectConstructorSpec(TernaryBool canBeInstantiated)
		{
			_canBeInstantiated = canBeInstantiated;
			_constructor = null;
		}
示例#11
0
		public ReflectConstructorSpec(IReflectConstructor constructor, object[] args)
		{
			_constructor = constructor;
			_args = args;
			_canBeInstantiated = TernaryBool.Yes;
		}
示例#12
0
 private ReflectConstructorSpec(TernaryBool canBeInstantiated)
 {
     _canBeInstantiated = canBeInstantiated;
     _constructor       = null;
 }
示例#13
0
 public ReflectConstructorSpec(IReflectConstructor constructor, object[] args)
 {
     _constructor       = constructor;
     _args              = args;
     _canBeInstantiated = TernaryBool.Yes;
 }