Example #1
0
        private TypeSpec GetTypeSpec(Type type, IMetadataReader metadataReader)
        {
            if (!type.HasExportAttribute(metadataReader))
            {
                throw new CoreException($"Type '{type.FullName}' should have an ExportAttribute attribute");
            }

            var exportAttribute = metadataReader.GetAttributes(type).FirstOrDefault(a => a is ExportAttribute) as ExportAttribute;

            IEnumerable <Attribute> additionalAttributes = metadataReader.GetAttributes(type)
                                                           .Where(a => !(a is ExportAttribute))
                                                           .OfType <Attribute>();

            var typeSpec = new TypeSpec(exportAttribute);

            foreach (Attribute additionalAttribute in additionalAttributes)
            {
                typeSpec.AdditionalAttributes.Add(additionalAttribute);
            }

            foreach (MemberInfo memberInfo in type.GetTsExportableMembers(metadataReader, false))
            {
                IEnumerable <Attribute> attributes = metadataReader
                                                     .GetAttributes(memberInfo)
                                                     .OfType <Attribute>();
                typeSpec.MemberAttributes.Add(memberInfo.Name, attributes.ToList());
            }

            return(typeSpec);
        }
        /// <summary>
        /// Gets type dependencies for the members inside a given type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private IEnumerable <TypeDependencyInfo> GetMemberTypeDependencies(Type type)
        {
            IEnumerable <TypeDependencyInfo> result = Enumerable.Empty <TypeDependencyInfo>();

            IEnumerable <MemberInfo> memberInfos = _typeService.GetTsExportableMembers(type);

            foreach (MemberInfo memberInfo in memberInfos)
            {
                if (_metadataReader.GetAttribute <TsTypeAttribute>(memberInfo) != null)
                {
                    continue;
                }

                Type memberType     = _typeService.GetMemberType(memberInfo);
                Type memberFlatType = _typeService.GetFlatType(memberType);

                if (memberFlatType == type || (memberFlatType.IsConstructedGenericType && memberFlatType.GetGenericTypeDefinition() == type))
                {
                    continue;                                                                                                                           // NOT a dependency if it's the type itself
                }
                IEnumerable <Attribute> memberAttributes = _metadataReader.GetAttributes <Attribute>(memberInfo);
                result = result.Concat(GetFlatTypeDependencies(memberFlatType, memberAttributes));
            }

            return(result);
        }