public void Add(string key, object value) { if (value == null) { return; } if (value is string stringValue) { StringProperties.Add(key, stringValue); } else if (value is byte[] binaryValue) { BinaryProperties.Add(key, binaryValue); } else if (value is bool boolValue) { BooleanProperties.Add(key, boolValue); } else if (value is DateTimeOffset dateTimeOffsetValue) { DateTimeProperties.Add(key, dateTimeOffsetValue); } else if (value is DateTime dateTimeValue) { DateTimeProperties.Add(key, dateTimeValue); } else { IntegerProperties.Add(key, Convert.ToInt64(value)); } }
public bool TryGetProperty <T>(string key, out T value) { if (IntegerProperties.TryGetValue(key, out var val)) { value = (T)Convert.ChangeType(val, typeof(T)); return(true); } if (StringProperties.TryGetValue(key, out var stringVal)) { value = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(stringVal); return(true); } value = default; return(false); }
public bool TryGetProperty(string key, out long value) { return(IntegerProperties.TryGetValue(key, out value)); }
private ControlProperties CreateProperties(PropertyType type, PropertyInfo info, ExposePropertyAttribute attribute) { ControlProperties control = null; switch (type) { case PropertyType.AnimationCurve: control = new AnimationCurveProperties(this, info, attribute); break; case PropertyType.Boolean: control = new BooleanProperties(this, info, attribute); break; case PropertyType.Bounds: control = new BoundsProperties(this, info, attribute); break; case PropertyType.Color: control = new ColorProperties(this, info, attribute); break; case PropertyType.Enum: control = new EnumProperties(this, info, attribute); break; case PropertyType.Float: control = new FloatProperties(this, info, attribute); break; case PropertyType.Integer: control = new IntegerProperties(this, info, attribute); break; case PropertyType.LayerMask: control = new LayerMaskProperties(this, info, attribute); break; case PropertyType.ObjectReference: control = new UnityObjectProperties(this, info, attribute); break; case PropertyType.Quaternion: control = new QuaternionProperties(this, info, attribute); break; case PropertyType.Rect: control = new RectProperties(this, info, attribute); break; case PropertyType.String: control = new StringProperties(this, info, attribute); break; case PropertyType.Vector2: control = new Vector2Properties(this, info, attribute); break; case PropertyType.Vector3: control = new Vector3Properties(this, info, attribute); break; case PropertyType.Vector4: control = new Vector4Properties(this, info, attribute); break; case PropertyType.SerializableObject: control = new SerializableObjectProperties(this, info, attribute); break; case PropertyType.Array: control = new ArrayProperties(this, info, attribute); break; } if (control != null) { var margin = control.Control.Margin; margin.Left += 2; margin.Top += 2; margin.Bottom += 2; control.Control.Margin = margin; } return(control); }