private TypeSignature BuildType(TypeSignature typeSig, List <TypeSignature> genericArguments)
        {
            switch (typeSig.ElementCode)
            {
            case TypeElementCode.Array:
            {
                var arrayType   = (ArrayType)typeSig;
                var elementType = BuildType(typeSig.ElementType, genericArguments);
                return(new ArrayType(elementType, arrayType.ArrayDimensions));
            }

            case TypeElementCode.ByRef:
            {
                var elementType = BuildType(typeSig.ElementType, genericArguments);
                return(new ByRefType(elementType));
            }

            case TypeElementCode.CustomModifier:
            {
                return(BuildType(typeSig.ElementType, genericArguments));
            }

            case TypeElementCode.FunctionPointer:
                return(typeSig);

            case TypeElementCode.GenericParameter:
            {
                int count = genericArguments.Count;
                genericArguments.Add(typeSig);
                return(new GenericParameterType(true, count));
            }

            case TypeElementCode.GenericType:
            {
                int count = genericArguments.Count;
                genericArguments.Add(typeSig);
                return(new GenericParameterType(true, count));
            }

            case TypeElementCode.Pinned:
            {
                var elementType = BuildType(typeSig.ElementType, genericArguments);
                return(new PinnedType(elementType));
            }

            case TypeElementCode.Pointer:
                return(typeSig);

            case TypeElementCode.DeclaringType:
            {
                if (typeSig.GetTypeCode(_module) != PrimitiveTypeCode.Void)
                {
                    int count = genericArguments.Count;
                    genericArguments.Add(typeSig);
                    return(new GenericParameterType(true, count));
                }
                else
                {
                    return(typeSig);
                }
            }

            default:
                throw new InvalidOperationException();
            }
        }