Beispiel #1
0
        static TypeName ConvertGenericType(Type type)
        {
            if (type.GetTypeInfo().IsGenericTypeDefinition)
            {
                DefaultTypeName result;
                int             skipCount;
                string          plainName = StripMangle(type.Name);

                if (type.DeclaringType == null)
                {
                    result = new DefaultTypeName(
                        AssemblyName.FromAssemblyName(type.GetTypeInfo().Assembly.GetName()),
                        plainName,
                        type.Namespace);
                    skipCount = 0;
                }
                else
                {
                    var declaring = FromType(type.DeclaringType);
                    result    = new DefaultTypeName(plainName, (DefaultTypeName)declaring);
                    skipCount = declaring.GenericParameterCount;
                }

                var gen = type.GetGenericArguments().Skip(skipCount).Select(
                    (t, i) => GenericParameterName.New(result, i, t.Name)).ToArray();
                result.FinalizeGenerics(gen);

                return(result);
            }

            var args = type.GetGenericArguments().Select(FromType);

            return(FromType(type.GetGenericTypeDefinition()).MakeGenericType(args));
        }
Beispiel #2
0
        internal static TypeName ParseQualifiedType(string ident)
        {
            var match = QUALIFIED_TYPE.Match(ident);

            if (!match.Success)
            {
                match = IMPLIED_NESTED_QUALIFIED_TYPE.Match(ident);
            }
            if (!match.Success)
            {
                throw new NotImplementedException();
            }

            int      sz; // of generics
            string   name   = TypeName.StripMangle(match.Groups["Type"].Value, out sz);
            TypeName result = new DefaultTypeName(null,
                                                  name,
                                                  match.Groups["Namespace"].Value.Trim('.'),
                                                  sz);

            var nestedTypes = match.Groups["Nested"].Value.Trim('.');

            if (nestedTypes.Length > 0)
            {
                foreach (var nested in nestedTypes.Split(new [] { '+', '/' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    result = result.GetNestedType(nested);
                }
            }

            return(result);
        }
Beispiel #3
0
        public static DefaultTypeName FromFullName(string ns,
                                                   string name,
                                                   AssemblyName assembly = null)
        {
            int mangle;

            name = TypeName.StripMangle(name, out mangle);
            var result = new DefaultTypeName(assembly, name, ns);

            result.FinalizeGenerics(mangle);
            return(result);
        }
Beispiel #4
0
        private void CopyGenericsTo(DefaultTypeName result)
        {
            if (_genericParameters != null)
            {
                int baseCount = DeclaringType == null ? 0 : DeclaringType.GenericParameterCount;
                var generics  = _genericParameters
                                .Where(t => !(t is RedirectedGenericParameterName))
                                .Select((t, i) => GenericParameterName.New(result, baseCount + i, t.Name)).ToArray();

                result.FinalizeGenerics(generics);
            }
        }
Beispiel #5
0
        public TypeName GetType(string ns, string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw Failure.EmptyString("name");
            }

            return(DefaultTypeName.FromFullName(ns, name, this));
        }
Beispiel #6
0
        public override bool Matches(TypeName name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.IsTypeSpecification)
            {
                return(false);
            }
            DefaultTypeName other = (DefaultTypeName)name;

            return(Name == other.Name &&
                   NamespaceName.SafeMatch(NamespaceName, name.NamespaceName) &&
                   TypeName.SafeMatch(DeclaringType, name.DeclaringType));
        }
Beispiel #7
0
        internal DefaultTypeName(string name,
                                 DefaultTypeName declaringType) : base(declaringType)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw Failure.EmptyString("name");
            }

            _fullName = string.Concat(
                DeclaringType.FullName, '+', name);

            _name     = name;
            _assembly = declaringType.Assembly;
        }
Beispiel #8
0
        private TypeName UpdateCore(string ns, AssemblyName assembly)
        {
            ns = ns ?? string.Empty;
            DefaultTypeName result;

            if (DeclaringType == null)
            {
                result = new DefaultTypeName(assembly, _name, ns);
            }
            else
            {
                var decl = DeclaringType
                           .WithAssembly(assembly)
                           .WithNamespace(ns);
                result = new DefaultTypeName(_name, (DefaultTypeName)decl);
            }
            CopyGenericsTo(result);
            return(result);
        }
Beispiel #9
0
        protected override MemberName WithDeclaringTypeOverride(TypeName declaringType)
        {
            if (declaringType.IsTypeSpecification)
            {
                var git = declaringType as GenericInstanceTypeName;
                if (git != null)
                {
                    declaringType = git.ElementType;
                }
                else
                {
                    throw DotNetFailure.NotSupportedBySpecifications();
                }
            }

            var result = new DefaultTypeName(_name, (DefaultTypeName)declaringType);

            CopyGenericsTo(result);
            return(result);
        }