コード例 #1
0
        internal void SetMethodCompletions(Type computedType, Type thisType, string methodName, bool includeStatic, bool includeInstance, RuleValidation validation)
        {
            BindingFlags @public = BindingFlags.Public;

            if (computedType.Assembly == thisType.Assembly)
            {
                @public |= BindingFlags.NonPublic;
            }
            if (includeInstance)
            {
                @public |= BindingFlags.Instance;
            }
            if (includeStatic)
            {
                @public |= BindingFlags.FlattenHierarchy | BindingFlags.Static;
            }
            List <MemberInfo> candidateMethods = new List <MemberInfo>();

            MemberInfo[] methods = computedType.GetMember(methodName, MemberTypes.Method, @public);
            AddCandidates(candidateMethods, methods);
            if (computedType.IsInterface)
            {
                List <Type> list2 = new List <Type>();
                list2.AddRange(computedType.GetInterfaces());
                for (int i = 0; i < list2.Count; i++)
                {
                    methods = list2[i].GetMember(methodName, MemberTypes.Method, @public);
                    AddCandidates(candidateMethods, methods);
                    Type[] interfaces = list2[i].GetInterfaces();
                    if (interfaces.Length > 0)
                    {
                        list2.AddRange(interfaces);
                    }
                }
                methods = typeof(object).GetMember(methodName, MemberTypes.Method, @public);
                AddCandidates(candidateMethods, methods);
            }
            foreach (ExtensionMethodInfo info in validation.ExtensionMethods)
            {
                ValidationError error;
                if ((info.Name == methodName) && RuleValidation.TypesAreAssignable(computedType, info.AssumedDeclaringType, null, out error))
                {
                    candidateMethods.Add(info);
                }
            }
            this.completions = candidateMethods;
        }
コード例 #2
0
        internal override bool Validate(RuleValidation validation)
        {
            bool               success = false;
            string             message;
            RuleExpressionInfo lhsExprInfo = null;

            if (assignStatement.Left == null)
            {
                ValidationError error = new ValidationError(Messages.NullAssignLeft, ErrorNumbers.Error_LeftOperandMissing);
                error.UserData[RuleUserDataKeys.ErrorObject] = assignStatement;
                validation.Errors.Add(error);
            }
            else
            {
                lhsExprInfo = validation.ExpressionInfo(assignStatement.Left);
                if (lhsExprInfo == null)
                {
                    lhsExprInfo = RuleExpressionWalker.Validate(validation, assignStatement.Left, true);
                }
            }

            RuleExpressionInfo rhsExprInfo = null;

            if (assignStatement.Right == null)
            {
                ValidationError error = new ValidationError(Messages.NullAssignRight, ErrorNumbers.Error_RightOperandMissing);
                error.UserData[RuleUserDataKeys.ErrorObject] = assignStatement;
                validation.Errors.Add(error);
            }
            else
            {
                rhsExprInfo = RuleExpressionWalker.Validate(validation, assignStatement.Right, false);
            }

            if (lhsExprInfo != null && rhsExprInfo != null)
            {
                Type expressionType = rhsExprInfo.ExpressionType;
                Type assignmentType = lhsExprInfo.ExpressionType;

                if (assignmentType == typeof(NullLiteral))
                {
                    // Can't assign to a null literal.
                    ValidationError error = new ValidationError(Messages.NullAssignLeft, ErrorNumbers.Error_LeftOperandInvalidType);
                    error.UserData[RuleUserDataKeys.ErrorObject] = assignStatement;
                    validation.Errors.Add(error);
                    success = false;
                }
                else if (assignmentType == expressionType)
                {
                    // Easy case, they're both the same type.
                    success = true;
                }
                else
                {
                    // The types aren't the same, but it still might be a legal assignment.
                    if (!RuleValidation.TypesAreAssignable(expressionType, assignmentType, assignStatement.Right, out ValidationError error))
                    {
                        if (error == null)
                        {
                            message = string.Format(CultureInfo.CurrentCulture, Messages.AssignNotAllowed, RuleDecompiler.DecompileType(expressionType), RuleDecompiler.DecompileType(assignmentType));
                            error   = new ValidationError(message, ErrorNumbers.Error_OperandTypesIncompatible);
                        }
                        error.UserData[RuleUserDataKeys.ErrorObject] = assignStatement;
                        validation.Errors.Add(error);
                    }
                    else
                    {
                        success = true;
                    }
                }
            }

            return(success);
        }
