private static string ReadString(XmlReader reader)
        {
            if (reader.ReadState != ReadState.Interactive)
            {
                return(string.Empty);
            }
            reader.MoveToElement();
            if (reader.NodeType == XmlNodeType.Element)
            {
                if (reader.IsEmptyElement)
                {
                    return(string.Empty);
                }
                if (!reader.Read())
                {
                    TkDebug.ThrowToolkitException("错误的Xml操作", reader);
                }
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    return(string.Empty);
                }
            }
            string str = string.Empty;

            while (IsTextualNode(reader.NodeType))
            {
                str = str + reader.Value;
                if (!reader.Read())
                {
                    return(str);
                }
            }
            return(str);
        }
Beispiel #2
0
        /// <summary>
        /// 根据类型创建对象
        /// </summary>
        /// <param name="type"></param>
        /// <exception cref="ToolkitException"></exception>
        /// <returns></returns>
        public static object CreateObject(Type type)
        {
            TkDebug.AssertArgumentNull(type, "type", null);

            try
            {
                return(Activator.CreateInstance(type));
            }
            //catch (MissingMethodException ex)
            //{
            //    TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
            //        "没有找到类型{0}的默认构造函数,请确认", type), ex, null);
            //}
            catch (TargetInvocationException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "调用类型{0}的默认构造函数时,发生例外,请调试你的代码", type), ex, null);
            }
            //catch (MethodAccessException ex)
            //{
            //    TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
            //        "类型{0}的默认构造函数访问权限不够", type), ex, null);
            //}
            catch (MemberAccessException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "类型{0}可能是一个抽象类型,无法创建", type), ex, null);
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "调用类型{0}的默认构造函数是发生例外", type), ex, null);
            }
            return(null);
        }
Beispiel #3
0
        private object GetSimpleValue(JsonTextReader reader, object receiver,
                                      ReadSettings settings, ObjectPropertyInfo info, bool autoTrim)
        {
            switch (reader.TokenType)
            {
            case JsonToken.Null:
            case JsonToken.Undefined:
                return(null);

            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.Boolean:
            case JsonToken.String:
                string value = reader.Value.ToString();
                return(SerializerUtil.GetPropertyObject(receiver, settings, info, value, autoTrim));

            case JsonToken.Date:
            case JsonToken.Bytes:
                return(reader.Value);

            default:
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "读取属性{3}时发生JSON错误。当前的状态是{0},不是有效的值状态,在第{1}行,第{2}列",
                                                            reader.TokenType, reader.CurrentLineNumber, reader.CurrentLinePosition,
                                                            info.PropertyName), this);
                return(null);
            }
        }
Beispiel #4
0
        public static WebResponse HttpGet(Uri uri, string contentType)
        {
            TkDebug.AssertArgumentNull(uri, "uri", null);

            WebRequest request = WebRequest.Create(uri);

            TkTrace.LogInfo(uri.ToString());

            try
            {
                WebResponse response = request.GetResponse();
                if (!string.IsNullOrEmpty(contentType))
                {
                    TkDebug.Assert(response.ContentType.Contains(contentType), string.Format(
                                       ObjectUtil.SysCulture, "{0}返回的ContentType是{1},而目标是{2},两者不兼容",
                                       uri, response.ContentType, contentType), null);
                }
                return(response);
            }
            catch (WebException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(
                                                  ObjectUtil.SysCulture, "访问{0}时出错", uri), ex, null);
                return(null);
            }
        }
Beispiel #5
0
        public static void SetValue(PropertyInfo info, object receiver, object value)
        {
            TkDebug.AssertArgumentNull(info, "info", null);
            TkDebug.AssertArgumentNull(receiver, "receiver", null);

            try
            {
                info.SetValue(receiver, value, null);
            }
            catch (System.ArgumentException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "对象{0}未找到属性{1}的 set 访问器或者数组不包含所需类型的参数",
                                                            receiver.GetType(), info.Name), ex, null);
            }
            catch (MemberAccessException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "无法设置对象{0}中属性{1}的值,请检查set的访问权限",
                                                            receiver.GetType(), info.Name), ex, null);
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "对象{0}中可能不存在属性{1},请检查",
                                                            receiver.GetType(), info.Name), ex, null);
            }
        }
