Пример #1
0
        public InterfaceInfo FindInterface(TypeInfo.TypeInfo typeInfo)
        {
            var r = this.compilation.GetSymbolsWithName(
                x => x.Contains(typeInfo.Name),
                SymbolFilter.Type);


            throw new NotImplementedException();
        }
Пример #2
0
        public static InterfaceInfo FromSymbol(INamedTypeSymbol symbol)
        {
            if (symbol.TypeKind != Microsoft.CodeAnalysis.TypeKind.Interface)
            {
                return(null);
            }

            var props   = new LinkedList <PropertyMemberInfo>();
            var methods = new LinkedList <MethodMemberInfo>();

            foreach (var s in symbol.GetMembers())
            {
                switch (s.Kind)
                {
                case SymbolKind.Property:
                    props.AddLast(PropertyMemberInfo.FromSymbol((IPropertySymbol)s));
                    break;

                case SymbolKind.Method:
                    if (s.CanBeReferencedByName)
                    {
                        methods.AddLast(MethodMemberInfo.FromSymbol((IMethodSymbol)s));
                    }
                    break;
                }
            }

            return(new InterfaceInfo(
                       TypeInfo.FromSymbol(symbol),
                       getAccessibility(symbol.DeclaredAccessibility),
                       props,
                       methods,
                       symbol.GetAttributes().Select(AttributeInfo.Create).ToArray()));

            Accessibility getAccessibility(Microsoft.CodeAnalysis.Accessibility access)
            {
                switch (access)
                {
                case Microsoft.CodeAnalysis.Accessibility.NotApplicable:
                    return(Accessibility.None);

                case Microsoft.CodeAnalysis.Accessibility.Private:
                    return(Accessibility.Private);

                case Microsoft.CodeAnalysis.Accessibility.Protected:
                    return(Accessibility.Protected);

                case Microsoft.CodeAnalysis.Accessibility.Public:
                    return(Accessibility.Public);

                case Microsoft.CodeAnalysis.Accessibility.Internal:
                    return(Accessibility.Internal);

                case Microsoft.CodeAnalysis.Accessibility.ProtectedAndInternal:
                    return(Accessibility.Protected | Accessibility.Internal);

                default:
                    throw new ArgumentOutOfRangeException(nameof(access), $"Interface accessibility {access.ToString()} is not supported.");
                }
            }
        }