Exemple #1
0
        public object CreateByConstructor(ConstructorInfo constructor)
        {
            List <ParameterInfo> parameters = ParametersInfoProcessor.GetParametersInfo(constructor);

            object[] tmpParams = new object[parameters.Count];
            int      i         = 0;

            foreach (ParameterInfo parameterInfo in parameters)
            {
                tmpParams[i] = ParameterGenerator.Generate(parameterInfo.ParameterType);
                i++;
            }
            return(constructor.Invoke(tmpParams));
        }
Exemple #2
0
        public object CreateByFieldsAndProperties(Type t)
        {
            object              res                = Activator.CreateInstance(t);
            List <FieldInfo>    fields             = ClassInfo.GetClassFieldsInfo(t);
            List <PropertyInfo> settableProperties = PropertiesInfoProcessor.GetSettableProperties(ClassInfo.GetClassPropertiesInfo(t));

            foreach (FieldInfo field in fields)
            {
                field.SetValue(res, ParameterGenerator.Generate(field.FieldType));
            }

            foreach (PropertyInfo property in settableProperties)
            {
                property.SetValue(res, ParameterGenerator.Generate(property.PropertyType));
            }

            return(res);
        }