Beispiel #6
0
        public static object GetStaticValue(FieldInfo info)
        {
            TkDebug.AssertArgumentNull(info, "info", null);

            try
            {
                return(info.GetValue(null));
            }
            catch (MemberAccessException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "调用方没有访问类型{0}中字段{1}的权限",
                                                            info.DeclaringType, info.Name), ex, null);
            }
            catch (ArgumentException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "类型{0}中既不声明字段{1}也不继承字段{1}",
                                                            info.DeclaringType, info.Name), ex, null);
            }
            catch (NotSupportedException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "类型{0}中字段{1}被标记为文本,但是该字段没有一个可接受的文本类型",
                                                            info.DeclaringType, info.Name), ex, null);
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "对象{0}中字段{1}可能不是静态的,请检查",
                                                            info.DeclaringType, info.Name), ex, null);
            }
            TkDebug.ThrowImpossibleCode(null);
            return(null);
        }
Beispiel #7
0
 private void AssertRead(JsonTextReader reader)
 {
     if (!reader.Read())
     {
         TkDebug.ThrowToolkitException(
             "需要读取Json数据时,却无法读出,请确认数据是否完整", this);
     }
 }
Beispiel #8
0
 private void AssertReadState(JsonTextReader reader, JsonToken token1, JsonToken token2)
 {
     if (reader.TokenType != token1 && reader.TokenType != token2)
     {
         TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                     "Json数据的状态有问题,当前需要的状态是{0}或{1},实际状态却是{2},在第{3}行,第{4}列",
                                                     token1, token2, reader.TokenType, reader.CurrentLineNumber, reader.CurrentLinePosition), this);
     }
 }
Beispiel #9
0
 public static void CheckRequiredContent(BaseObjectAttribute attribute,
                                         Object receiver, ObjectPropertyInfo info, String value)
 {
     if (attribute.Required && string.IsNullOrEmpty(value))
     {
         TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                     "字段{0}标记了required,但是对应的Content没有配置值", info.PropertyName), receiver);
     }
 }
Beispiel #10
0
 private void AssertReadState(JsonTextReader reader, JsonToken token, string propertyName)
 {
     if (reader.TokenType != token)
     {
         string propHint = string.IsNullOrEmpty(propertyName) ? string.Empty :
                           string.Format(ObjectUtil.SysCulture, "分析属性{0}出错:", propertyName);
         TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                     "{3}Json数据的状态有问题,当前需要的状态是{0},实际状态却是{1},在第{2}行,第{3}列",
                                                     token, reader.TokenType, reader.CurrentLineNumber, reader.CurrentLinePosition,
                                                     propHint), this);
     }
 }
Beispiel #11
0
        public string VerfiyGetHostString(string name)
        {
            TkDebug.AssertArgumentNullOrEmpty(name, "name", this);

            string url;

            if (fHosts.TryGetValue(name, out url))
            {
                return(url);
            }

            TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                        "没有在Application.xml中配置名称为{0}的Host", name), this);
            return(null);
        }
Beispiel #12
0
        private void SkipProperty(JsonTextReader reader)
        {
            int depth = reader.Depth;

            AssertRead(reader);
            switch (reader.TokenType)
            {
            case JsonToken.StartObject:
                while (reader.Read())
                {
                    if (reader.TokenType == JsonToken.EndObject && reader.Depth == depth)
                    {
                        break;
                    }
                }
                AssertReadState(reader, JsonToken.EndObject, null);
                break;

            case JsonToken.StartArray:
                while (reader.Read())
                {
                    if (reader.TokenType == JsonToken.EndArray && reader.Depth == depth)
                    {
                        break;
                    }
                }
                AssertReadState(reader, JsonToken.EndArray, null);
                break;

            case JsonToken.Null:
            case JsonToken.Undefined:
            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.String:
            case JsonToken.Boolean:
            case JsonToken.Date:
            case JsonToken.Bytes:
                break;

            default:
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "当前的状态是{0},不是有效的值状态或者对象数组的起始状态,在第{1}行,第{2}列",
                                                            reader.TokenType, reader.CurrentLineNumber, reader.CurrentLinePosition), this);
                break;
            }
            //AssertRead(reader);
        }
Beispiel #13
0
        public bool Add(Type type)
        {
            TkDebug.AssertArgumentNull(type, "type", this);

            var attrs = Attribute.GetCustomAttributes(type, typeof(BasePlugInAttribute), false);
            var attr  = (from item in attrs
                         let plugAttr = item as BasePlugInAttribute
                                        where plugAttr.FactoryName == Name
                                        select plugAttr).FirstOrDefault();

            if (attr == null)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "类型{0}没有标注工厂对应的Attribute,请检查", type), this);
            }
            return(Add(attr, type));
        }
