Ejemplo n.º 1
0
        /// <summary>
        /// Parses the type signature.
        /// </summary>
        private Type parseTypeSignature(TypeSignature signature)
        {
            try
            {
                if (!string.IsNullOrEmpty(signature.Postfix))
                {
                    return(processPostfix(parseTypeSignature(signature.Arguments[0]), signature.Postfix));
                }

                var name    = signature.Name;
                var hasArgs = signature.Arguments != null && signature.Arguments.Length > 0;
                if (hasArgs)
                {
                    name += "`" + signature.Arguments.Length;
                }

                if (TypeAliases.ContainsKey(name))
                {
                    return(TypeAliases[name]);
                }

                var type = findType(name);
                return(hasArgs
                                        ? GenericHelper.MakeGenericTypeChecked(type, signature.Arguments.Select(parseTypeSignature).ToArray())
                                        : type);
            }
            catch (ArgumentException ex)
            {
                throw new LensCompilerException(ex.Message, signature);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Wraps a type into a specific postfix.
        /// </summary>
        private static Type processPostfix(Type type, string postfix)
        {
            if (postfix == "[]")
            {
                return(type.MakeArrayType());
            }

            if (postfix == "~")
            {
                return(GenericHelper.MakeGenericTypeChecked(typeof(IEnumerable <>), type));
            }

            if (postfix == "?")
            {
                return(GenericHelper.MakeGenericTypeChecked(typeof(Nullable <>), type));
            }

            throw new ArgumentException(string.Format("Unknown postfix '{0}'!", postfix));
        }