public object Generate(Type t) { object tmp = Activator.CreateInstance(typeof(List <>).MakeGenericType(t)); ((IList)tmp).Add(FieldValueGenerator.GenerateValue(t)); return(tmp); }
private object CreateByConstructor(Type t, ConstructorInfo info) { //temp object for infoking constructor object[] tmp = new object[info.GetParameters().Length]; int i = 0; //fill in object foreach (ParameterInfo pi in info.GetParameters()) { tmp[i] = FieldValueGenerator.GenerateValue(pi.ParameterType); i++; } return(info.Invoke(tmp)); }
private object CreateByPublicFields(Type t) { //NEED TO ADD CHECH ON ONLY GET-PROPERTIES object tmp = Activator.CreateInstance(t); //get public fields FieldInfo[] fieldInfo = t.GetFields(BindingFlags.Public | BindingFlags.Instance); PropertyInfo[] propertyInfo = t.GetProperties(BindingFlags.Public | BindingFlags.Instance); //setting values to public fields foreach (FieldInfo info in fieldInfo) { info.SetValue(tmp, FieldValueGenerator.GenerateValue(info.FieldType)); } foreach (PropertyInfo info in propertyInfo) { info.SetValue(tmp, FieldValueGenerator.GenerateValue(info.PropertyType)); } return(tmp); }