/// <summary> /// Return list of names of different properties. /// </summary> /// <param name="preset"></param> /// <returns></returns> public string[] Compare(Preset preset) { List<string> list = new List<string>(); PropertyInfo[] properties = this.GetType().GetProperties(); PropertyInfo property; object thisValue; object presetValue; for (int i = 0; i < properties.Length; i++) { property = properties[i]; Type type = property.PropertyType; if (!type.IsPublic) continue; thisValue = property.GetValue(this, null); presetValue = property.GetValue(preset, null); if (type == typeof(bool) && (bool)thisValue != (bool)presetValue) { list.Add(property.Name); } if (type == typeof(string) && (string)thisValue != (string)presetValue) { list.Add(property.Name); } } FieldInfo[] fields = this.GetType().GetFields(BindingFlags.Public); FieldInfo field; for (int i = 0; i < fields.Length; i++) { field = fields[i]; Type type = field.FieldType; if (!type.IsPublic) continue; thisValue = field.GetValue(this); presetValue = field.GetValue(preset); if (type == typeof(bool) && (bool)thisValue != (bool)presetValue) { list.Add(field.Name); } if (type == typeof(string) && (string)thisValue != (string)presetValue) { list.Add(field.Name); } } return list.ToArray(); }
/// <summary> /// Creates a copy of Preset with same values. /// </summary> /// <returns>Copy of this Preset with same values.</returns> public Preset Copy() { Preset preset = new Preset(); JocysCom.ClassLibrary.Runtime.Helper.CopyProperties(this, preset); return preset; }
/// <summary> /// /// </summary> /// <remarks> /// Password is generated in these steps: /// a) Load array of chars according to presets; /// b) Apply filters; /// c) Proceed until password length is reached; /// d) Apply Regular Expressions; /// </remarks> public Generator() { // Preconfigure generator with default preset; Preset = new Preset(PresetName.DefaultEasyToEnter); }