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

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

namespace System.Activities.Expressions 
{
    using System.Activities.Validation; 
    using System.Collections.ObjectModel; 
    using System.Linq.Expressions;
    using System.Runtime; 

    static class UnaryExpressionHelper
    {
        public static void OnGetArguments(CodeActivityMetadata metadata, InArgument operand) 
        {
            RuntimeArgument operandArgument = new RuntimeArgument("Operand", typeof(TOperand), ArgumentDirection.In, true); 
            metadata.Bind(operand, operandArgument); 

            metadata.SetArgumentsCollection( 
                new Collection
                {
                    operandArgument
                }); 
        }
 
        public static bool TryGenerateLinqDelegate(ExpressionType operatorType, out Func operation, out ValidationError validationError) 
        {
            operation = null; 
            validationError = null;

            ParameterExpression operandParameter = Expression.Parameter(typeof(TOperand), "operand");
            try 
            {
                UnaryExpression unaryExpression = Expression.MakeUnary(operatorType, operandParameter, typeof(TResult)); 
                Expression> lambdaExpression = Expression.Lambda>(unaryExpression, operandParameter); 
                operation = lambdaExpression.Compile();
                return true; 
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e)) 
                {
                    throw; 
                } 

                validationError = new ValidationError(e.Message); 
                return false;
            }
        }
    } 

} 

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