Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 /// <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));
 }