private static void GenerateSecondParameterAndArgument(IEventDeclaration eventDeclaration, IParameter parameter, IConstructLanguage language, FileModel fileModel, IList <IArgument> arguments, IList <IParameter> parameters) { NamingPolicy parametersNamingPolicy = language.PrimaryNamingPolicyFor <IParameter>(fileModel.UserSettings); IType parameterType = eventDeclaration.TypeName.Type.As <IDelegateType>().ReplaceParameterTypesIn(parameter.Type); IParameter newParameter = language.Parameter( parameter.IsRef, parameter.IsOut, parameter.IsParams, language.TypeName(eventDeclaration.StringTypeAtThisLocation()), parameter.DefaultValue); string parameterName = parametersNamingPolicy.ChangeNameAccordingToPolicy("propertyName", parameter.SolutionModel); newParameter.Identifier = language.Identifier(parameterName); IObjectCreation objectCreation = language.ObjectCreation( language.TypeName(parameterType), language.Arguments( language.Argument( language.VariableAccess(newParameter.Identifier)))); arguments.Add( language.Argument( objectCreation)); parameters.Add(newParameter); }
protected override void AddCodeMarkers(FileModel fileModel) { foreach (IAddEventHandlerStatement addEventHandler in fileModel.All <IAddEventHandlerStatement>().Where(x => x.HandlerExpression.Is <IObjectCreation>())) { IObjectCreation objectCreation = addEventHandler.HandlerExpression.As <IObjectCreation>(); objectCreation.TypeName.AddCodeMarker(RemoveNewDelegateCreationMarkerID, this, RemoveUnnecessaryObjectCreation, objectCreation); } }
public static object SetObjectCreatedBy(this IObjectCreation creation, Func <object, object> newCreatedByFactory) { creation.NotNull(nameof(creation)); newCreatedByFactory.NotNull(nameof(newCreatedByFactory)); var newCreatedBy = creation.GetObjectCreatedBy(); return(creation.SetObjectCreatedBy(newCreatedByFactory.Invoke(newCreatedBy))); }
public static async ValueTask <object> SetObjectCreatedByAsync(this IObjectCreation creation, Func <object, object> newCreatedByFactory, CancellationToken cancellationToken = default) { creation.NotNull(nameof(creation)); newCreatedByFactory.NotNull(nameof(newCreatedByFactory)); var newCreatedBy = await creation.GetObjectCreatedByAsync(cancellationToken).ConfigureAwait(); return(await creation.SetObjectCreatedByAsync(newCreatedByFactory.Invoke(newCreatedBy), cancellationToken) .ConfigureAwait()); }
private void RemoveUnnecessaryObjectCreation(IObjectCreation objectCreation) { IExpression argument = objectCreation.Arguments.Arguments.First().Expression; objectCreation.ReplaceWith(argument); }
private static void CheckSystemSecurityCryptographyAlgorithms(ITypeSymbol containingType, IObjectCreation objectCreation, SyntaxNodeAnalysisContext c) { // DSACryptoServiceProvider is always noncompliant as it has a max key size of 1024 // RSACryptoServiceProvider() and RSACryptoServiceProvider(System.Security.Cryptography.CspParameters) constructors are noncompliants as they have a default key size of 1024 if (containingType.Is(KnownType.System_Security_Cryptography_DSACryptoServiceProvider) || (containingType.Is(KnownType.System_Security_Cryptography_RSACryptoServiceProvider) && HasDefaultSize(objectCreation.ArgumentList.Arguments, c))) { c.ReportDiagnosticWhenActive(Diagnostic.Create(Rule, objectCreation.Expression.GetLocation(), MinimalCommonKeyLength, CipherName(containingType), "")); } else { var firstParam = objectCreation.ArgumentList.Get(0); CheckGenericDsaRsaCryptographyAlgorithms(containingType, objectCreation.Expression, firstParam, c); } }
private void RemoveUnnecessaryObjectCreation(IObjectCreation objectCreation) { IExpression argument = objectCreation.Arguments.Arguments.First().Expression; objectCreation.ReplaceWith(argument); }
internal bool ShouldBeReported(IObjectCreation objectCreation, SemanticModel semanticModel, bool isDefaultConstructorSafe) => IsTrackedType(objectCreation.Expression, semanticModel) && !ObjectCreatedWithAllowedValue(objectCreation, semanticModel, isDefaultConstructorSafe) && !IsLaterAssignedWithAllowedValue(objectCreation, semanticModel);