Пример #1
0
            public void AnalyzeAttribute(SyntaxNodeAnalysisContext context)
            {
                AttributeSyntax syntax           = (AttributeSyntax)context.Node;
                ISymbol         attributedSymbol = context.ContainingSymbol !;

                AttributeData?attr = syntax.FindAttributeData(attributedSymbol);

                if (attr?.AttributeClass?.ToDisplayString() == TypeNames.CustomMarshallerAttribute &&
                    attr.AttributeConstructor is not null)
                {
                    DiagnosticReporter managedTypeReporter = DiagnosticReporter.CreateForLocation(syntax.FindArgumentWithNameOrArity("managedType", 0).FindTypeExpressionOrNullLocation(), context.ReportDiagnostic);
                    INamedTypeSymbol   entryType           = (INamedTypeSymbol)attributedSymbol;

                    INamedTypeSymbol?managedTypeInAttribute = (INamedTypeSymbol?)attr.ConstructorArguments[0].Value;
                    if (managedTypeInAttribute is null)
                    {
                        managedTypeReporter.CreateAndReportDiagnostic(ManagedTypeMustBeNonNullRule, entryType.ToDisplayString());
                    }

                    if (!ManualTypeMarshallingHelper.TryResolveManagedType(
                            entryType,
                            managedTypeInAttribute,
                            ManualTypeMarshallingHelper.IsLinearCollectionEntryPoint(entryType),
                            (entryType, managedType) => managedTypeReporter.CreateAndReportDiagnostic(ManagedTypeMustBeClosedOrMatchArityRule, managedType, entryType), out ITypeSymbol managedType))
                    {
                        return;
                    }
                    DiagnosticReporter marshallerTypeReporter    = DiagnosticReporter.CreateForLocation(syntax.FindArgumentWithNameOrArity("marshallerType", 2).FindTypeExpressionOrNullLocation(), context.ReportDiagnostic);
                    ITypeSymbol?       marshallerTypeInAttribute = (ITypeSymbol?)attr.ConstructorArguments[2].Value;
                    if (marshallerTypeInAttribute is null)
                    {
                        marshallerTypeReporter.CreateAndReportDiagnostic(MarshallerTypeMustBeNonNullRule);
                    }
                    if (!ManualTypeMarshallingHelper.TryResolveMarshallerType(
                            entryType,
                            marshallerTypeInAttribute,
                            (entryType, marshallerType) => marshallerTypeReporter.CreateAndReportDiagnostic(MarshallerTypeMustBeClosedOrMatchArityRule, marshallerType, entryType),
                            out ITypeSymbol marshallerType))
                    {
                        return;
                    }

                    AnalyzeMarshallerType(
                        marshallerTypeReporter,
                        (INamedTypeSymbol)managedType,
                        (MarshalMode)attr.ConstructorArguments[1].Value,
                        (INamedTypeSymbol?)marshallerType,
                        ManualTypeMarshallingHelper.IsLinearCollectionEntryPoint(entryType));
                }
            }
            public void AnalyzeAttribute(SyntaxNodeAnalysisContext context)
            {
                AttributeSyntax syntax           = (AttributeSyntax)context.Node;
                ISymbol         attributedSymbol = context.ContainingSymbol !;

                AttributeData?attr = syntax.FindAttributeData(attributedSymbol);

                if (attr?.AttributeClass?.ToDisplayString() == TypeNames.NativeMarshallingAttribute &&
                    attr.AttributeConstructor is not null)
                {
                    INamedTypeSymbol?entryType = (INamedTypeSymbol?)attr.ConstructorArguments[0].Value;
                    AnalyzeManagedTypeMarshallingInfo(
                        GetSymbolType(attributedSymbol),
                        DiagnosticReporter.CreateForLocation(syntax.FindArgumentWithNameOrArity("nativeType", 0).FindTypeExpressionOrNullLocation(), context.ReportDiagnostic),
                        entryType);
                }
            }