コード例 #1
0
 public void AddProperty(BasePropertyChanger propertyChanger)
 {
     InitializePropertyVars();
     RemoveExistingProperty(propertyChanger.FullPropertyPath);
     properties.Add(propertyChanger);
     Props.Add(propertyChanger.ToPropertyChangerDto());
 }
コード例 #2
0
            public static void Modify(object instance, string propertyName, object value, bool logDetails = false)
            {
                Log.Debug($"Modify - {propertyName} to {value}");
                PropertyModDetails propertyModDetails = BasePropertyChanger.GetPropertyModDetails(instance, propertyName, logDetails);

                if (propertyModDetails == null || !propertyModDetails.Found)
                {
                    if (logDetails)
                    {
                        Log.Error($"{propertyName} not found in instance.");
                    }
                    return;
                }
                BasePropertyChanger propertyChanger = PropertyChangerFactory.CreateFromModDetails(propertyModDetails, logDetails);

                if (propertyChanger != null)
                {
                    propertyChanger.ValueOverride = value;
                    propertyChanger.ModifyPropertyWithDetails(propertyModDetails);
                }
                else if (logDetails)
                {
                    if (propertyModDetails.attachedPropertyType != null)
                    {
                        Log.Error($"propertyChanger ({propertyName} to {value} of type {propertyModDetails.attachedPropertyType.Name}) is null!");
                    }
                    else
                    {
                        Log.Error($"propertyChanger ({propertyName} to {value}) is null!");
                    }
                }
            }
コード例 #3
0
 public void SetValue(BasePropertyChanger propertyChanger)
 {
     if (property != null)
     {
         property.SetValue(instance, propertyChanger.GetValue());
     }
     else if (field != null)
     {
         field.SetValue(instance, propertyChanger.GetValue());
     }
     else
     {
         propertyChanger.TrySetProperty(instance, attachedPropertyName);
     }
 }
コード例 #4
0
        public static BasePropertyChanger CreateFromModDetails(PropertyModDetails propertyModDetails, bool logErrors = true)
        {
            Type propertyType = propertyModDetails.GetPropertyType();

            if (propertyType == null)
            {
                return(null);
            }
            BasePropertyChanger propertyChanger = CreateFromTypeName(propertyType.Name, logErrors);

            if (propertyChanger != null)
            {
                propertyChanger.FullPropertyPath = propertyModDetails.GetName();
            }
            return(propertyChanger);
        }
コード例 #5
0
        void RemoveExistingProperty(string name)
        {
            BasePropertyChanger propertyChanger = properties.FirstOrDefault(x => x.FullPropertyPath == name);

            if (propertyChanger != null)
            {
                properties.Remove(propertyChanger);
            }

            PropertyChangerDto propDto = Props.FirstOrDefault(y => y.FullPropertyPath == name);

            if (propDto != null)
            {
                Props.Remove(propDto);
            }
        }
コード例 #6
0
        /// <summary>
        /// Call after deserialization...
        /// </summary>
        public void RebuildProperties()
        {
            //Talespire.Log.Indent();
            //LogThis();

            if (Props != null)
            {
                properties = new List <BasePropertyChanger>();

                foreach (PropertyChangerDto propertyChangerDto in Props)
                {
                    if (string.IsNullOrWhiteSpace(propertyChangerDto.FullPropertyPath))
                    {
                        Talespire.Log.Error($"propertyChangerDto.FullPropertyPath for type {propertyChangerDto.Type} with value {propertyChangerDto.Value} is null or empty!");
                        continue;
                    }
                    Talespire.Log.Debug($"{propertyChangerDto.FullPropertyPath}: {propertyChangerDto.Type};");
                    BasePropertyChanger changer = PropertyChangerFactory.CreateFrom(propertyChangerDto);
                    if (changer != null)
                    {
                        Talespire.Log.Debug($"Found property changer ({propertyChangerDto.Type})!");
                        changer.FullPropertyPath = propertyChangerDto.FullPropertyPath;
                        changer.Value            = propertyChangerDto.Value;
                        properties.Add(changer);
                    }
                }
            }

            if (Children != null)
            {
                foreach (CompositeEffect compositeEffect in Children)
                {
                    compositeEffect.RebuildProperties();
                }
            }

            //Talespire.Log.Unindent();
        }