Esempio n. 1
0
    public void ProcessType(TypeDefinition typeDefinition)
    {
        if (!typeDefinition.CustomAttributes.ContainsValidationAttribute())
        {
            //TODO:log
            return;
        }

        if (dataErrorInfoFinder.Found)
        {
            var injector = new DataErrorInfoInjector
            {
                TypeDefinition           = typeDefinition,
                TypeSystem               = ModuleDefinition.TypeSystem,
                ValidationTemplateFinder = templateFinder,
                DataErrorInfoFinder      = dataErrorInfoFinder,
                ModuleWeaver             = this,
            };
            injector.Execute();
        }

        if (notifyDataErrorInfoFinder.Found)
        {
            var injector = new NotifyDataErrorInfoInjector
            {
                TypeDefinition            = typeDefinition,
                NotifyDataErrorInfoFinder = notifyDataErrorInfoFinder,
                ValidationTemplateFinder  = templateFinder,
                TypeSystem   = ModuleDefinition.TypeSystem,
                ModuleWeaver = this,
            };
            injector.Execute();
        }
    }
Esempio n. 2
0
    public void ProcessType(TypeDefinition type)
    {
        var containsValidationAttribute = type.CustomAttributes.ContainsValidationAttribute();

        if (!type.ImplementsINotify())
        {
            if (containsValidationAttribute)
            {
                throw new WeavingException($"Found [InjectValidationAttribute] on '{type.Name}' but it doesn't implement INotifyPropertyChanged so cannot inject.");
            }

            return;
        }

        if (!containsValidationAttribute)
        {
            return;
        }

        if (type.HasGenericParameters)
        {
            throw new WeavingException($"Failed to process '{type.FullName}'. Generic models are not supported. Feel free to send a pull request.");
        }

        var templateFieldInjector = new TemplateFieldInjector
        {
            ValidationTemplateFinder = templateFinder,
            TargetType       = type,
            ModuleDefinition = ModuleDefinition,
            TypeSystem       = TypeSystem
        };

        templateFieldInjector.AddField();

        if (dataErrorInfoFinder.Found)
        {
            var injector = new DataErrorInfoInjector
            {
                TypeDefinition          = type,
                TypeSystem              = TypeSystem,
                DataErrorInfoFinder     = dataErrorInfoFinder,
                ModuleWeaver            = this,
                ValidationTemplateField = templateFieldInjector.ValidationTemplateField
            };
            injector.Execute();
        }

        if (notifyDataErrorInfoFinder.Found)
        {
            var injector = new NotifyDataErrorInfoInjector
            {
                TypeDefinition            = type,
                NotifyDataErrorInfoFinder = notifyDataErrorInfoFinder,
                TypeSystem              = TypeSystem,
                ModuleWeaver            = this,
                ValidationTemplateField = templateFieldInjector.ValidationTemplateField
            };
            injector.Execute();
        }
    }
Esempio n. 3
0
    public void ProcessType(TypeDefinition type)
    {
        var containsValidationAttribute = type.CustomAttributes.ContainsValidationAttribute();
        if (!type.ImplementsINotify())
        {
            if (containsValidationAttribute)
            {
                throw new WeavingException($"Found [InjectValidationAttribute] on '{type.Name}' but it doesnt implement INotifyPropertyChanged so cannot inject.");
            }
            return;
        }
        if (!containsValidationAttribute)
        {
            return;
        }
        if (type.HasGenericParameters)
        {
            throw new WeavingException($"Failed to process '{type.FullName}'. Generic models are not supported. Feel free to send a pull request.");
        }
        var templateFieldInjector = new TemplateFieldInjector
                                                      {
                                                          ValidationTemplateFinder = templateFinder,
                                                          TargetType = type,
                                                          ModuleDefinition = ModuleDefinition
                                                      };
         templateFieldInjector.AddField();

        if (dataErrorInfoFinder.Found)
        {
            var injector = new DataErrorInfoInjector
            {
                TypeDefinition = type,
                TypeSystem = ModuleDefinition.TypeSystem,
                DataErrorInfoFinder = dataErrorInfoFinder,
                ModuleWeaver = this,
                ValidationTemplateField = templateFieldInjector.ValidationTemplateField
            };
            injector.Execute();
        }

        if (notifyDataErrorInfoFinder.Found)
        {
            var injector = new NotifyDataErrorInfoInjector
            {
                TypeDefinition = type,
                NotifyDataErrorInfoFinder = notifyDataErrorInfoFinder,
                TypeSystem= ModuleDefinition.TypeSystem,
                ModuleWeaver = this,
                ValidationTemplateField = templateFieldInjector.ValidationTemplateField
            };
            injector.Execute();
        }
    }
Esempio n. 4
0
    public void ProcessType(TypeDefinition typeDefinition)
    {
        if (!typeDefinition.CustomAttributes.ContainsValidationAttribute())
        {
            return;
        }
        if (typeDefinition.HasGenericParameters)
        {
            throw new WeavingException(string.Format("Failed to process '{0}'. Generic models are not supported. Feel free to send a pull request.", typeDefinition.FullName));
        }
        var templateFieldInjector = new TemplateFieldInjector
                                                      {
                                                          ValidationTemplateFinder = templateFinder,
                                                          TargetType = typeDefinition,
                                                          ModuleDefinition = ModuleDefinition
                                                      };
         templateFieldInjector.AddField();

        if (dataErrorInfoFinder.Found)
        {
            var injector = new DataErrorInfoInjector
            {
                TypeDefinition = typeDefinition,
                TypeSystem = ModuleDefinition.TypeSystem,
                DataErrorInfoFinder = dataErrorInfoFinder,
                ModuleWeaver = this,
                ValidationTemplateField = templateFieldInjector.ValidationTemplateField
            };
            injector.Execute();
        }

        if (notifyDataErrorInfoFinder.Found)
        {
            var injector = new NotifyDataErrorInfoInjector
            {
                TypeDefinition = typeDefinition,
                NotifyDataErrorInfoFinder = notifyDataErrorInfoFinder,
                TypeSystem= ModuleDefinition.TypeSystem,
                ModuleWeaver = this,
                ValidationTemplateField = templateFieldInjector.ValidationTemplateField
            };
            injector.Execute();
        }
    }