public override List <string> GetFields(System.Type type = null, List <string> preAlloc = null) { ListPool <string> .GetIfNull(ref preAlloc); // No target set? If so, return empty list if (!this.hasBoundType) { return(preAlloc); } // Special field - "This" if (object.ReferenceEquals(type, null) || type.IsAssignableFrom(this.boundType)) { preAlloc.Add("This"); } // Write fields var props = DataBindingFieldProperty.Get(this.boundType); for (int i = 0; i < props.Count; i++) { if (object.ReferenceEquals(type, null) || type.IsAssignableFrom(props[i].fieldType)) { preAlloc.Add(props[i].name); } } return(preAlloc); }
public void OnValidate() { this._type = null; this._field = null; this._isValid = !object.ReferenceEquals(this.GetTargetType(), null) && !object.ReferenceEquals(this.GetField(), null); }
/// <summary> /// Sets the target field of this template (<see cref="targetField"/>). /// This setter can be used to set the field via code rather than the unity inspector. /// </summary> public void SetTargetField(DataBindingFieldProperty fieldProperty) { if (fieldProperty.declaringType != this.GetTargetType()) { throw new InvalidOperationException("Cannot set target field of a generic templated leaf to a field property that was not declared on the template target."); } this.targetField = fieldProperty.name; }
public override void SetFieldValue(string field, object value) { object boundObject = this.boundObject; // Invoke getter once if (object.ReferenceEquals(boundObject, null)) { throw new NullReferenceException("Bound object is null, cannot set a field of null!"); } // Get field prop & set DataBindingFieldProperty fieldProperty = DataBindingFieldProperty.Get(boundObject.GetType(), field); fieldProperty.SetValue(boundObject, value); }
/// <summary> /// Returns the field this template binds to. /// </summary> public DataBindingFieldProperty GetField() { if (object.ReferenceEquals(this._field, null)) { var type = GetTargetType(); this._field = DataBindingFieldProperty.Get(type, this.targetField); if (object.ReferenceEquals(this._field, null)) { Debug.LogError("Couldnt find field " + this.targetField + " on type " + this.targetType + " ( " + type + " )"); } } return(this._field); }
public override Type GetFieldType(string field) { // Get bound type var type = this.boundType; if (type == null) { return(typeof(object)); } // Get field prop var fieldProp = DataBindingFieldProperty.Get(type, field); if (fieldProp == null) { return(typeof(object)); } return(fieldProp.fieldType); }
/// <summary> /// Cache element constructor for <see cref="fieldCache"/> /// </summary> private DataBindingFieldProperty CacheConstructor(string field) { return(DataBindingFieldProperty.Get(this.boundObject.GetType(), field)); }
public void SetTargetField(FieldInfo fieldInfo) { SetTargetField(DataBindingFieldProperty.Get(fieldInfo)); }
public void SetTargetField(PropertyInfo propertyInfo) { SetTargetField(DataBindingFieldProperty.Get(propertyInfo)); }