コード例 #1
0
        internal static bool IsBinaryOperator(Symbols.UserDefinedOperator Op)
        {
            switch (Op)
            {
            case Symbols.UserDefinedOperator.Plus:
            case Symbols.UserDefinedOperator.Minus:
            case Symbols.UserDefinedOperator.Multiply:
            case Symbols.UserDefinedOperator.Divide:
            case Symbols.UserDefinedOperator.Power:
            case Symbols.UserDefinedOperator.IntegralDivide:
            case Symbols.UserDefinedOperator.Concatenate:
            case Symbols.UserDefinedOperator.ShiftLeft:
            case Symbols.UserDefinedOperator.ShiftRight:
            case Symbols.UserDefinedOperator.Modulus:
            case Symbols.UserDefinedOperator.Or:
            case Symbols.UserDefinedOperator.Xor:
            case Symbols.UserDefinedOperator.And:
            case Symbols.UserDefinedOperator.Like:
            case Symbols.UserDefinedOperator.Equal:
            case Symbols.UserDefinedOperator.NotEqual:
            case Symbols.UserDefinedOperator.Less:
            case Symbols.UserDefinedOperator.LessEqual:
            case Symbols.UserDefinedOperator.GreaterEqual:
            case Symbols.UserDefinedOperator.Greater:
                return(true);

            default:
                return(false);
            }
        }
コード例 #2
0
            private static Symbols.Method VerifyForLoopOperator(Symbols.UserDefinedOperator Op, object ForLoopArgument, Type ForLoopArgumentType)
            {
                Symbols.Method callableUserDefinedOperator = Operators.GetCallableUserDefinedOperator(Op, new object[] { ForLoopArgument, ForLoopArgument });
                if (callableUserDefinedOperator == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("ForLoop_OperatorRequired2", new string[] { Utils.VBFriendlyNameOfType(ForLoopArgumentType, true), Symbols.OperatorNames[(int)Op] }));
                }
                MethodInfo info = callableUserDefinedOperator.AsMethod() as MethodInfo;

                ParameterInfo[] parameters = info.GetParameters();
                switch (Op)
                {
                case Symbols.UserDefinedOperator.Plus:
                case Symbols.UserDefinedOperator.Minus:
                    if ((((parameters.Length != 2) || (parameters[0].ParameterType != ForLoopArgumentType)) || (parameters[1].ParameterType != ForLoopArgumentType)) || (info.ReturnType != ForLoopArgumentType))
                    {
                        throw new ArgumentException(Utils.GetResourceString("ForLoop_UnacceptableOperator2", new string[] { callableUserDefinedOperator.ToString(), Utils.VBFriendlyNameOfType(ForLoopArgumentType, true) }));
                    }
                    return(callableUserDefinedOperator);

                case Symbols.UserDefinedOperator.Multiply:
                case Symbols.UserDefinedOperator.Divide:
                case Symbols.UserDefinedOperator.Power:
                case Symbols.UserDefinedOperator.IntegralDivide:
                case Symbols.UserDefinedOperator.Concatenate:
                case Symbols.UserDefinedOperator.ShiftLeft:
                case Symbols.UserDefinedOperator.ShiftRight:
                case Symbols.UserDefinedOperator.Modulus:
                case Symbols.UserDefinedOperator.Or:
                case Symbols.UserDefinedOperator.Xor:
                case Symbols.UserDefinedOperator.And:
                case Symbols.UserDefinedOperator.Like:
                case Symbols.UserDefinedOperator.Equal:
                case Symbols.UserDefinedOperator.NotEqual:
                case Symbols.UserDefinedOperator.Less:
                    return(callableUserDefinedOperator);

                case Symbols.UserDefinedOperator.LessEqual:
                case Symbols.UserDefinedOperator.GreaterEqual:
                    if (((parameters.Length != 2) || (parameters[0].ParameterType != ForLoopArgumentType)) || (parameters[1].ParameterType != ForLoopArgumentType))
                    {
                        throw new ArgumentException(Utils.GetResourceString("ForLoop_UnacceptableRelOperator2", new string[] { callableUserDefinedOperator.ToString(), Utils.VBFriendlyNameOfType(ForLoopArgumentType, true) }));
                    }
                    return(callableUserDefinedOperator);
                }
                return(callableUserDefinedOperator);
            }
コード例 #3
0
        internal static bool IsUnaryOperator(Symbols.UserDefinedOperator Op)
        {
            switch (Op)
            {
            case Symbols.UserDefinedOperator.Narrow:
            case Symbols.UserDefinedOperator.Widen:
            case Symbols.UserDefinedOperator.IsTrue:
            case Symbols.UserDefinedOperator.IsFalse:
            case Symbols.UserDefinedOperator.Negate:
            case Symbols.UserDefinedOperator.Not:
            case Symbols.UserDefinedOperator.UnaryPlus:
                return(true);

            default:
                return(false);
            }
        }
