FieldValue.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 / Expressions / FieldValue.cs / 1305376 / FieldValue.cs

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

namespace System.Activities.Expressions 
{
    using System.Activities; 
    using System.Activities.Validation; 
    using System.ComponentModel;
    using System.Reflection; 

    public sealed class FieldValue : CodeActivity
    {
        Func operationFunction; 

        [DefaultValue(null)] 
        public string FieldName 
        {
            get; 
            set;
        }

        [DefaultValue(null)] 
        public InArgument Operand
        { 
            get; 
            set;
        } 

        protected override void CacheMetadata(CodeActivityMetadata metadata)
        {
            bool isRequired = false; 

            if (typeof(TOperand).IsEnum) 
            { 
                metadata.AddValidationError(SR.TargetTypeCannotBeEnum(this.GetType().Name, this.DisplayName));
            } 

            if (string.IsNullOrEmpty(this.FieldName))
            {
                metadata.AddValidationError(SR.ActivityPropertyMustBeSet("FieldName", this.DisplayName)); 
            }
            else 
            { 
                FieldInfo fieldInfo = null;
                Type operandType = typeof(TOperand); 
                fieldInfo = operandType.GetField(this.FieldName);

                if (fieldInfo == null)
                { 
                    metadata.AddValidationError(SR.MemberNotFound(this.FieldName, typeof(TOperand).Name));
                } 
                else 
                {
                    isRequired = !fieldInfo.IsStatic; 
                    ValidationError validationError;
                    if (!MemberExpressionHelper.TryGenerateLinqDelegate(this.FieldName, true, fieldInfo.IsStatic, out this.operationFunction, out validationError))
                    {
                        metadata.AddValidationError(validationError); 
                    }
                } 
            } 
            MemberExpressionHelper.AddOperandArgument(metadata, this.Operand, isRequired);
        } 

        protected override TResult Execute(CodeActivityContext context)
        {
            TOperand operandValue = this.Operand.Get(context); 
            return this.operationFunction(operandValue);
        } 
    } 
}

// 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