コード例 #3
0
        internal override bool Validate(RuleValidation validation)
        {
            bool flag = false;
            RuleExpressionInfo info = null;

            if (this.assignStatement.Left == null)
            {
                ValidationError item = new ValidationError(Messages.NullAssignLeft, 0x541);
                item.UserData["ErrorObject"] = this.assignStatement;
                validation.Errors.Add(item);
            }
            else
            {
                info = validation.ExpressionInfo(this.assignStatement.Left);
                if (info == null)
                {
                    info = RuleExpressionWalker.Validate(validation, this.assignStatement.Left, true);
                }
            }
            RuleExpressionInfo info2 = null;

            if (this.assignStatement.Right == null)
            {
                ValidationError error2 = new ValidationError(Messages.NullAssignRight, 0x543);
                error2.UserData["ErrorObject"] = this.assignStatement;
                validation.Errors.Add(error2);
            }
            else
            {
                info2 = RuleExpressionWalker.Validate(validation, this.assignStatement.Right, false);
            }
            if ((info == null) || (info2 == null))
            {
                return(flag);
            }
            Type expressionType = info2.ExpressionType;
            Type lhsType        = info.ExpressionType;

            if (lhsType == typeof(NullLiteral))
            {
                ValidationError error3 = new ValidationError(Messages.NullAssignLeft, 0x542);
                error3.UserData["ErrorObject"] = this.assignStatement;
                validation.Errors.Add(error3);
                return(false);
            }
            if (lhsType != expressionType)
            {
                ValidationError error = null;
                if (!RuleValidation.TypesAreAssignable(expressionType, lhsType, this.assignStatement.Right, out error))
                {
                    if (error == null)
                    {
                        error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.AssignNotAllowed, new object[] { RuleDecompiler.DecompileType(expressionType), RuleDecompiler.DecompileType(lhsType) }), 0x545);
                    }
                    error.UserData["ErrorObject"] = this.assignStatement;
                    validation.Errors.Add(error);
                    return(flag);
                }
            }
            return(true);
        }
コード例 #4
0
        internal void SetTypeMemberCompletions(Type computedType, Type thisType, bool isStatic, RuleValidation validation)
        {
            BindingFlags @public = BindingFlags.Public;

            if (isStatic)
            {
                @public |= BindingFlags.FlattenHierarchy | BindingFlags.Static;
            }
            else
            {
                @public |= BindingFlags.Instance;
            }
            if (computedType.Assembly == thisType.Assembly)
            {
                @public |= BindingFlags.NonPublic;
            }
            List <MemberInfo> list = new List <MemberInfo>(computedType.GetMembers(@public));

            if (computedType.IsInterface)
            {
                List <Type> list2 = new List <Type>(computedType.GetInterfaces());
                for (int i = 0; i < list2.Count; i++)
                {
                    Type type = list2[i];
                    list2.AddRange(type.GetInterfaces());
                    list.AddRange(type.GetMembers(@public));
                }
                list.AddRange(typeof(object).GetMembers(@public));
            }
            foreach (ExtensionMethodInfo info in validation.ExtensionMethods)
            {
                ValidationError error;
                if (RuleValidation.TypesAreAssignable(computedType, info.AssumedDeclaringType, null, out error))
                {
                    list.Add(info);
                }
            }
            Dictionary <string, MemberInfo> dictionary = new Dictionary <string, MemberInfo>();

            foreach (MemberInfo info2 in list)
            {
                MethodInfo   info3;
                PropertyInfo info4;
                if (info2 != null)
                {
                    switch (info2.MemberType)
                    {
                    case MemberTypes.Property:
                    {
                        info4 = (PropertyInfo)info2;
                        ParameterInfo[] indexParameters = info4.GetIndexParameters();
                        if ((indexParameters == null) || (indexParameters.Length <= 0))
                        {
                            goto Label_0292;
                        }
                        foreach (MethodInfo info5 in info4.GetAccessors((@public & BindingFlags.NonPublic) != BindingFlags.Default))
                        {
                            if ((info5.DeclaringType == thisType) || IsNonPrivate(info5, thisType))
                            {
                                dictionary[info5.Name] = info5;
                            }
                        }
                        break;
                    }

                    case MemberTypes.TypeInfo:
                    case MemberTypes.NestedType:
                        if (isStatic && ((info2.DeclaringType == thisType) || IsNonPrivate((Type)info2, thisType)))
                        {
                            dictionary[info2.Name] = info2;
                        }
                        break;

                    case MemberTypes.Field:
                        goto Label_01E3;

                    case MemberTypes.Method:
                        goto Label_014C;
                    }
                }
                continue;
Label_014C:
                info3 = (MethodInfo)info2;
                if ((!info3.IsSpecialName && !info3.IsGenericMethod) && (((info3.DeclaringType == thisType) || IsNonPrivate(info3, thisType)) || (info3 is ExtensionMethodInfo)))
                {
                    dictionary[info2.Name] = info2;
                }
                continue;
Label_01E3:
                if ((info2.DeclaringType == thisType) || IsNonPrivate((FieldInfo)info2, thisType))
                {
                    dictionary[info2.Name] = info2;
                }
                continue;
Label_0292:
                if (info2.DeclaringType == thisType)
                {
                    dictionary[info2.Name] = info2;
                }
                else
                {
                    foreach (MethodInfo info6 in info4.GetAccessors((@public & BindingFlags.NonPublic) != BindingFlags.Default))
                    {
                        if (IsNonPrivate(info6, thisType))
                        {
                            dictionary[info2.Name] = info2;
                            break;
                        }
                    }
                }
            }
            this.completions = dictionary.Values;
        }