public SelectValidatedTypeReferenceMembersCommand(TypeMemberChooser typeMemberChooser, ElementViewModel context, CommandAttribute attribute, IUIServiceWpf uiService)
            : base(attribute, uiService)
        {
            if (context.ConfigurationType != typeof(ValidationRulesetData)) throw new InvalidOperationException();

            this.validatedTypeReferenceElement = context.AncestorElements().Where(x => x.ConfigurationType == typeof(ValidatedTypeReference)).First();
            this.fieldCollectionElement = (ElementCollectionViewModel)context.ChildElements.Where(x => x.ConfigurationType == typeof(ValidatedFieldReferenceCollection)).First();
            this.propertyCollectionElement = (ElementCollectionViewModel)context.ChildElements.Where(x => x.ConfigurationType == typeof(ValidatedPropertyReferenceCollection)).First();
            this.methodsCollectionElement = (ElementCollectionViewModel)context.ChildElements.Where(x => x.ConfigurationType == typeof(ValidatedMethodReferenceCollection)).First();

            this.typeMemberChooser = typeMemberChooser;
        }
Пример #2
0
        /// <summary>
        /// Adds either a <see cref="FieldNode"/>, <see cref="MethodNode"/> or <see cref="PropertyNode"/> to the current <see cref="RuleSetNode"/>,
        /// based on the selected member.
        /// </summary>
        /// <param name="node">The parent node to newly added configuration node.</param>
        protected override void ExecuteCore(ConfigurationNode node)
        {
            try
            {
                UIService.BeginUpdate();
                Type type = FindType(node);
                if (type != null)
                {
                    IUIService        uiService     = ServiceHelper.GetUIService(serviceProvider);
                    TypeMemberChooser memberChooser = new TypeMemberChooser(uiService);
                    foreach (MemberInfo memberInfo in memberChooser.ChooseMembers(type))
                    {
                        if (memberInfo != null)
                        {
                            if (node.Nodes.Contains(memberInfo.Name))
                            {
                                continue;
                            }

                            ConfigurationNode childNode = null;
                            if (memberInfo is PropertyInfo)
                            {
                                childNode = new PropertyNode(memberInfo.Name);
                            }
                            else if (memberInfo is MethodInfo)
                            {
                                childNode = new MethodNode(memberInfo.Name);
                            }
                            else if (memberInfo is FieldInfo)
                            {
                                childNode = new FieldNode(memberInfo.Name);
                            }
                            else
                            {
                                Debug.Assert(false, "memberInfo should be either PropertyInfo, MethodInfo or FieldInfo");
                            }

                            node.AddNode(childNode);
                            UIService.SetUIDirty(node.Hierarchy);
                        }
                    }
                }
            }
            finally
            {
                UIService.EndUpdate();
            }
        }
Пример #3
0
        /// <summary>
        /// Adds either a <see cref="FieldNode"/>, <see cref="MethodNode"/> or <see cref="PropertyNode"/> to the current <see cref="RuleSetNode"/>,
        /// based on the selected member.
        /// </summary>
        /// <param name="node">The parent node to newly added configuration node.</param>
        protected override void ExecuteCore(ConfigurationNode node)
        {
            try
            {
                UIService.BeginUpdate();
                Type type = FindType(node);
                if (type != null)
                {
                    IUIService uiService = ServiceHelper.GetUIService(serviceProvider);
                    TypeMemberChooser memberChooser = new TypeMemberChooser(uiService);
                    foreach (MemberInfo memberInfo in memberChooser.ChooseMembers(type))
                    {
                        if (memberInfo != null)
                        {
                            if (node.Nodes.Contains(memberInfo.Name)) continue;

                            ConfigurationNode childNode = null;
                            if (memberInfo is PropertyInfo)
                            {
                                childNode = new PropertyNode(memberInfo.Name);
                            }
                            else if (memberInfo is MethodInfo)
                            {
                                childNode = new MethodNode(memberInfo.Name);
                            }
                            else if (memberInfo is FieldInfo)
                            {
                                childNode = new FieldNode(memberInfo.Name);
                            }
                            else
                            {
                                Debug.Assert(false, "memberInfo should be either PropertyInfo, MethodInfo or FieldInfo");
                            }

                            node.AddNode(childNode);
                            UIService.SetUIDirty(node.Hierarchy);
                        }
                    }
                }
            }
            finally
            {
                UIService.EndUpdate();
            }
        }