Beispiel #14
0
        //#region IEnumerable<ObjectPropertyInfo> 成员

        //public IEnumerator<ObjectPropertyInfo> GetEnumerator()
        //{
        //    return fElements.Values.GetEnumerator();
        //}

        //#endregion IEnumerable<ObjectPropertyInfo> 成员

        //#region IEnumerable 成员

        //IEnumerator IEnumerable.GetEnumerator()
        //{
        //    return GetEnumerator();
        //}

        //#endregion IEnumerable 成员

        //private void InternalAdd(Type type, PropertyInfo property,
        //    NamedAttribute elementAttribute, string modelName)
        //{
        //    elementAttribute.SetNameMode(modelName, property);
        //    ObjectPropertyInfo item = new ReflectorObjectPropertyInfo(property, elementAttribute, modelName);
        //    QName key = elementAttribute.GetQName(item.LocalName);
        //    try
        //    {
        //        fElements.Add(key, item);
        //        fLocalElements.Add(key.LocalName, item);
        //        ObjectPropertyInfoList list;
        //        if (fProperties.ContainsKey(property))
        //            list = fProperties[property];
        //        else
        //        {
        //            list = new ObjectPropertyInfoList(property, elementAttribute.Required);
        //            fProperties.Add(property, list);
        //        }
        //        list.Add(type, item);
        //    }
        //    catch (Exception ex)
        //    {
        //        TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
        //            "类型{0}的属性{1}中的XmlElementAttribute或者MultipleFlagAttribute的Name(值为{2})已存在,请检查",
        //            type, property.Name, key), ex, type);
        //    }
        //}

        //private void AddAttribute(SimpleElementAttribute elementAttribute, Type type,
        //    PropertyInfo property, string modelName)
        //{
        //    //ElementAttribute attr = elementAttribute as ElementAttribute;
        //    //bool addDefault = attr.DefaultValue != null && !attr.IsMultiple &&
        //    //    attr.GetType() == typeof(XmlElementAttribute);
        //    InternalAdd(type, property, elementAttribute, modelName);
        //}

        private void AddSingleAttrible(Type type, PropertyInfo property,
                                       NamedAttribute elementAttribute, string modelName)
        {
            elementAttribute.SetNameMode(modelName, property);
            ObjectPropertyInfo item = new ReflectorObjectPropertyInfo(property, elementAttribute, modelName);
            QName key = elementAttribute.GetQName(item.LocalName);

            try
            {
                fSingleElements.Add(key, item);
                fSingleLocalElements.Add(key.LocalName, item);
                fElementWriter.Add(new SingleElementWriter(item));
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "类型{0}的属性{1}中的XmlElementAttribute或者MultipleFlagAttribute的Name(值为{2})已存在,请检查",
                                                            type, property.Name, key), ex, type);
            }
        }
Beispiel #15
0
        public static QName GetFullName(string expandedName)
        {
            TkDebug.AssertArgumentNullOrEmpty(expandedName, "expandedName", null);

            if (expandedName[0] != '{')
            {
                return(Get(expandedName));
            }

            int num = expandedName.LastIndexOf('}');

            if ((num <= 1) || (num == (expandedName.Length - 1)))
            {
                TkDebug.ThrowToolkitException(expandedName + "格式错误", null);
            }
            string @namespace = expandedName.Substring(1, num);
            string localName  = expandedName.Substring(num + 1);

            return(new QName(@namespace, localName));
        }
Beispiel #16
0
 public static object CreateObjectWithCtor(Type type)
 {
     TkDebug.AssertArgumentNull(type, "type", null);
     try
     {
         ConstructorInfo[] ctors = type.GetConstructors(FLAGS);
         var ctor = (from item in ctors
                     where item.GetParameters().Length == 0
                     select item).FirstOrDefault();
         TkDebug.AssertNotNull(ctor, string.Format(ObjectUtil.SysCulture,
                                                   "类型{0}没有配置不带参数的构造函数", type), type);
         return(ctor.Invoke(EMPTY));
     }
     catch (TargetInvocationException ex)
     {
         TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                     "调用类型{0}的不带参数的构造函数时,发生例外,请调试你的代码", type), ex, null);
     }
     catch (MemberAccessException ex)
     {
         TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                     "类型{0}可能是一个抽象类型,无法创建", type), ex, null);
     }
     catch (NotSupportedException ex)
     {
         TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                     "类型{0}不支持创建", type), ex, null);
     }
     catch (SecurityException ex)
     {
         TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                     "调用方不具有类型{0}访问权限", type), ex, null);
     }
     catch (Exception ex)
     {
         TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                     "调用类型{0}的不带参数的构造函数是发生例外", type), ex, null);
     }
     return(null);
 }
Beispiel #17
0
        public static object GetValue(PropertyInfo info, object receiver)
        {
            TkDebug.AssertArgumentNull(info, "info", null);
            TkDebug.AssertArgumentNull(receiver, "receiver", null);

            try
            {
                return(info.GetValue(receiver, null));
            }
            catch (MemberAccessException ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "无法从对象{0}中获取属性{1}的值,请检查get的访问权限",
                                                            receiver.GetType(), info.Name), ex, null);
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "对象{0}中可能不存在属性{1},请检查",
                                                            receiver.GetType(), info.Name), ex, null);
            }
            TkDebug.ThrowImpossibleCode(null);
            return(null);
        }
