当前位置: 首页>>代码示例>>C#>>正文


C# TypeSpec.AddName方法代码示例

本文整理汇总了C#中TypeSpec.AddName方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSpec.AddName方法的具体用法?C# TypeSpec.AddName怎么用?C# TypeSpec.AddName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TypeSpec的用法示例。


在下文中一共展示了TypeSpec.AddName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

        static TypeSpec Parse(string typeName, ref int p, bool is_recurse, bool allow_aqn)
        {
            int pos = p;
            int name_start;
            bool in_modifiers = false;
            TypeSpec data = new TypeSpec();

            SkipSpace(typeName, ref pos);

            name_start = pos;

            for (; pos < typeName.Length; ++pos)
            {
                switch (typeName[pos])
                {
                    case '+':
                        data.AddName(typeName.Substring(name_start, pos - name_start));
                        name_start = pos + 1;
                        break;
                    case ',':
                    case ']':
                        data.AddName(typeName.Substring(name_start, pos - name_start));
                        name_start = pos + 1;
                        in_modifiers = true;
                        if (is_recurse && !allow_aqn)
                        {
                            p = pos;
                            return data;
                        }
                        break;
                    case '&':
                    case '*':
                    case '[':
                        if (typeName[pos] != '[' && is_recurse)
                            throw new ArgumentException("Generic argument can't be byref or pointer type", "typeName");
                        data.AddName(typeName.Substring(name_start, pos - name_start));
                        name_start = pos + 1;
                        in_modifiers = true;
                        break;
                }
                if (in_modifiers)
                    break;
            }

            if (name_start < pos)
                data.AddName(typeName.Substring(name_start, pos - name_start));

            if (in_modifiers)
            {
                for (; pos < typeName.Length; ++pos)
                {

                    switch (typeName[pos])
                    {
                        case '&':
                            if (data.is_byref)
                                throw new ArgumentException("Can't have a byref of a byref", "typeName");

                            data.is_byref = true;
                            break;
                        case '*':
                            if (data.is_byref)
                                throw new ArgumentException("Can't have a pointer to a byref type", "typeName");
                            ++data.pointer_level;
                            break;
                        case ',':
                            if (is_recurse)
                            {
                                int end = pos;
                                while (end < typeName.Length && typeName[end] != ']')
                                    ++end;
                                if (end >= typeName.Length)
                                    throw new ArgumentException("Unmatched ']' while parsing generic argument assembly name");
                                data.assembly_name = typeName.Substring(pos + 1, end - pos - 1).Trim();
                                p = end + 1;
                                return data;
                            }
                            data.assembly_name = typeName.Substring(pos + 1).Trim();
                            pos = typeName.Length;
                            break;
                        case '[':
                            if (data.is_byref)
                                throw new ArgumentException("Byref qualifier must be the last one of a type", "typeName");
                            ++pos;
                            if (pos >= typeName.Length)
                                throw new ArgumentException("Invalid array/generic spec", "typeName");
                            SkipSpace(typeName, ref pos);

                            if (typeName[pos] != ',' && typeName[pos] != '*' && typeName[pos] != ']')
                            {//generic args
                                List<TypeSpec> args = new List<TypeSpec>();
                                if (data.IsArray)
                                    throw new ArgumentException("generic args after array spec", "typeName");

                                while (pos < typeName.Length)
                                {
                                    SkipSpace(typeName, ref pos);
                                    bool aqn = typeName[pos] == '[';
                                    if (aqn)
                                        ++pos; //skip '[' to the start of the type
//.........这里部分代码省略.........
开发者ID:daszat,项目名称:zetbox,代码行数:101,代码来源:TypeNameParser.cs


注:本文中的TypeSpec.AddName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。