Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6790961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:47:19+00:00 2026-05-26T17:47:19+00:00

I’ve got an Outer activity which has a Body onto which you drag other

  • 0

I’ve got an Outer activity which has a Body onto which you drag other activities. I then have several Inner activities, which MUST be a descendent of an Outer activity. I’d like to add design-time validation to ensure the Inner is placed within an Outer.

I’ve heard that I “can use System.Activities.Validation.GetParentChain to enumerate all of the parents of an activity during the validation step“. But even after reading the documentation for the class, I have no idea how to use it.

I would think I use it inside CacheMetadata in my Inner class. I’d like to use have a foreach(var ancestor in parentChain) { … }, and make sure at least one ancestor is of type Outer. Not sure how to do that.

Can anyone explain how to validate at design time that an Inner activity is a descendant of an Outer activity?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:47:20+00:00Added an answer on May 26, 2026 at 5:47 pm

    As you can see through the documentation GetParentChain is a regular CodeActivity. You can use it in conjunction with Activity.Constraints.

    Constraints are executed at design time, just like CacheMetadata(), but you have the ability to access the context (the ValidationContext at this point, of course). Otherwise you wouldn’t be able to known the upper level activities.

    Lets see if I understood your case right and if this example covers it. Basically it loops through IEnumerable<Activity> returned by GetParentChain and checks if any of Inner‘s parents is an Outer. This way it ensures that Inner is always inside an Outer.

    public sealed class Inner : CodeActivity
    {
    
        public Inner()
        {
            Constraints.Add(MustBeInsideOuterActivityConstraint());
        }
    
        protected override void Execute(CodeActivityContext context)
        {
            // Execution logic here
        }
    
        private Constraint<Inner> MustBeInsideOuterActivityConstraint()
        {
            var activityBeingValidated = new DelegateInArgument<Inner>();
            var validationContext = new DelegateInArgument<ValidationContext>();
            var parent = new DelegateInArgument<Activity>();
            var parentIsOuter = new Variable<bool>();
    
            return new Constraint<Inner>
            {
                Body = new ActivityAction<Inner, ValidationContext>
                {
                    Argument1 = activityBeingValidated,
                    Argument2 = validationContext,
    
                    Handler = new Sequence
                    {
                        Variables = 
                        {
                            parentIsOuter
                        },
                        Activities =
                        {
                            new ForEach<Activity>
                            {
                                Values = new GetParentChain 
                                { 
                                    ValidationContext = validationContext 
                                },
    
                                Body = new ActivityAction<Activity>
                                {
                                    Argument = parent,
    
                                    Handler = new If
                                    {
                                        Condition = new InArgument<bool>(env => 
                                            object.Equals(parent.Get(env).GetType(), typeof(Outer))),
    
                                        Then = new Assign<bool> 
                                        { 
                                            To = parentIsOuter, 
                                            Value = true 
                                        }
                                    }    
                                }
                            },
    
                            new AssertValidation
                            {
                                Assertion = parentIsOuter,
                                Message = "Inner must be inside Outer"
                            }
                        }
                    }
                }
            };
        }
    }
    

    If you want to allow multiple Outers, you have to check them, one by one, wither with a loop through an array (using ForEach) or multiple nested Ifs.

    For example, with multiple ifs, and continuing with the code above:

    Handler = new If
    {
        Condition = new InArgument<bool>(env => 
            object.Equals(parent.Get(env).GetType(), typeof(OuterONE))),
    
        Then = new Assign<bool> 
        { 
            To = parentIsOuter, 
            Value = true 
        }
        Else = new If
        {
             Condition = new InArgument<bool>(env => 
                 object.Equals(parent.Get(env).GetType(), typeof(OuterTWO))),
    
             Then = new Assign<bool> 
             { 
                To = parentIsOuter, 
                Value = true 
             },
    
             Else = new If 
             {
                 // and continue with other Outers
             }
        }
    } 
    

    In short, an If-then-else statement using activities.

    Other option that I’ve never tested but that it seems pretty plausible, and because you can use activities inside constraints, is throw all this logic inside an activity which its only job is to check if type if an Outer:

    public sealed CheckIfTypeIsOuter<T> : CodeActivity<bool>
    {
        protected override bool Execute() 
        {
            if (typeof(T) == typeof(Outer1))
                return true;
            if (typeof(T) == typeof(Outer2))
                return true;
            if (typeof(T) == typeof(Outer3))
                return true;
            if (typeof(T) == typeof(Outer4))
                return true;
    
            return false;
        }
    }
    

    This way you can do it through code.

    Well, I guess you get the idea!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.