Beispiel #18
0
        /// <summary>
        /// Builds the expression tree from the token queue
        /// </summary>
        /// <returns></returns>
        public Expression BuildTree(Expression scopeParam, bool isCall)
        {
            if (fTokenQueue.Count == 0)
            {
                Parse(scopeParam != null);
            }

            // make a copy of the queue, so that we don't empty the original queue
            var tempQueue = new Queue <Token>(fTokenQueue);
            var exprStack = new Stack <Expression>();
            var args      = new List <Expression>();

            //var literalStack = new Stack<String>();

#if DEBUG
            var q = tempQueue.Select(x => (x.Value ?? "<null>").ToString()
                                     + (x.GetType() == typeof(MemberToken) ? ":" + ((MemberToken)x).Name : ""));
            System.Diagnostics.Debug.WriteLine(string.Join("][", q.ToArray()));
#endif
            int  isCastPending = -1;
            Type typeCast      = null;

            while (tempQueue.Count > 0)
            {
                Token t = tempQueue.Dequeue();
                t.IsCall = isCall && tempQueue.Count == 0;
                if (isCastPending > -1)
                {
                    isCastPending--;
                }
                if (isCastPending == 0)
                {
                    exprStack.Push(Expression.Convert(exprStack.Pop(), typeCast));
                    isCastPending = -1;
                }

                if (t.IsIdent)
                {
                    // handle numeric literals
                    exprStack.Push(Expression.Constant(t.Value, t.Type));
                }
                else if (t.IsType)
                {
                    exprStack.Push(Expression.Constant(t.Value));
                }
                else if (t.IsScope)
                {
                    if (scopeParam == null)
                    {
                        TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                                    "不是期望的标识符 {0}或者作用域为空", t.Value), this);
                    }
                    exprStack.Push(scopeParam);
                }
                else if (t.IsOperator)
                {
                    // handle operators
                    Expression result = null;
                    var        op     = fOperators[(string)t.Value];
                    var        opfunc = OpFuncServiceLocator.Resolve(op.GetType());
                    for (int i = 0; i < t.ArgCount; i++)
                    {
                        args.Add(exprStack.Pop());
                    }
                    // Arguments are in reverse order
                    args.Reverse();
                    result = opfunc(new OpFuncArgs()
                    {
                        TempQueue  = tempQueue,
                        ExprStack  = exprStack,
                        T          = t,
                        Op         = op,
                        Args       = args,
                        ScopeParam = scopeParam,
                        Types      = new List <string>()
                        {
                            "System.Linq"
                        }
                    });
                    args.Clear();
                    exprStack.Push(result);
                }
                else if (t.IsCast)
                {
                    isCastPending = 2;
                    typeCast      = t.Type;
                }
            }

            // we should only have one complete expression on the stack, otherwise, something went wrong
            if (exprStack.Count == 1)
            {
                Expression pop = exprStack.Pop();
#if DEBUG
                System.Diagnostics.Debug.WriteLine(pop.ToString());
#endif
                return(pop);
            }
            else
            {
                TkDebug.ThrowToolkitException("非法的表达式", this);
                return(null);
            }
        }
