private static void HandleArgument(SyntaxNodeAnalysisContext context, ArgumentSyntax argument) { if (argument.TryGetTypeofValue(context.SemanticModel, context.CancellationToken, out var ownerType) && !ownerType.IsAssignableTo(KnownSymbols.DependencyObject, context.Compilation)) { context.ReportDiagnostic(Diagnostic.Create(Descriptors.WPF0015RegisteredOwnerTypeMustBeDependencyObject, argument.GetLocation(), KnownSymbols.DependencyProperty.RegisterAttached.Name)); } }
private static void HandleArgument(SyntaxNodeAnalysisContext context, ArgumentSyntax argument) { if (argument.TryGetTypeofValue(context.SemanticModel, context.CancellationToken, out var ownerType) && !ownerType.Equals(context.ContainingSymbol.ContainingType)) { context.ReportDiagnostic(Diagnostic.Create(Descriptors.WPF0011ContainingTypeShouldBeRegisteredOwner, argument.GetLocation(), context.ContainingSymbol.ContainingType)); } }
internal static bool TryGetRegisteredType(FieldOrProperty fieldOrProperty, SemanticModel semanticModel, CancellationToken cancellationToken, out ArgumentSyntax typeArg, out ITypeSymbol result) { typeArg = null; result = null; if (fieldOrProperty.TryGetAssignedValue(cancellationToken, out var value) && value is InvocationExpressionSyntax invocation) { if (TryGetRegisterCall(invocation, semanticModel, cancellationToken, out _) && invocation.TryGetArgumentAtIndex(3, out typeArg)) { return(typeArg.TryGetTypeofValue(semanticModel, cancellationToken, out result)); } } return(false); }