Exemplo n.º 1
0
        private static object ResolveScopeWalkBindTarget(string bindAs, LambdaRepository lambdaRepo, ScopeChain scopeChain)
        {
            int    lastIdxOf;
            int    depth  = BindHelper.CountInstancesOfPattern(bindAs, @"..\", out lastIdxOf);
            object target = BindHelper.ResolveBindTarget(bindAs.Substring(lastIdxOf + 3, bindAs.Length - (depth * 3)), lambdaRepo, scopeChain, depth);

            return(target);
        }
Exemplo n.º 2
0
        private object EnsureCharArgument(string arg, ScopeChain scopeChain, string lambdaName, int index)
        {
            object target = null;

            if (BindHelper.IsDoubleQuoted(arg) || BindHelper.IsSingleQuoted(arg))
            {
                target = arg.Substring(1, (arg.Length - 2));
            }
            else
            {
                target = BindHelper.ResolveBindTarget(arg, this, scopeChain);
                this.EnsureArgumentType(arg, target, TypeCode.Char, lambdaName, index);
            }
            return(target);
        }
Exemplo n.º 3
0
        private static object ResolveVariableReferenceBindTarget(string bindAs, LambdaRepository lambdaRepo, ScopeChain scopeChain)
        {
            object target = null;
            int    dot    = bindAs.IndexOf('.');

            if (dot > -1)
            {
                target = scopeChain.AccessVariable(bindAs.Substring(0, dot));
                scopeChain.Push(target);
                target = BindHelper.ResolveBindTarget(bindAs.Substring(++dot, bindAs.Length - dot), lambdaRepo, scopeChain);
                scopeChain.Pop();
            }
            else
            {
                target = scopeChain.AccessVariable(bindAs);
            }
            return(target);
        }
Exemplo n.º 4
0
        private object EnsureUInt64Argument(string arg, ScopeChain scopeChain, string lambdaName, int index)
        {
            object target = null;

            if (char.IsDigit(arg[0])) //must be numeric literal
            {
                if (!UInt64.TryParse(arg, out UInt64 u))
                {
                    throw new MergeException(this.FormatExceptionMessageBuilder(lambdaName, arg, index, TypeCode.UInt64));
                }
                target = u;
            }
            else
            {
                target = BindHelper.ResolveBindTarget(arg, this, scopeChain);
                this.EnsureArgumentType(arg, target, TypeCode.UInt64, lambdaName, index);
            }
            return(target);
        }
Exemplo n.º 5
0
        private object EnsureSingleArgument(string arg, ScopeChain scopeChain, string lambdaName, int index)
        {
            object target = null;

            if (char.IsDigit(arg[0]) || arg[0] == '.' || arg[0] == '-' || arg[0] == '+') //must be numeric literal
            {
                if (!Single.TryParse(arg, out Single s))
                {
                    throw new MergeException(this.FormatExceptionMessageBuilder(lambdaName, arg, index, TypeCode.Single));
                }
                target = s;
            }
            else
            {
                target = BindHelper.ResolveBindTarget(arg, this, scopeChain);
                this.EnsureArgumentType(arg, target, TypeCode.Single, lambdaName, index);
            }
            return(target);
        }
Exemplo n.º 6
0
        public object EnsureBooleanArgument(string arg, ScopeChain scopeChain, string lambdaName, int index)
        {
            object target = null;

            if (string.Compare(arg, "true", true) == 0)
            {
                target = true;
            }
            else if (string.Compare(arg, "false", true) == 0)
            {
                target = false;
            }
            else
            {
                target = BindHelper.ResolveBindTarget(arg, this, scopeChain);
                this.EnsureArgumentType(arg, target, TypeCode.Boolean, lambdaName, index);
            }
            return(target);
        }
Exemplo n.º 7
0
        private object EnsureDateTimeArgument(string arg, ScopeChain scopeChain, string lambdaName, int index)
        {
            object target = null;

            if (BindHelper.IsDoubleQuoted(arg) || BindHelper.IsSingleQuoted(arg))
            {
                arg = arg.Substring(1, (arg.Length - 2));
                if (!DateTime.TryParse(arg, out DateTime dt))
                {
                    throw new MergeException(this.FormatExceptionMessageBuilder(lambdaName, arg, index, TypeCode.DateTime));
                }
                return(dt);
            }
            else
            {
                target = BindHelper.ResolveBindTarget(arg, this, scopeChain);
                this.EnsureArgumentType(arg, target, TypeCode.DateTime, lambdaName, index);
            }
            return(target);
        }
Exemplo n.º 8
0
        private object CaptureLambdaArgument(string arg, ScopeChain scopeChain, ParameterInfo paramInfo, string lambda, int index)
        {
            object   obj   = null;
            TypeCode tCode = Type.GetTypeCode(paramInfo.ParameterType);

            switch (tCode)
            {
            case TypeCode.Object:
                obj = BindHelper.ResolveBindTarget(arg, this, scopeChain);
                break;

            case TypeCode.Boolean:
                obj = this.EnsureBooleanArgument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.Byte:
                obj = this.EnsureByteArgument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.Char:
                obj = this.EnsureCharArgument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.String:
                obj = this.EnsureStringArgument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.DateTime:
                obj = this.EnsureDateTimeArgument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.Decimal:
                obj = this.EnsureDecimalArgument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.Double:
                obj = this.EnsureDoubleArgument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.Int16:
                obj = this.EnsureInt16Argument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.Int32:
                obj = this.EnsureInt32Argument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.Int64:
                obj = this.EnsureInt64Argument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.UInt16:
                obj = this.EnsureUInt16Argument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.UInt32:
                obj = this.EnsureUInt32Argument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.UInt64:
                obj = this.EnsureUInt64Argument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.SByte:
                obj = this.EnsureSByteArgument(arg, scopeChain, lambda, index);
                break;

            case TypeCode.Single:
                obj = this.EnsureSingleArgument(arg, scopeChain, lambda, index);;
                break;

            //case TypeCode.Empty:
            //    break;
            //case TypeCode.DBNull:
            //    break;
            default:
                throw new MergeException($"encountered un-expected Type.TypeCode: {tCode}");
            }

            return(obj);
        }