/// <summary>
 /// Gets the <c>VariableContext</c>s for the fields in the type.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="semanticModel">The semantic model.</param>
 /// <returns></returns>
 internal static IEnumerable <VariableContext> GetDescendantFieldContexts(this ITypeDeclarationContext typeContext, SemanticModel semanticModel)
 => typeContext.Declaration
 //todo: this may cause issues with nested classes/structs
 .DescendantNodes()
 .OfType <FieldDeclarationSyntax>()
 .SelectMany(f =>
             f.Declaration
             .Variables
             .Select(v => new VariableContext(Maybe.From(typeContext), f, v, semanticModel)));
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyContext"/> class.
 /// </summary>
 /// <param name="containingTypeContext">The context for the type that contains this member.</param>
 /// <param name="propertyDeclaration">The property declaration.</param>
 /// <param name="semanticModel">The semantic model.</param>
 /// <exception cref="System.ArgumentNullException">
 /// propertyDeclaration
 /// or
 /// semanticModel
 /// </exception>
 public PropertyContext(ITypeDeclarationContext containingTypeContext, PropertyDeclarationSyntax propertyDeclaration, SemanticModel semanticModel)
 {
     if (containingTypeContext == null)
     {
         throw new ArgumentException(nameof(containingTypeContext));
     }
     ContainingTypeContext = Maybe.From(containingTypeContext);
     Declaration           = propertyDeclaration ?? throw new ArgumentNullException(nameof(propertyDeclaration));
     SemanticModel         = semanticModel ?? throw new ArgumentNullException(nameof(semanticModel));
 }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodContext"/> class.
        /// </summary>
        /// <param name="containingTypeContext">The context for the type that contains this member.</param>
        /// <param name="methodDeclaration">The method declaration.</param>
        /// <param name="semanticModel">The semantic model.</param>
        /// <exception cref="System.ArgumentNullException">methodDeclaration</exception>
        /// <exception cref="System.ArgumentException">semanticModel</exception>
        public MethodContext(ITypeDeclarationContext containingTypeContext, MethodDeclarationSyntax methodDeclaration, SemanticModel semanticModel)
        {
            if (containingTypeContext == null)
            {
                throw new ArgumentException(nameof(containingTypeContext));
            }
            ContainingTypeContext = Maybe.From(containingTypeContext);
            Declaration           = methodDeclaration ?? throw new ArgumentNullException(nameof(methodDeclaration));
            SemanticModel         = semanticModel ?? throw new ArgumentException(nameof(semanticModel));

            Symbol = semanticModel.GetDeclaredSymbol(methodDeclaration);
        }
示例#4
0
        /// <summary>
        /// Gets the type dependencies for a type declaration.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException">if the value is not a <see cref="ClassContext"/> or <see cref="StructContext"/></exception>
        public IEnumerable <TypeContext> GetTypeDependencies(ITypeDeclarationContext value)
        {
            switch (value)
            {
            case ClassContext cls:
                return(GetTypeDependencies(cls));

            case StructContext str:
                return(GetTypeDependencies(str));

            //todo add interfacecontext
            default:
                throw new NotImplementedException(value.GetType().Name);
            }
        }
 /// <summary>
 /// Gets the field/method/constructor/property contexts for this class/struct.
 /// Does not include extension methods.
 /// </summary>
 /// <param name="type">The class/struct/interface context.</param>
 /// <returns></returns>
 internal static IEnumerable <ITypeMemberContext> GetTypeMembersExcludingExtensions(this ITypeDeclarationContext type)
 => ((IEnumerable <ITypeMemberContext>)type.Fields)
 .Union(type.Methods.Where(x => !x.IsExtensionMethod))
 .Union(type.Constructors)
 .Union(type.Properties);
 /// <summary>
 /// Gets the <c>PropertyContext</c>s for the type.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="semanticModel">The semantic model.</param>
 /// <returns></returns>
 internal static IEnumerable <PropertyContext> GetDescendantPropertyContexts(this ITypeDeclarationContext typeContext, SemanticModel semanticModel)
 => typeContext.Declaration
 //todo: this may cause issues with nested classes/structs
 .DescendantNodes()
 .OfType <PropertyDeclarationSyntax>()
 .Select(x => new PropertyContext(typeContext, x, semanticModel));