Exemplo n.º 1
0
    public BindableProperty(PropertyDefinition property)
    {
        Property     = property;
        PropertyType = property.Module.ImportReference(property.PropertyType);
        BackingField = property.DeclaringType.Fields.SingleOrDefault(f => f.Name == $"<{property.Name}>k__BackingField");

        var attribute = property.GetAttribute(WeaverConstants.BindableAttribute);

        BindingMode = attribute.GetValue(WeaverConstants.BindingMode, XFBindingMode.OneWay);

        var typeSystem = property.Module.TypeSystem;

        ValidateValueMethod = ResolveMethod(attribute.GetValue <string>(WeaverConstants.OnValidateValue), $"OnValidate{property.Name}Value",
                                            typeSystem.Boolean,
                                            WeaverTypes.BindableObject, typeSystem.Object);
        PropertyChangedMethod = ResolveMethod(attribute.GetValue <string>(WeaverConstants.OnPropertyChanged), $"On{property.Name}Changed",
                                              typeSystem.Void,
                                              WeaverTypes.BindableObject, typeSystem.Object, typeSystem.Object);
        PropertyChangingMethod = ResolveMethod(attribute.GetValue <string>(WeaverConstants.OnPropertyChanging), $"On{property.Name}Changing",
                                               typeSystem.Void,
                                               WeaverTypes.BindableObject, typeSystem.Object, typeSystem.Object);
        CoerceValueMethod = ResolveMethod(attribute.GetValue <string>(WeaverConstants.OnCoerceValue), $"OnCoerce{property.Name}Value",
                                          typeSystem.Object,
                                          WeaverTypes.BindableObject, typeSystem.Object);
        DefaultValueCreatorMethod = ResolveMethod(attribute.GetValue <string>(WeaverConstants.OnCreateValue), $"OnCreate{property.Name}Value",
                                                  typeSystem.Object,
                                                  WeaverTypes.BindableObject);

        OwningType = attribute.GetValue <TypeReference>(WeaverConstants.OwningType) ?? property.DeclaringType;

        Initializers = FieldInitializer.Create(BackingField);
    }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the property names that should be passed to the notification target method when the property value is changed.
        /// </summary>
        /// <param name="property">The property definition.</param>
        /// <returns>IEnumerable&lt;System.String&gt;.</returns>
        static IEnumerable <string> GetNotifyPropertyNames(PropertyDefinition property, NotificationMode mode)
        {
            //Check for Supression
            var suppress = property.GetAttribute(typeof(SuppressNotifyAttribute));

            if (suppress == null)
            {
                var notify = property.GetAttribute(typeof(NotifyAttribute));

                if (notify == null && mode == NotificationMode.Implicit)
                {
                    yield return(property.Name);
                }
                else if (notify != null)
                {
                    //Return property names supplied by the constructor, if none are specified return the property name itself.
                    if (notify.HasConstructorArguments)
                    {
                        var args = notify.ConstructorArguments.FirstOrDefault(a => a.Type.FullName == typeof(string[]).FullName).Value as CustomAttributeArgument[];

                        if (args == null)
                        {
                            yield return(null);
                        }
                        else if (args.Length == 0)
                        {
                            yield return(property.Name);
                        }
                        else
                        {
                            foreach (var arg in args)
                            {
                                yield return((string)arg.Value);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void DetermineIncludeInBackup()
        {
            IncludeInBackup = true;

            var excludeFromBackupAttribute = PropertyDefinition.GetAttribute("Catel.Fody.ExcludeFromBackupAttribute");

            if (excludeFromBackupAttribute != null)
            {
                IncludeInBackup = false;

                PropertyDefinition.RemoveAttribute("Catel.Fody.ExcludeFromBackupAttribute");
            }
        }
Exemplo n.º 4
0
 public CustomAttribute GetAttribute <T>() where T : Attribute
 {
     if (field != null)
     {
         return(field.GetAttribute <T>());
     }
     else if (property != null)
     {
         return(property.GetAttribute <T>());
     }
     else
     {
         return(eventDef.GetAttribute <T>());
     }
 }
Exemplo n.º 5
0
        private void DetermineDefaultValue()
        {
            //var defaultValueAttribute = PropertyDefinition.GetAttribute("Catel.Fody.DefaultValueAttribute");
            var defaultValueAttribute = PropertyDefinition.GetAttribute("System.ComponentModel.DefaultValueAttribute");

            if (defaultValueAttribute != null)
            {
                DefaultValue = defaultValueAttribute.ConstructorArguments[0].Value;

                // Catel.Fody attribute style
                //var attributeValue = (CustomAttributeArgument) defaultValueAttribute.ConstructorArguments[0].Value;
                //DefaultValue = attributeValue.Value;

                // Note: do not remove since we are now using System.ComponentModel.DefaultValueAttribute after
                // the discussion at https://catelproject.atlassian.net/browse/CTL-244
                //PropertyDefinition.RemoveAttribute("Catel.Fody.DefaultValueAttribute");
            }
        }
Exemplo n.º 6
0
        private (string?name, char?shortName) GetOptionNames(PropertyDefinition definition)
        {
            string?name      = default;
            char?  shortName = default;

            foreach (var arg in definition.GetAttribute(CommandLineParserTypeNames.OptionAttributeFullName).ConstructorArguments)
            {
                if (arg.Type.FullName == SystemTypeNames.StringFullName)
                {
                    name = (string)arg.Value;
                }
                else if (arg.Type.FullName == SystemTypeNames.CharFullName)
                {
                    shortName = (char)arg.Value;
                }
                else
                {
                    m_Logger.LogWarning($"{definition.FullName}: Unexpected constructor argument of type '{arg.Type.FullName}' in OptionAttribute.");
                }
            }

            return(name, shortName);
        }