當前位置: 首頁>>代碼示例>>C#>>正文


C# RuleValidation.ResolveConstructor方法代碼示例

本文整理匯總了C#中System.Workflow.Activities.Rules.RuleValidation.ResolveConstructor方法的典型用法代碼示例。如果您正苦於以下問題:C# RuleValidation.ResolveConstructor方法的具體用法?C# RuleValidation.ResolveConstructor怎麽用?C# RuleValidation.ResolveConstructor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Workflow.Activities.Rules.RuleValidation的用法示例。


在下文中一共展示了RuleValidation.ResolveConstructor方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Validate

        internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
        {
            string message;
            ValidationError error;

            CodeObjectCreateExpression createExpression = (CodeObjectCreateExpression)expression;

            if (isWritten)
            {
                message = string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, typeof(CodeObjectCreateExpression).ToString());
                error = new ValidationError(message, ErrorNumbers.Error_InvalidAssignTarget);
                error.UserData[RuleUserDataKeys.ErrorObject] = createExpression;
                validation.Errors.Add(error);
                return null;
            }

            if (createExpression.CreateType == null)
            {
                error = new ValidationError(Messages.NullTypeType, ErrorNumbers.Error_ParameterNotSet);
                error.UserData[RuleUserDataKeys.ErrorObject] = createExpression;
                validation.Errors.Add(error);
                return null;
            }

            Type resultType = validation.ResolveType(createExpression.CreateType);
            if (resultType == null)
                return null;

            // look up parameters
            List<CodeExpression> parameters = new List<CodeExpression>();
            try
            {
                // Early exit from this if a cycle is detected.
                if (!validation.PushParentExpression(createExpression))
                    return null;

                bool hasInvalidArgument = false;
                for (int i = 0; i < createExpression.Parameters.Count; ++i)
                {
                    CodeExpression parameter = createExpression.Parameters[i];
                    if (parameter == null)
                    {
                        message = string.Format(CultureInfo.CurrentCulture, Messages.NullConstructorParameter, i.ToString(CultureInfo.CurrentCulture), RuleDecompiler.DecompileType(resultType));
                        error = new ValidationError(message, ErrorNumbers.Error_ParameterNotSet);
                        error.UserData[RuleUserDataKeys.ErrorObject] = createExpression;
                        validation.Errors.Add(error);
                        hasInvalidArgument = true;
                    }
                    else
                    {
                        RuleExpressionInfo parameterInfo = RuleExpressionWalker.Validate(validation, parameter, false);
                        if (parameterInfo == null)
                            hasInvalidArgument = true;
                        parameters.Add(parameter);
                    }
                }
                // quit if parameters not valid
                if (hasInvalidArgument)
                    return null;
            }
            finally
            {
                validation.PopParentExpression();
            }

            // see if we can find the matching constructor
            BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance;
            if (validation.AllowInternalMembers(resultType))
                bindingFlags |= BindingFlags.NonPublic;

            // creating a value-type object with no parameters can always be done
            if ((resultType.IsValueType) && (parameters.Count == 0))
                return new RuleExpressionInfo(resultType);

            // error if type is an abstract type
            if (resultType.IsAbstract)
            {
                message = string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, RuleDecompiler.DecompileType(resultType));
                error = new ValidationError(message, ErrorNumbers.Error_MethodNotExists);
                error.UserData[RuleUserDataKeys.ErrorObject] = createExpression;
                validation.Errors.Add(error);
                return null;
            }

            RuleConstructorExpressionInfo constructorInvokeInfo = validation.ResolveConstructor(resultType, bindingFlags, parameters, out error);
            if (constructorInvokeInfo == null)
            {
                message = string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, RuleDecompiler.DecompileType(resultType));
                error = new ValidationError(message, ErrorNumbers.Error_MethodNotExists);
                error.UserData[RuleUserDataKeys.ErrorObject] = createExpression;
                validation.Errors.Add(error);
                return null;
            }

            return constructorInvokeInfo;
        }
開發者ID:nlh774,項目名稱:DotNetReferenceSource,代碼行數:96,代碼來源:Expressions.cs

示例2: Validate

 internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
 {
     ValidationError error;
     CodeObjectCreateExpression newParent = (CodeObjectCreateExpression) expression;
     if (isWritten)
     {
         error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeObjectCreateExpression).ToString() }), 0x17a);
         error.UserData["ErrorObject"] = newParent;
         validation.Errors.Add(error);
         return null;
     }
     if (newParent.CreateType == null)
     {
         error = new ValidationError(Messages.NullTypeType, 0x53d);
         error.UserData["ErrorObject"] = newParent;
         validation.Errors.Add(error);
         return null;
     }
     Type type = validation.ResolveType(newParent.CreateType);
     if (type == null)
     {
         return null;
     }
     List<CodeExpression> argumentExprs = new List<CodeExpression>();
     try
     {
         if (!validation.PushParentExpression(newParent))
         {
             return null;
         }
         bool flag = false;
         for (int i = 0; i < newParent.Parameters.Count; i++)
         {
             CodeExpression expression3 = newParent.Parameters[i];
             if (expression3 == null)
             {
                 error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.NullConstructorParameter, new object[] { i.ToString(CultureInfo.CurrentCulture), RuleDecompiler.DecompileType(type) }), 0x53d);
                 error.UserData["ErrorObject"] = newParent;
                 validation.Errors.Add(error);
                 flag = true;
             }
             else
             {
                 if (RuleExpressionWalker.Validate(validation, expression3, false) == null)
                 {
                     flag = true;
                 }
                 argumentExprs.Add(expression3);
             }
         }
         if (flag)
         {
             return null;
         }
     }
     finally
     {
         validation.PopParentExpression();
     }
     BindingFlags constructorBindingFlags = BindingFlags.Public | BindingFlags.Instance;
     if (validation.AllowInternalMembers(type))
     {
         constructorBindingFlags |= BindingFlags.NonPublic;
     }
     if (type.IsValueType && (argumentExprs.Count == 0))
     {
         return new RuleExpressionInfo(type);
     }
     if (type.IsAbstract)
     {
         error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, new object[] { RuleDecompiler.DecompileType(type) }), 0x137);
         error.UserData["ErrorObject"] = newParent;
         validation.Errors.Add(error);
         return null;
     }
     RuleConstructorExpressionInfo info2 = validation.ResolveConstructor(type, constructorBindingFlags, argumentExprs, out error);
     if (info2 == null)
     {
         error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.UnknownConstructor, new object[] { RuleDecompiler.DecompileType(type) }), 0x137);
         error.UserData["ErrorObject"] = newParent;
         validation.Errors.Add(error);
         return null;
     }
     return info2;
 }
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:85,代碼來源:ObjectCreateExpression.cs


注:本文中的System.Workflow.Activities.Rules.RuleValidation.ResolveConstructor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。