private static void HandleObjectCreation(SyntaxNodeAnalysisContext context) { var objectCreation = context.Node as ObjectCreationExpressionSyntax; if (objectCreation == null || objectCreation.IsMissing) { return; } ArgumentSyntax defaultValueArg; if (!PropertyMetaData.TryGetDefaultValue( objectCreation, context.SemanticModel, context.CancellationToken, out defaultValueArg)) { return; } var defaultValue = defaultValueArg.Expression; if (IsNonEmptyArrayCreation(defaultValue as ArrayCreationExpressionSyntax, context) || IsReferenceTypeCreation(defaultValue as ObjectCreationExpressionSyntax, context)) { IFieldSymbol dp; if (!PropertyMetaData.TryGetDependencyProperty(objectCreation, context.SemanticModel, context.CancellationToken, out dp)) { return; } context.ReportDiagnostic(Diagnostic.Create(Descriptor, defaultValueArg.GetLocation(), dp)); } }
private static void HandleObjectCreation(SyntaxNodeAnalysisContext context) { var objectCreation = context.Node as ObjectCreationExpressionSyntax; if (objectCreation == null || objectCreation.IsMissing) { return; } ArgumentSyntax defaultValueArg; if (!PropertyMetaData.TryGetDefaultValue( objectCreation, context.SemanticModel, context.CancellationToken, out defaultValueArg)) { return; } var defaultValue = defaultValueArg.Expression; if (defaultValue.IsSameType(KnownSymbol.Object, context)) { return; } IFieldSymbol dp; if (!PropertyMetaData.TryGetDependencyProperty(objectCreation, context.SemanticModel, context.CancellationToken, out dp)) { return; } ITypeSymbol registeredType; if (!DependencyProperty.TryGetRegisteredType(dp, context.SemanticModel, context.CancellationToken, out registeredType)) { return; } if (!registeredType.IsRepresentationPreservingConversion(defaultValue, context.SemanticModel, context.CancellationToken)) { context.ReportDiagnostic(Diagnostic.Create(Descriptor, defaultValueArg.GetLocation(), dp, registeredType)); } }
private static void HandleObjectCreation(SyntaxNodeAnalysisContext context) { if (context.IsExcludedFromAnalysis()) { return; } var objectCreation = context.Node as ObjectCreationExpressionSyntax; if (objectCreation == null || objectCreation.IsMissing) { return; } if (!PropertyMetaData.TryGetDefaultValue( objectCreation, context.SemanticModel, context.CancellationToken, out ArgumentSyntax defaultValueArg)) { return; } var defaultValue = defaultValueArg.Expression; if (IsNonEmptyArrayCreation(defaultValue as ArrayCreationExpressionSyntax, context) || IsReferenceTypeCreation(defaultValue as ObjectCreationExpressionSyntax, context)) { var type = context.SemanticModel.GetSymbolSafe(defaultValue, context.CancellationToken)?.ContainingType; if (type == KnownSymbol.FontFamily) { return; } if (!PropertyMetaData.TryGetDependencyProperty(objectCreation, context.SemanticModel, context.CancellationToken, out IFieldSymbol dp)) { return; } context.ReportDiagnostic(Diagnostic.Create(Descriptor, defaultValueArg.GetLocation(), dp)); } }
private static void HandleObjectCreation(SyntaxNodeAnalysisContext context) { var objectCreation = context.Node as ObjectCreationExpressionSyntax; if (context.SemanticModel == null || objectCreation == null || objectCreation.IsMissing) { return; } ArgumentSyntax callback; if (!PropertyMetaData.TryGetPropertyChangedCallback( objectCreation, context.SemanticModel, context.CancellationToken, out callback)) { return; } IdentifierNameSyntax nameExpression; string registeredName; if (TryGetIdentifierAndRegisteredName( callback, context.SemanticModel, context.CancellationToken, out nameExpression, out registeredName)) { if (!nameExpression.Identifier.ValueText.IsParts("On", registeredName, "Changed")) { context.ReportDiagnostic(Diagnostic.Create(Descriptor, nameExpression.GetLocation(), nameExpression, $"On{registeredName}Changed")); } } }
private static void HandleObjectCreation(SyntaxNodeAnalysisContext context) { if (context.IsExcludedFromAnalysis()) { return; } var objectCreation = context.Node as ObjectCreationExpressionSyntax; if (objectCreation == null || objectCreation.IsMissing) { return; } if (!PropertyMetaData.TryGetCoerceValueCallback( objectCreation, context.SemanticModel, context.CancellationToken, out ArgumentSyntax callback)) { return; } if (TryGetIdentifierAndRegisteredName( callback, context.SemanticModel, context.CancellationToken, out IdentifierNameSyntax nameExpression, out string registeredName)) { if (!nameExpression.Identifier.ValueText.IsParts("Coerce", registeredName)) { context.ReportDiagnostic(Diagnostic.Create(Descriptor, nameExpression.GetLocation(), nameExpression, $"Coerce{registeredName}")); } } }