コード例 #4
0
        internal static Symbols.UserDefinedOperator MapToUserDefinedOperator(MethodBase Method)
        {
            int index = 1;

            do
            {
                if (Method.Name.Equals(Symbols.OperatorCLSNames[index]))
                {
                    int length = Method.GetParameters().Length;
                    Symbols.UserDefinedOperator Op = (Symbols.UserDefinedOperator) checked ((sbyte)index);
                    if (length == 1 && Symbols.IsUnaryOperator(Op) || length == 2 && Symbols.IsBinaryOperator(Op))
                    {
                        return(Op);
                    }
                }
                checked { ++index; }
            }while (index <= 27);
            return(Symbols.UserDefinedOperator.UNDEF);
        }
コード例 #5
0
        internal static object InvokeUserDefinedOperator(Symbols.UserDefinedOperator Op, object[] Arguments)
        {
            CallSiteBinder binder;
            ExpressionType?nullable = IDOUtils.LinqOperator(Op);

            if (!nullable.HasValue)
            {
                return(Operators.InvokeObjectUserDefinedOperator(Op, Arguments));
            }
            ExpressionType linqOp = (ExpressionType)nullable;

            if (Arguments.Length == 1)
            {
                binder = new VBUnaryOperatorBinder(Op, linqOp);
            }
            else
            {
                binder = new VBBinaryOperatorBinder(Op, linqOp);
            }
            object instance = Arguments[0];

            object[] arguments = (Arguments.Length == 1) ? Symbols.NoArguments : new object[] { Arguments[1] };
            return(IDOUtils.CreateFuncCallSiteAndInvoke(binder, instance, arguments));
        }
コード例 #6
0
 public VBUnaryOperatorBinder(Symbols.UserDefinedOperator Op, ExpressionType LinqOp) : base(LinqOp)
 {
     this._Op = Op;
 }
コード例 #7
0
        public static string MethodToString(MethodBase Method)
        {
            bool   flag;
            Type   typ = null;
            string str = "";

            if (Method.MemberType == MemberTypes.Method)
            {
                typ = ((MethodInfo)Method).ReturnType;
            }
            if (Method.IsPublic)
            {
                str = str + "Public ";
            }
            else if (Method.IsPrivate)
            {
                str = str + "Private ";
            }
            else if (Method.IsAssembly)
            {
                str = str + "Friend ";
            }
            if ((Method.Attributes & MethodAttributes.Virtual) != MethodAttributes.ReuseSlot)
            {
                if (!Method.DeclaringType.IsInterface)
                {
                    str = str + "Overrides ";
                }
            }
            else if (Symbols.IsShared(Method))
            {
                str = str + "Shared ";
            }
            Symbols.UserDefinedOperator uNDEF = Symbols.UserDefinedOperator.UNDEF;
            if (Symbols.IsUserDefinedOperator(Method))
            {
                uNDEF = Symbols.MapToUserDefinedOperator(Method);
            }
            if (uNDEF != Symbols.UserDefinedOperator.UNDEF)
            {
                if (uNDEF == Symbols.UserDefinedOperator.Narrow)
                {
                    str = str + "Narrowing ";
                }
                else if (uNDEF == Symbols.UserDefinedOperator.Widen)
                {
                    str = str + "Widening ";
                }
                str = str + "Operator ";
            }
            else if ((typ == null) || (typ == VoidType))
            {
                str = str + "Sub ";
            }
            else
            {
                str = str + "Function ";
            }
            if (uNDEF != Symbols.UserDefinedOperator.UNDEF)
            {
                str = str + Symbols.OperatorNames[(int)uNDEF];
            }
            else if (Method.MemberType == MemberTypes.Constructor)
            {
                str = str + "New";
            }
            else
            {
                str = str + Method.Name;
            }
            if (Symbols.IsGeneric(Method))
            {
                str  = str + "(Of ";
                flag = true;
                foreach (Type type2 in Symbols.GetTypeParameters(Method))
                {
                    if (!flag)
                    {
                        str = str + ", ";
                    }
                    else
                    {
                        flag = false;
                    }
                    str = str + VBFriendlyNameOfType(type2, false);
                }
                str = str + ")";
            }
            str  = str + "(";
            flag = true;
            foreach (ParameterInfo info in Method.GetParameters())
            {
                if (!flag)
                {
                    str = str + ", ";
                }
                else
                {
                    flag = false;
                }
                str = str + ParameterToString(info);
            }
            str = str + ")";
            if ((typ == null) || (typ == VoidType))
            {
                return(str);
            }
            return(str + " As " + VBFriendlyNameOfType(typ, true));
        }
