If.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / If.cs / 1305376 / If.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

namespace System.Activities.Statements 
{
    using System.Activities; 
    using System.Collections.ObjectModel; 
    using System.ComponentModel;
    using System.Diagnostics.CodeAnalysis; 
    using System.Linq.Expressions;
    using System.Runtime;
    using System.Windows.Markup;
 
    [SuppressMessage(FxCop.Category.Naming, FxCop.Rule.IdentifiersShouldNotMatchKeywords, Justification = "Optimizing for XAML naming. VB imperative users will [] qualify (e.g. New [If])")]
    public sealed class If : NativeActivity 
    { 
        public If()
            : base() 
        {
        }

        public If(Expression> condition) 
            : this()
        { 
            if (condition == null) 
            {
                throw FxTrace.Exception.ArgumentNull("condition"); 
            }

            this.Condition = new InArgument(condition);
        } 

        public If(Activity condition) 
            : this() 
        {
            if (condition == null) 
            {
                throw FxTrace.Exception.ArgumentNull("condition");
            }
 
            this.Condition = new InArgument(condition);
        } 
 
        public If(InArgument condition)
            : this() 
        {
            if (condition == null)
            {
                throw FxTrace.Exception.ArgumentNull("condition"); 
            }
 
            this.Condition = condition; 
        }
 
        [RequiredArgument]
        [DefaultValue(null)]
        public InArgument Condition
        { 
            get;
            set; 
        } 

        [DefaultValue(null)] 
        [DependsOn("Condition")]
        public Activity Then
        {
            get; 
            set;
        } 
 
        [DefaultValue(null)]
        [DependsOn("Then")] 
        public Activity Else
        {
            get;
            set; 
        }
 
        protected override void Execute(NativeActivityContext context) 
        {
            if (Condition.Get(context)) 
            {
                if (Then != null)
                {
                    context.ScheduleActivity(Then); 
                }
            } 
            else if (Else != null) 
            {
                context.ScheduleActivity(Else); 
            }
        }

        protected override void CacheMetadata(NativeActivityMetadata metadata) 
        {
            RuntimeArgument conditionArgument = new RuntimeArgument("Condition", typeof(bool), ArgumentDirection.In, true); 
            metadata.Bind(this.Condition, conditionArgument); 
            metadata.SetArgumentsCollection(new Collection { conditionArgument });
 
            Collection children = null;

            if (this.Then != null)
            { 
                ActivityUtilities.Add(ref children, this.Then);
            } 
 
            if (this.Else != null)
            { 
                ActivityUtilities.Add(ref children, this.Else);
            }

            metadata.SetChildrenCollection(children); 
        }
    } 
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK