public void SetFieldValue(object owner, object value = null, object definition = null) { if (Loading || owner == null) { return; } if (value == null) { if (!ValueControl.TryParseValue(CacheContext, Field.FieldType.GenericTypeArguments[0], lowerTextBox.Text, out var lower) || !ValueControl.TryParseValue(CacheContext, Field.FieldType.GenericTypeArguments[0], upperTextBox.Text, out var upper)) { return; } value = Activator.CreateInstance(Field.FieldType, new[] { lower, upper }); } Field.SetValue(owner, value); }
private Dictionary <string, IFieldControl> CreateFieldControls(CacheForm form, Control parent, FieldInfo field, Type type, bool toplevel) { Enabled = false; var result = new Dictionary <string, IFieldControl>(); var enumerator = TagStructure.GetTagFieldEnumerable(new TagStructureInfo(type, Cache.Version)); var currentLocation = new Point(parent is GroupBox ? 3 : 0, parent is GroupBox ? 16 : 0); foreach (var fieldInfo in enumerator) { if (fieldInfo.Attribute.Flags.HasFlag(TagFieldFlags.Padding)) { continue; } var fieldType = fieldInfo.FieldInfo.FieldType; var isFlagsEnum = (fieldType.GetCustomAttributes(typeof(FlagsAttribute), false).FirstOrDefault() as FlagsAttribute ?? null) != null; var isTagBlock = (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List <>)); var isStruct = (fieldType.GetCustomAttributes(typeof(TagStructureAttribute), false).FirstOrDefault() as TagStructureAttribute ?? null) != null; var isBounds = (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Bounds <>)); if (toplevel && (isStruct || isTagBlock)) { continue; } if (field != null && field != fieldInfo.FieldInfo) { continue; } Control control = null; if (fieldType == typeof(StringId)) { control = new StringIdControl(Cache, fieldInfo.FieldInfo); } else if (fieldType.IsEnum) { if (isFlagsEnum) { control = new FlagsControl(fieldInfo.FieldInfo); } else { control = new EnumControl(fieldInfo.FieldInfo); } } else if (fieldType == typeof(Point2d)) { control = new Point2dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(Rectangle2d)) { control = new Rectangle2dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(ArgbColor)) { control = new ArgbColorControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealPoint2d)) { control = new RealPoint2dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealPoint3d)) { control = new RealPoint3dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealVector2d)) { control = new RealVector2dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealVector3d)) { control = new RealVector3dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealQuaternion)) { control = new RealQuaternionControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealRgbColor)) { control = new RealRgbColorControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealArgbColor)) { control = new RealArgbColorControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealEulerAngles2d)) { control = new RealEulerAngles2dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealEulerAngles3d)) { control = new RealEulerAngles3dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealPlane2d)) { control = new RealPlane2dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(RealPlane3d)) { control = new RealPlane3dControl(Cache, fieldInfo.FieldInfo); } else if (fieldType == typeof(CachedTag)) { control = new TagReferenceControl(form, Cache, fieldInfo.FieldInfo); } else if (isTagBlock) { control = new BlockControl(form, Cache, fieldType, fieldInfo.FieldInfo); if (((BlockControl)control).Struct.FieldControls.Count == 0) { continue; } } else if (isStruct) { control = new StructControl(form, Cache, fieldType, fieldInfo.FieldInfo); if (((StructControl)control).FieldControls.Count == 0) { continue; } } else if (isBounds) { control = new BoundsControl(Cache, fieldInfo.FieldInfo); } else { control = new ValueControl(Cache, fieldInfo.FieldInfo); } control.Location = new Point(currentLocation.X, currentLocation.Y); parent.Controls.Add(control); currentLocation.Y = control.Bottom; if (parent is GroupBox gb && gb.AutoSize == false) { parent.Width = control.Right + 8; parent.Height = control.Bottom + 6; } if (isStruct || isTagBlock) { control.BringToFront(); } result[fieldInfo.FieldInfo.Name] = (IFieldControl)control; Application.DoEvents(); } Enabled = true; return(result); }