コード例 #8
0
        /// <summary>Returns a Visual Basic method signature.</summary>
        /// <param name="Method">A <see cref="T:System.Reflection.MethodBase" /> object to return a Visual Basic method signature for.</param>
        /// <returns>The Visual Basic method signature for the supplied <see cref="T:System.Reflection.MethodBase" /> object.</returns>
        public static string MethodToString(MethodBase Method)
        {
            Type   typ1 = (Type)null;
            string str1 = "";

            if (Method.MemberType == MemberTypes.Method)
            {
                typ1 = ((MethodInfo)Method).ReturnType;
            }
            if (Method.IsPublic)
            {
                str1 += "Public ";
            }
            else if (Method.IsPrivate)
            {
                str1 += "Private ";
            }
            else if (Method.IsAssembly)
            {
                str1 += "Friend ";
            }
            if ((Method.Attributes & MethodAttributes.Virtual) != MethodAttributes.PrivateScope)
            {
                if (!Method.DeclaringType.IsInterface)
                {
                    str1 += "Overrides ";
                }
            }
            else if (Symbols.IsShared((MemberInfo)Method))
            {
                str1 += "Shared ";
            }
            Symbols.UserDefinedOperator userDefinedOperator = Symbols.UserDefinedOperator.UNDEF;
            if (Symbols.IsUserDefinedOperator(Method))
            {
                userDefinedOperator = Symbols.MapToUserDefinedOperator(Method);
            }
            string str2;

            switch (userDefinedOperator)
            {
            case Symbols.UserDefinedOperator.UNDEF:
                str2 = typ1 == null || typ1 == Utils.VoidType ? str1 + "Sub " : str1 + "Function ";
                break;

            case Symbols.UserDefinedOperator.Narrow:
                str1 += "Narrowing ";
                goto default;

            case Symbols.UserDefinedOperator.Widen:
                str1 += "Widening ";
                goto default;

            default:
                str2 = str1 + "Operator ";
                break;
            }
            string str3 = userDefinedOperator == Symbols.UserDefinedOperator.UNDEF ? (Method.MemberType != MemberTypes.Constructor ? str2 + Method.Name : str2 + "New") : str2 + Symbols.OperatorNames[(int)userDefinedOperator];

            if (Symbols.IsGeneric(Method))
            {
                string str4           = str3 + "(Of ";
                bool   flag           = true;
                Type[] typeParameters = Symbols.GetTypeParameters((MemberInfo)Method);
                int    index          = 0;
                while (index < typeParameters.Length)
                {
                    Type typ2 = typeParameters[index];
                    if (!flag)
                    {
                        str4 += ", ";
                    }
                    else
                    {
                        flag = false;
                    }
                    str4 += Utils.VBFriendlyNameOfType(typ2, false);
                    checked { ++index; }
                }
                str3 = str4 + ")";
            }
            string str5  = str3 + "(";
            bool   flag1 = true;

            ParameterInfo[] parameters = Method.GetParameters();
            int             index1     = 0;

            while (index1 < parameters.Length)
            {
                ParameterInfo Parameter = parameters[index1];
                if (!flag1)
                {
                    str5 += ", ";
                }
                else
                {
                    flag1 = false;
                }
                str5 += Utils.ParameterToString(Parameter);
                checked { ++index1; }
            }
            string str6 = str5 + ")";

            if (typ1 != null && typ1 != Utils.VoidType)
            {
                str6 = str6 + " As " + Utils.VBFriendlyNameOfType(typ1, true);
            }
            return(str6);
        }
 public VBUnaryOperatorBinder(Symbols.UserDefinedOperator Op, ExpressionType LinqOp) : base(LinqOp)
 {
     this._Op = Op;
 }
コード例 #10
0
        internal static ExpressionType?LinqOperator(Symbols.UserDefinedOperator vbOperator)
        {
            ExpressionType?nullable2;

            switch (vbOperator)
            {
            case Symbols.UserDefinedOperator.Negate:
                return(0x1c);

            case Symbols.UserDefinedOperator.Not:
                return(0x22);

            case Symbols.UserDefinedOperator.UnaryPlus:
                return(0x1d);

            case Symbols.UserDefinedOperator.Plus:
                return(0);

            case Symbols.UserDefinedOperator.Minus:
                return(0x2a);

            case Symbols.UserDefinedOperator.Multiply:
                return(0x1a);

            case Symbols.UserDefinedOperator.Divide:
                return(12);

            case Symbols.UserDefinedOperator.Power:
                return(0x27);

            case Symbols.UserDefinedOperator.IntegralDivide:
            case Symbols.UserDefinedOperator.Concatenate:
            case Symbols.UserDefinedOperator.Like:
                return(nullable2);

            case Symbols.UserDefinedOperator.ShiftLeft:
                return(0x13);

            case Symbols.UserDefinedOperator.ShiftRight:
                return(0x29);

            case Symbols.UserDefinedOperator.Modulus:
                return(0x19);

            case Symbols.UserDefinedOperator.Or:
                return(0x24);

            case Symbols.UserDefinedOperator.Xor:
                return(14);

            case Symbols.UserDefinedOperator.And:
                return(2);

            case Symbols.UserDefinedOperator.Equal:
                return(13);

            case Symbols.UserDefinedOperator.NotEqual:
                return(0x23);

            case Symbols.UserDefinedOperator.Less:
                return(20);

            case Symbols.UserDefinedOperator.LessEqual:
                return(0x15);

            case Symbols.UserDefinedOperator.GreaterEqual:
                return(0x10);

            case Symbols.UserDefinedOperator.Greater:
                return(15);
            }
            return(nullable2);
        }