public void when_adding_assembly_then_adds_all_ids_from_used_types()
        {
            var map = new MemberIdMap();
            map.Add(Assembly.LoadFrom(assemblyFile));

            map.idToMemberMap.ToList().ForEach(pair => Console.WriteLine("{0} : {1}", pair.Key, pair.Value));
        }
Beispiel #2
0
        // TODO: support multiple assemblies.
        public static IEnumerable<Member> ReadMembers(Assembly assembly)
        {
            var fileName = Path.ChangeExtension(assembly.Location, ".xml");
            if (!File.Exists(fileName))
                throw new FileNotFoundException("Could not find documentation file to load.", fileName);

            var doc = XDocument.Load(fileName);
            var map = new MemberIdMap();
            map.Add(assembly);

            return doc.Root.Element("members").Elements("member")
                .Select(element => CreateMember(element.Attribute("name").Value, ReadContent(element)))
                .Select(member => ReplaceExtensionMethods(member, map))
                .Select(member => ReplaceTypes(member, map))
                .Select(member => SetInfo(member, map));
        }
Beispiel #3
0
        // TODO: support multiple assemblies.
        public static IEnumerable <Member> ReadMembers(Assembly assembly)
        {
            var fileName = Path.ChangeExtension(assembly.Location, ".xml");

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("Could not find documentation file to load.", fileName);
            }

            var doc = XDocument.Load(fileName);
            var map = new MemberIdMap();

            map.Add(assembly);

            return(doc.Root.Element("members").Elements("member")
                   .Select(element => CreateMember(element.Attribute("name").Value, ReadContent(element)))
                   .Select(member => ReplaceExtensionMethods(member, map))
                   .Select(member => ReplaceTypes(member, map))
                   .Select(member => SetInfo(member, map)));
        }
Beispiel #4
0
        private static Member ReplaceTypes(Member member, MemberIdMap map)
        {
            if (member.Kind != MemberKinds.Type)
            {
                return(member);
            }

            var type = (Type)map.GetOrDefault(member.ToString());

            if (type == null)
            {
                return(member);
            }

            var nestingTypeId = "";

            if (type.DeclaringType != null &&
                !string.IsNullOrEmpty((nestingTypeId = map.GetOrDefault(type.DeclaringType))))
            {
                return(new NestedType(member.ToString(), nestingTypeId, member.Elements));
            }

            if (type.IsInterface)
            {
                return(new Interface(member.ToString(), member.Elements));
            }
            if (type.IsClass)
            {
                return(new Class(member.ToString(), member.Elements));
            }
            if (type.IsEnum)
            {
                return(new Enum(member.ToString(), member.Elements));
            }
            if (type.IsValueType)
            {
                return(new Struct(member.ToString(), member.Elements));
            }

            return(member);
        }
Beispiel #5
0
        private static Member SetInfo(Member member, MemberIdMap map)
        {
            member.Info = map.GetOrDefault(member.ToString());

            return(member);
        }
Beispiel #6
0
        private static Member SetInfo(Member member, MemberIdMap map)
        {
            member.Info = map.GetOrDefault(member.ToString());

            return member;
        }
Beispiel #7
0
        private static Member ReplaceTypes(Member member, MemberIdMap map)
        {
            if (member.Kind != MemberKinds.Type)
                return member;

            var type = (Type)map.GetOrDefault(member.ToString());
            if (type == null)
                return member;

            var nestingTypeId = "";
            if (type.DeclaringType != null &&
                !string.IsNullOrEmpty((nestingTypeId = map.GetOrDefault(type.DeclaringType))))
                return new NestedType(member.ToString(), nestingTypeId, member.Elements);

            if (type.IsInterface)
                return new Interface(member.ToString(), member.Elements);
            if (type.IsClass)
                return new Class(member.ToString(), member.Elements);
            if (type.IsEnum)
                return new Enum(member.ToString(), member.Elements);
            if (type.IsValueType)
                return new Struct(member.ToString(), member.Elements);

            return member;
        }
Beispiel #8
0
        private static Member ReplaceExtensionMethods(Member member, MemberIdMap map)
        {
            if (member.Kind != MemberKinds.Method)
                return member;

            var method = (MethodBase)map.GetOrDefault(member.ToString());
            if (method == null)
                return member;

            if (method.GetCustomAttributes(true).Any(attr => attr.GetType().FullName == "System.Runtime.CompilerServices.ExtensionAttribute"))
            {
                var extendedTypeId = map.GetOrDefault(method.GetParameters()[0].ParameterType);
                if (!string.IsNullOrEmpty(extendedTypeId))
                    return new ExtensionMethod(member.ToString(), extendedTypeId, member.Elements);
            }

            return member;
        }