Beispiel #19
0
 public void WriteComplexContent(ComplexContentAttribute attribute, object writer,
                                 object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
 {
     TkDebug.ThrowToolkitException("Json不支持ComplexContent节点", this);
 }
Beispiel #20
0
 public void ReadComplexContent(ComplexContentAttribute attribute, object reader,
                                object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
 {
     TkDebug.ThrowToolkitException("Json不支持ComplexContent节点", this);
 }
Beispiel #21
0
        /// <summary>
        /// Parses the expression and builds the token queue for compiling
        /// </summary>
        public void Parse(bool isScope = false)
        {
            try
            {
                fTokenQueue.Clear();
                fPtr = 0;

                while (IsInBounds())
                {
                    string op = "";

                    int lastptr = fPtr;

                    if (fPstr[fPtr] != ' ')
                    {
                        // Parse enclosed strings
                        if (fPstr[fPtr] == '\'')
                        {
                            bool isStringClosed = false;
                            fPtr++;
                            lastptr = fPtr;
                            var tokenbuilder = new StringBuilder();

                            // check for escaped single-quote and backslash
                            while (IsInBounds())
                            {
                                if (fPstr[fPtr] == '\\')
                                {
                                    tokenbuilder.Append(fPstr.Substring(lastptr, fPtr - lastptr));
                                    char nextchar = fPstr[fPtr + 1];
                                    switch (nextchar)
                                    {
                                    case '\'':
                                    case '\\':
                                        tokenbuilder.Append(nextchar);
                                        break;

                                    default:
                                        TkDebug.ThrowToolkitException("无法识别的转义字符", this);
                                        break;
                                    }
                                    fPtr++;
                                    fPtr++;
                                    lastptr = fPtr;
                                }
                                else if ((fPstr[fPtr] == '\''))
                                {
                                    isStringClosed = true;
                                    break;
                                }
                                else
                                {
                                    fPtr++;
                                }
                            }

                            if (!isStringClosed)
                            {
                                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                                            "没有关闭的字符串,位置在{0}", lastptr), this);
                            }

                            tokenbuilder.Append(fPstr.Substring(lastptr, fPtr - lastptr));
                            string token = tokenbuilder.ToString();
                            fTokenQueue.Enqueue(new Token()
                            {
                                Value   = token,
                                IsIdent = true,
                                Type    = typeof(string)
                            });
                            fPtr++;
                        }
                        // Parse enclosed dates
                        else if (fPstr[fPtr] == '#')
                        {
                            bool isDateClosed = false;

                            fPtr++;
                            lastptr = fPtr;

                            while (IsInBounds())
                            {
                                fPtr++;
                                if (fPstr[fPtr] == '#')
                                {
                                    isDateClosed = true;
                                    break;
                                }
                            }

                            if (!isDateClosed)
                            {
                                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                                            "未关闭的日期,位置在{0}", lastptr), this);
                            }

                            string token = fPstr.Substring(lastptr, fPtr - lastptr);

                            DateTime dt;
                            if (token == "Now")
                            {
                                dt = DateTime.Now;
                            }
                            else
                            {
                                dt = DateTime.Parse(token, ObjectUtil.SysCulture);
                            }

                            fTokenQueue.Enqueue(new Token()
                            {
                                Value   = dt,
                                IsIdent = true,
                                Type    = typeof(DateTime)
                            });
                            fPtr++;
                        }
                        // ArgSeparator
                        else if (fPstr[fPtr] == ',')
                        {
                            bool pe = false;

                            while (fOpStack.Count > 0)
                            {
                                if ((string)fOpStack.Peek().Value == "(")
                                {
                                    OpToken temp      = fOpStack.Pop();
                                    Token   lastToken = fOpStack.Peek();
                                    if (lastToken.GetType() == typeof(MemberToken))
                                    {
                                        MemberToken lastmember = (MemberToken)lastToken;
                                        if (lastmember != null)
                                        {
                                            lastmember.ArgCount++;
                                        }
                                    }
                                    fOpStack.Push(temp);
                                    pe = true;
                                    break;
                                }
                                else
                                {
                                    OpToken popToken = fOpStack.Pop();
                                    fTokenQueue.Enqueue(popToken);
                                }
                            }

                            if (!pe)
                            {
                                TkDebug.ThrowToolkitException("括号不匹配", this);
                            }

                            fPtr++;
                        }
                        // Member accessor
                        else if (fPstr[fPtr] == '.')
                        {
                            if (fOpStack.Count > 0)
                            {
                                OpToken sc = fOpStack.Peek();
                                // if the last operator was also a Member accessor pop it on the tokenQueue
                                if ((string)sc.Value == ".")
                                {
                                    OpToken popToken = fOpStack.Pop();
                                    fTokenQueue.Enqueue(popToken);
                                }
                            }

                            fOpStack.Push(new MemberToken());
                            fPtr++;
                        }
                        // Parse hexadecimal literals
                        else if (HelperMethods.IsHexStart(fPstr, fPtr))
                        {
                            bool isNeg = false;
                            if (fPstr[fPtr] == '-')
                            {
                                isNeg = true;
                                fPtr++;
                                lastptr = fPtr;
                            }
                            //skip 0x
                            fPtr += 2;
                            // Number identifiers start with a number and may contain numbers and decimals
                            while (IsInBounds() && (HelperMethods.IsHex(fPstr, fPtr) || fPstr[fPtr] == 'L'))
                            {
                                fPtr++;
                            }

                            string token = fPstr.Substring(lastptr, fPtr - lastptr);

                            Type   ntype = typeof(System.Int32);
                            object val   = null;

                            if (token.EndsWith("L", StringComparison.CurrentCulture))
                            {
                                ntype = typeof(System.Int64);
                                token = token.Remove(token.Length - 1, 1);
                            }

                            switch (ntype.Name)
                            {
                            case "Int32":
                                val = isNeg ? -Convert.ToInt32(token, 16) : Convert.ToInt32(token, 16);
                                break;

                            case "Int64":
                                val = isNeg ? -Convert.ToInt64(token, 16) : Convert.ToInt64(token, 16);
                                break;
                            }

                            fTokenQueue.Enqueue(new Token()
                            {
                                Value   = val,
                                IsIdent = true,
                                Type    = ntype
                            });
                        }
                        // Parse numbers
                        else if (HelperMethods.IsANumber(fPstr, fPtr))
                        {
                            bool isDecimal    = false;
                            int  suffixLength = 0;

                            // Number identifiers start with a number and may contain numbers and decimals
                            while (IsInBounds())
                            {
                                if (fPstr[fPtr] == 'l' || fPstr[fPtr] == 'L' ||
                                    fPstr[fPtr] == 'u' || fPstr[fPtr] == 'U')
                                {
                                    if (isDecimal)
                                    {
                                        TkDebug.ThrowToolkitException("不是期望的decimal结束符", this);
                                    }

                                    //if (suffixLength == 0) suffixStart = _ptr;
                                    if (suffixLength == 1)
                                    {
                                        fPtr++;
                                        break;
                                    }
                                    suffixLength++;
                                }
                                else if (fPstr[fPtr] == '.')
                                {
                                    if (isDecimal)
                                    {
                                        break;
                                    }
                                    isDecimal = true;
                                }
                                else if (fPstr[fPtr] == 'd' || fPstr[fPtr] == 'D' ||
                                         fPstr[fPtr] == 'f' || fPstr[fPtr] == 'F' ||
                                         fPstr[fPtr] == 'm' || fPstr[fPtr] == 'M')
                                {
                                    suffixLength++;
                                    fPtr++;
                                    break;
                                }
                                else if (!HelperMethods.IsANumber(fPstr, fPtr))
                                {
                                    break;
                                }
                                fPtr++;
                            }

                            string token  = fPstr.Substring(lastptr, fPtr - lastptr);
                            string suffix = "";

                            Type   ntype = null;
                            object val   = null;

                            if (suffixLength > 0)
                            {
                                suffix = token.Substring(token.Length - suffixLength);
                                token  = token.Substring(0, token.Length - suffixLength);

                                switch (suffix.ToLower(ObjectUtil.SysCulture))
                                {
                                case "d":
                                    ntype = typeof(Double);
                                    val   = double.Parse(token, CultureInfo.InvariantCulture);
                                    break;

                                case "f":
                                    ntype = typeof(Single);
                                    val   = float.Parse(token, CultureInfo.InvariantCulture);
                                    break;

                                case "m":
                                    ntype = typeof(Decimal);
                                    val   = decimal.Parse(token, CultureInfo.InvariantCulture);
                                    break;

                                case "l":
                                    ntype = typeof(Int64);
                                    val   = long.Parse(token, CultureInfo.InvariantCulture);
                                    break;

                                case "u":
                                    ntype = typeof(UInt32);
                                    val   = uint.Parse(token, CultureInfo.InvariantCulture);
                                    break;

                                case "ul":
                                case "lu":
                                    ntype = typeof(UInt64);
                                    val   = ulong.Parse(token, CultureInfo.InvariantCulture);
                                    break;
                                }
                            }
                            else
                            {
                                if (isDecimal)
                                {
                                    ntype = typeof(Double);
                                    val   = double.Parse(token, CultureInfo.InvariantCulture);
                                }
                                else
                                {
                                    ntype = typeof(Int32);
                                    val   = int.Parse(token, CultureInfo.InvariantCulture);
                                }
                            }


                            fTokenQueue.Enqueue(new Token()
                            {
                                Value   = val,
                                IsIdent = true,
                                Type    = ntype
                            });
                        }
                        // Test for identifier
                        else if (HelperMethods.IsAlpha(fPstr[fPtr]) || (fPstr[fPtr] == '_'))
                        {
                            fPtr++;

                            while (IsInBounds() && (HelperMethods.IsAlpha(fPstr[fPtr]) ||
                                                    (fPstr[fPtr] == '_') || HelperMethods.IsNumeric(fPstr, fPtr)))
                            {
                                fPtr++;
                            }

                            string token = fPstr.Substring(lastptr, fPtr - lastptr);


                            MemberToken mToken = null;

                            if (fOpStack.Count > 0)
                            {
                                OpToken opToken = fOpStack.Peek();
                                if (opToken.GetType() == typeof(MemberToken))
                                {
                                    mToken = (MemberToken)opToken;
                                }
                            }

                            if ((mToken != null) && (mToken.Name == null))
                            {
                                mToken.Name = token;
                            }
                            else if (TypeRegistry.ContainsKey(token))
                            {
                                if (TypeRegistry[token].GetType().Name == "RuntimeType")
                                {
                                    fTokenQueue.Enqueue(new Token()
                                    {
                                        Value  = ((Type)TypeRegistry[token]).UnderlyingSystemType,
                                        IsType = true
                                    });
                                }
                                else
                                {
                                    fTokenQueue.Enqueue(new Token()
                                    {
                                        Value  = TypeRegistry[token],
                                        IsType = true
                                    });
                                }
                            }
                            else
                            {
                                if ((token == "null"))
                                {
                                    fTokenQueue.Enqueue(new Token()
                                    {
                                        Value   = null,
                                        IsIdent = true,
                                        Type    = typeof(object)
                                    });
                                }
                                else if ((token == "true") || (token == "false"))
                                {
                                    fTokenQueue.Enqueue(new Token()
                                    {
                                        Value   = Boolean.Parse(token),
                                        IsIdent = true,
                                        Type    = typeof(Boolean)
                                    });
                                }
                                else
                                {
                                    if (Global != null)
                                    {
                                        fTokenQueue.Enqueue(new Token()
                                        {
                                            Value = Global, IsType = true
                                        });
                                    }
                                    else
                                    {
                                        if (isScope)
                                        {
                                            fTokenQueue.Enqueue(new Token()
                                            {
                                                IsScope = true
                                            });
                                        }
                                        else
                                        {
                                            //_tokenQueue.Enqueue(new Token() { IsIdent = true, Value = token });
                                            TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                                                        "未知的类型或标识符'{0}'", token), this);
                                        }
                                    }

                                    if (fOpStack.Count > 0)
                                    {
                                        OpToken sc = fOpStack.Peek();
                                        // if the last operator was also a Member accessor pop it on the tokenQueue
                                        if ((string)sc.Value == ".")
                                        {
                                            OpToken popToken = fOpStack.Pop();
                                            fTokenQueue.Enqueue(popToken);
                                        }
                                    }

                                    fOpStack.Push(new MemberToken());
                                    fPtr -= token.Length;
                                }
                            }
                        }
                        else if (fPstr[fPtr] == '[')
                        {
                            fOpStack.Push(new OpToken()
                            {
                                Value = "[",
                                Ptr   = fPtr + 1
                            });
                            fPtr++;
                        }
                        else if (fPstr[fPtr] == ']')
                        {
                            bool pe = false;
                            // Until the token at the top of the stack is a left bracket,
                            // pop operators off the stack onto the output queue
                            while (fOpStack.Count > 0)
                            {
                                OpToken sc = fOpStack.Peek();
                                if ((string)sc.Value == "[")
                                {
                                    OpToken temp = fOpStack.Pop();
                                    if (fOpStack.Count > 0)
                                    {
                                        Token lastToken = fOpStack.Peek();
                                        if (lastToken.GetType() == typeof(MemberToken))
                                        {
                                            MemberToken lastmember = (MemberToken)lastToken;
                                            // check if there was anything significant between the opening paren and the closing paren
                                            // If so, then we have an argument... This isn't the best approach perhaps, but it works...
                                            if (fPstr.Substring(sc.Ptr, fPtr - sc.Ptr).Trim().Length > 0)
                                            {
                                                lastmember.ArgCount++;
                                            }
                                        }
                                    }
                                    fOpStack.Push(temp);
                                    pe = true;
                                    break;
                                }
                                else
                                {
                                    OpToken popToken = fOpStack.Pop();
                                    fTokenQueue.Enqueue(popToken);
                                }
                            }

                            // If the stack runs out without finding a left parenthesis, then there are mismatched parentheses.
                            if (!pe)
                            {
                                TkDebug.ThrowToolkitException("括号不匹配", this);
                            }

                            // Pop the left parenthesis from the stack, but not onto the output queue.
                            fOpStack.Pop();
                            //tokenQueue.Enqueue(lopToken);


                            fPtr++;
                        }
                        else if (fPstr[fPtr] == '(')
                        {
                            int curptr        = fPtr;
                            int depth         = 0;
                            var containsComma = false;

                            while (IsInBounds())
                            {
                                if (fPstr[fPtr] == '(')
                                {
                                    depth++;
                                }
                                if (fPstr[fPtr] == ')')
                                {
                                    depth--;
                                }
                                if (fPstr[fPtr] == ',')
                                {
                                    containsComma = true;
                                }
                                fPtr++;
                                if (depth == 0)
                                {
                                    break;
                                }
                            }

                            fPtr--;

                            if (depth != 0)
                            {
                                TkDebug.ThrowToolkitException("括号不匹配", this);
                            }

                            string token = fPstr.Substring(lastptr + 1, fPtr - lastptr - 1).Trim();

                            Type t;

                            bool isCast = false;

                            if (!containsComma)
                            {
                                if (TypeRegistry.ContainsKey(token))
                                {
                                    fTokenQueue.Enqueue(new Token()
                                    {
                                        Value  = "(" + token + ")",
                                        IsCast = true,
                                        Type   = (Type)TypeRegistry[token]
                                    });
                                    //_ptr = curptr + 1;
                                    isCast = true;
                                }
                                else if ((t = Type.GetType(token)) != null)
                                {
                                    fTokenQueue.Enqueue(new Token()
                                    {
                                        Value  = "(" + t.Name + ")",
                                        IsCast = true,
                                        Type   = t
                                    });
                                    // _ptr = curptr + 1;
                                    isCast = true;
                                }
                            }

                            if (!isCast)
                            {
                                fOpStack.Push(new OpToken()
                                {
                                    Value = "(",
                                    Ptr   = curptr + 1
                                });

                                fPtr = curptr + 1;
                            }
                        }
                        else if (fPstr[fPtr] == ')')
                        {
                            bool pe = false;
                            //int poppedtokens = 0;
                            // Until the token at the top of the stack is a left parenthesis,
                            // pop operators off the stack onto the output queue
                            while (fOpStack.Count > 0)
                            {
                                OpToken sc = fOpStack.Peek();
                                if ((string)sc.Value == "(")
                                {
                                    OpToken temp = fOpStack.Pop();
                                    if (fOpStack.Count > 0)
                                    {
                                        Token lastToken = fOpStack.Peek();
                                        if (lastToken.GetType() == typeof(MemberToken))
                                        {
                                            MemberToken lastmember = (MemberToken)lastToken;
                                            // check if there was anything significant between the opening paren and the closing paren
                                            // If so, then we have an argument... This isn't the best approach perhaps, but it works...
                                            if (fPstr.Substring(sc.Ptr, fPtr - sc.Ptr).Trim().Length > 0)
                                            {
                                                lastmember.ArgCount++;
                                            }
                                        }
                                    }
                                    fOpStack.Push(temp);
                                    pe = true;
                                    break;
                                }
                                else
                                {
                                    OpToken popToken = fOpStack.Pop();
                                    fTokenQueue.Enqueue(popToken);
                                    // poppedtokens++;
                                }
                            }

                            // If the stack runs out without finding a left parenthesis, then there are mismatched parentheses.
                            if (!pe)
                            {
                                TkDebug.ThrowToolkitException("括号不匹配", this);
                            }

                            // Pop the left parenthesis from the stack, but not onto the output queue.
                            fOpStack.Pop();

                            //If the token at the top of the stack is a function token, pop it onto the output queue.
                            if (fOpStack.Count > 0)
                            {
                                OpToken popToken = fOpStack.Peek();
                                if ((string)popToken.Value == ".")
                                {
                                    popToken            = fOpStack.Pop();
                                    popToken.IsFunction = true;
                                    fTokenQueue.Enqueue(popToken);
                                }
                            }
                            fPtr++;
                        }
                        //else if (_pstr[_ptr] == '=' && _pstr[_ptr + 1] == '>')
                        //{
                        //    _ptr++;
                        //    _ptr++;
                        //}
                        else if ((op = fOperators.IsOperator(fPstr, ref fPtr)) != null)
                        {
                            while (fOpStack.Count > 0)
                            {
                                OpToken sc = fOpStack.Peek();

                                if (fOperators.IsOperator((string)sc.Value) &&
                                    ((fOperators[op].LeftAssoc &&
                                      (fOperators[op].Precedence <= fOperators[(string)sc.Value].Precedence)) ||
                                     (fOperators[op].Precedence < fOperators[(string)sc.Value].Precedence))
                                    )
                                {
                                    OpToken popToken = fOpStack.Pop();
                                    fTokenQueue.Enqueue(popToken);
                                }
                                else
                                {
                                    break;
                                }
                            }

                            fOpStack.Push(new OpToken()
                            {
                                Value = op
                            });
                            fPtr++;
                        }
                        else
                        {
                            TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                                        "不是期望的标识符 '{0}'", fPstr[fPtr]), this);
                        }
                    }
                    else
                    {
                        fPtr++;
                    }
                }

                while (fOpStack.Count > 0)
                {
                    OpToken sc = fOpStack.Peek();
                    if ((string)sc.Value == "(" || (string)sc.Value == ")")
                    {
                        TkDebug.ThrowToolkitException("括号不匹配", this);
                    }

                    sc = fOpStack.Pop();
                    fTokenQueue.Enqueue(sc);
                }
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(String.Format(ObjectUtil.SysCulture,
                                                            "分析错误,位置在{0}: {1}", fPtr, ex.Message), ex, this);
            }
        }