Example #1
0
 /// <summary>
 /// Used to create a NormalType to take advantage of caching (avoid parsing more than once)
 /// </summary>
 /// <param name="typeString">String representing the CLR type.</param>
 /// <returns>A NormalType instance</returns>
 public static NormalType CreateNormalType(string typeString)
 {
     if (string.IsNullOrEmpty(typeString))
     {
         return(null);
     }
     typeString = typeString.Replace('{', '<').Replace('}', '>').Replace("``", "");
     if (CachedTypes.TryGetValue(typeString, out var val))
     {
         return(val);
     }
     else
     {
         NormalType ret = new NormalType(typeString);
         CachedTypes[typeString] = ret;
         return(ret);
     }
 }
Example #2
0
        private IEnumerable <NormalType> _GetSubTypes()
        {
            if (string.IsNullOrWhiteSpace(_GenericTypeString))
            {
                yield break;
            }

            string genericString = _GenericTypeString;
            string nestStr       = "";
            int    nestLevel     = 0;

            for (int i = 0; i < genericString.Length; i++)
            {
                char ch = genericString[i];
                if (ch == '<')
                {
                    nestLevel++;
                    nestStr += "<";         //if we're in a sub-nest, keep the < ie, the second < in "List<List<int>>" but not the first <
                }
                else if (ch == '>')
                {
                    nestLevel--;
                    nestStr += ">";
                }
                else if (ch == ',' && nestLevel == 0)
                {
                    yield return(NormalType.CreateNormalType(nestStr));          //generate our generic type link

                    nestStr = "";
                }
                else if (ch == ' ')
                { //do nothing, ignore spaces
                }
                else
                {
                    nestStr += ch.ToString();
                }
            }
            if (!string.IsNullOrEmpty(nestStr))
            {
                yield return(NormalType.CreateNormalType(nestStr));
            }
        }
Example #3
0
        /// <summary>
        /// Gets the method parameter type names from the member name.
        /// </summary>
        /// <returns>The method parameter type name list.</returns>
        /// <example>
        /// It will prepend the type kind character (<c>T:</c>) to the type string.
        /// <para>For <c>(System.String,System.Int32)</c>, returns <c>["T:System.String","T:System.Int32"]</c>.</para>
        /// It also handle generic type.
        /// <para>For <c>(System.Collections.Generic.IEnumerable{System.String})</c>, returns <c>["T:System.Collections.Generic.IEnumerable{System.String}"]</c>.</para>
        /// </example>
        public IEnumerable <NormalType> GetParamTypes()
        {
            if (_ParamTypes.Any())              //using the "new" stuff, get the parameter types from the param tags
            {
                return(_ParamTypes.Select(x => NormalType.CreateNormalType(x)));
            }
            else if (!_Name.Contains('('))      //if there's no parameters (non method/constructor)
            {
                return(Enumerable.Empty <NormalType>());
            }
            else
            {
                string paramString = _Name.Split('(').Last().Trim(')');

                int    delta = 0;
                string ret   = "";
                var    list  = new List <string>();

                foreach (var ch in paramString)
                {
                    if (ch == '{')
                    {
                        delta++;
                    }
                    else if (ch == '}')
                    {
                        delta--;
                    }
                    else if (ch != ',' || delta != 0)
                    {
                        ret += ch.ToString();
                    }
                    else if (delta == 0 && ch == ',')
                    {
                        list.Add(ret);
                        ret = "";
                    }
                }

                return(list.Select(x => NormalType.CreateNormalType(x)));
            }
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ParamUnit"/> class.
 /// </summary>
 /// <param name="element">The param XML element.</param>
 /// <param name="paramType">The parameter type corresponding to the param XML element.</param>
 /// <exception cref="ArgumentException">Throw if XML element name is not <c>param</c>.</exception>
 internal ParamUnit(XElement element, NormalType paramType, MemberName parentName) : base(element, "param", parentName)
 {
     _ParamType = paramType;
 }