public void CopyTo(SecurityAttribute copy) { copy._action = _action; copy._type = _type; copy._xml = _xml; NamedArguments.CopyTo(copy.NamedArguments); }
public FunctionCallExpression(Expression value, IEnumerable <Argument> args) { this.Value = value.NotNull(); var list = args.ToArray(); var positionals = list.TakeWhile(x => x is PositionalArgument).ToArray(); var named = list.SkipWhile(x => x is PositionalArgument); if (named.Any(a => a is PositionalArgument)) { throw new InvalidOperationException("All named arguments must be defined after the positional arguments!"); } this.PositionalArguments = positionals.Cast <PositionalArgument>().ToArray(); this.NamedArguments = named.Cast <NamedArgument>().ToArray(); if (NamedArguments.Select(n => n.Name).Distinct().Count() != NamedArguments.Count) { throw new InvalidOperationException("Named arguments must be unique!"); } for (int i = 0; i < positionals.Length; i++) { this.PositionalArguments[i].Position = i; } }
public bool Equals(MarkupExtensionInfo other) { if (ReferenceEquals(other, null)) { return(false); } if (other.ExtensionType != ExtensionType) { return(false); } if (other.StartOffset != StartOffset) { return(false); } if (other.EndOffset != EndOffset) { return(false); } if (other.NamedArguments.Count != NamedArguments.Count) { return(false); } if (other.PositionalArguments.Count != PositionalArguments.Count) { return(false); } for (int i = 0; i < PositionalArguments.Count; i++) { if (!PositionalArguments[i].Equals(other.PositionalArguments[i])) { return(false); } } List <KeyValuePair <string, AttributeValue> > myItems = NamedArguments.ToList(); List <KeyValuePair <string, AttributeValue> > otherItems = other.NamedArguments.ToList(); for (int i = 0; i < myItems.Count; i++) { if (myItems[i].Key != otherItems[i].Key) { return(false); } if (!myItems[i].Value.Equals(otherItems[i].Value)) { return(false); } } return(true); }
public override string ToString() { string str = Constructor.ToString(); str += "(" + String.Join(", ", FixedArguments.Select(fa => fa.ToString())) + String.Join(", ", NamedArguments.Select(na => na.ToString())) + ")"; str += "(ctor: " + Constructor.Handle.ToString(); return(str); }
/// <summary> /// Gets the property/field named <paramref name="name" /> /// </summary> /// <param name="name">Name of property/field</param> /// <param name="isField"><c>true</c> if it's a field, <c>false</c> if it's a property</param> /// <returns>A <see cref="CANamedArgument" /> instance or <c>null</c> if not found</returns> public CANamedArgument GetNamedArgument(UTF8String name, bool isField) { foreach (var namedArg in NamedArguments.GetSafeEnumerable()) { if (namedArg.IsField == isField && UTF8String.Equals(namedArg.Name, name)) { return(namedArg); } } return(null); }
/// <summary> /// Gets the property/field named <paramref name="name" /> /// </summary> /// <param name="name">Name of property/field</param> /// <param name="isField"><c>true</c> if it's a field, <c>false</c> if it's a property</param> /// <returns>A <see cref="CANamedArgument" /> instance or <c>null</c> if not found</returns> public CANamedArgument GetNamedArgument(string name, bool isField) { foreach (var namedArg in NamedArguments.GetSafeEnumerable()) { if (namedArg.IsField == isField && UTF8String.ToSystemStringOrEmpty(namedArg.Name) == name) { return(namedArg); } } return(null); }
public ReceivePackRecovery( IHookReceivePack next, NamedArguments.FailedPackWaitTimeBeforeExecution failedPackWaitTimeBeforeExecution, IRecoveryFilePathBuilder recoveryFilePathBuilder, GitServiceResultParser resultFileParser) { this.next = next; this.failedPackWaitTimeBeforeExecution = failedPackWaitTimeBeforeExecution.Value; this.recoveryFilePathBuilder = recoveryFilePathBuilder; this.resultFileParser = resultFileParser; }
public override void Initialize(AnalysisContext context) { context.EnableConcurrentExecution(); context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.ReportDiagnostics); context.RegisterCompilationStartAction(context => { var compilation = context.Compilation; var isPublishTrimmed = context.Options.GetMSBuildPropertyValue(MSBuildPropertyOptionNames.PublishTrimmed, compilation); if (!string.Equals(isPublishTrimmed?.Trim(), "true", StringComparison.OrdinalIgnoreCase)) { return; } context.RegisterOperationAction(operationContext => { var call = (IInvocationOperation)operationContext.Operation; if (call.IsVirtual && call.TargetMethod.OverriddenMethod != null) { return; } CheckMethodOrCtorCall(operationContext, call.TargetMethod, call.Syntax.GetLocation()); }, OperationKind.Invocation); context.RegisterOperationAction(operationContext => { var call = (IObjectCreationOperation)operationContext.Operation; CheckMethodOrCtorCall(operationContext, call.Constructor, call.Syntax.GetLocation()); }, OperationKind.ObjectCreation); context.RegisterOperationAction(operationContext => { var propAccess = (IPropertyReferenceOperation)operationContext.Operation; var prop = propAccess.Property; var usageInfo = propAccess.GetValueUsageInfo(prop); if (usageInfo.HasFlag(ValueUsageInfo.Read) && prop.GetMethod != null) { CheckMethodOrCtorCall( operationContext, prop.GetMethod, propAccess.Syntax.GetLocation()); } if (usageInfo.HasFlag(ValueUsageInfo.Write) && prop.SetMethod != null) { CheckMethodOrCtorCall( operationContext, prop.SetMethod, propAccess.Syntax.GetLocation()); } }, OperationKind.PropertyReference); void CheckMethodOrCtorCall( OperationAnalysisContext operationContext, IMethodSymbol method, Location location) { AttributeData?requiresUnreferencedCode; // If parent method contains RequiresUnreferencedCodeAttribute then we shouldn't report diagnostics for this method if (operationContext.ContainingSymbol is IMethodSymbol && TryGetRequiresUnreferencedCodeAttribute(operationContext.ContainingSymbol.GetAttributes(), out requiresUnreferencedCode)) { return; } if (TryGetRequiresUnreferencedCodeAttribute(method.GetAttributes(), out requiresUnreferencedCode)) { operationContext.ReportDiagnostic(Diagnostic.Create( s_rule, location, method.OriginalDefinition.ToString(), (string)requiresUnreferencedCode !.ConstructorArguments[0].Value !, requiresUnreferencedCode !.NamedArguments.FirstOrDefault(na => na.Key == "Url").Value.Value?.ToString())); } } }); }
public void CopyTo(CustomAttribute copy) { copy._constructor = _constructor; CtorArguments.CopyTo(copy.CtorArguments); NamedArguments.CopyTo(copy.NamedArguments); }
public OneFolderRecoveryFilePathBuilder(NamedArguments.ReceivePackRecoveryDirectory receivePackRecoveryDirectory) { this.receivePackRecoveryDirectory = receivePackRecoveryDirectory.Value; }
static void CheckMethodOrCtorCall( OperationAnalysisContext operationContext, IMethodSymbol method) { // If parent method contains RequiresUnreferencedCodeAttribute then we shouldn't report diagnostics for this method if (operationContext.ContainingSymbol is IMethodSymbol && operationContext.ContainingSymbol.HasAttribute(RequiresUnreferencedCodeAttribute)) { return; } if (!method.HasAttribute(RequiresUnreferencedCodeAttribute)) { return; } if (method.TryGetAttributeWithMessageOnCtor(FullyQualifiedRequiresUnreferencedCodeAttribute, out AttributeData? requiresUnreferencedCode)) { operationContext.ReportDiagnostic(Diagnostic.Create( s_requiresUnreferencedCodeRule, operationContext.Operation.Syntax.GetLocation(), method.OriginalDefinition.ToString(), (string)requiresUnreferencedCode !.ConstructorArguments[0].Value !, requiresUnreferencedCode !.NamedArguments.FirstOrDefault(na => na.Key == "Url").Value.Value?.ToString())); } }
static void CheckStaticConstructors(OperationAnalysisContext operationContext, ImmutableArray <IMethodSymbol> constructors) { foreach (var constructor in constructors) { if (constructor.Parameters.Length == 0 && constructor.HasAttribute(RequiresUnreferencedCodeAttribute) && constructor.MethodKind == MethodKind.StaticConstructor) { if (constructor.TryGetAttributeWithMessageOnCtor(FullyQualifiedRequiresUnreferencedCodeAttribute, out AttributeData? requiresUnreferencedCode)) { operationContext.ReportDiagnostic(Diagnostic.Create( s_requiresUnreferencedCodeRule, operationContext.Operation.Syntax.GetLocation(), constructor.ToString(), (string)requiresUnreferencedCode !.ConstructorArguments[0].Value !, requiresUnreferencedCode !.NamedArguments.FirstOrDefault(na => na.Key == "Url").Value.Value?.ToString())); } } } }
static void CheckMethodOrCtorCall( OperationAnalysisContext operationContext, IMethodSymbol method) { // Find containing symbol ISymbol?containingSymbol = null; for (var current = operationContext.Operation; current is not null; current = current.Parent) { if (current is ILocalFunctionOperation local) { containingSymbol = local.Symbol; break; } else if (current is IAnonymousFunctionOperation lambda) { containingSymbol = lambda.Symbol; break; } else if (current is IMethodBodyBaseOperation) { break; } } containingSymbol ??= operationContext.ContainingSymbol; // If parent method contains RequiresUnreferencedCodeAttribute then we shouldn't report diagnostics for this method if (containingSymbol is IMethodSymbol && containingSymbol.HasAttribute(RequiresUnreferencedCodeAttribute)) { return; } // If calling an instance constructor, check first for any static constructor since it will be called implicitly if (method.ContainingType is { } containingType&& operationContext.Operation is IObjectCreationOperation) { CheckStaticConstructors(operationContext, containingType.StaticConstructors); } if (!method.HasAttribute(RequiresUnreferencedCodeAttribute)) { return; } // Warn on the most derived base method taking into account covariant returns while (method.OverriddenMethod != null && SymbolEqualityComparer.Default.Equals(method.ReturnType, method.OverriddenMethod.ReturnType)) { method = method.OverriddenMethod; } if (method.TryGetAttributeWithMessageOnCtor(FullyQualifiedRequiresUnreferencedCodeAttribute, out AttributeData? requiresUnreferencedCode)) { operationContext.ReportDiagnostic(Diagnostic.Create( s_requiresUnreferencedCodeRule, operationContext.Operation.Syntax.GetLocation(), method.OriginalDefinition.ToString(), (string)requiresUnreferencedCode !.ConstructorArguments[0].Value !, requiresUnreferencedCode !.NamedArguments.FirstOrDefault(na => na.Key == "Url").Value.Value?.ToString())); } }
public override string ToString() { string str = Type.ToString(false) + "..ctor"; str += "(" + String.Join(", ", FixedArguments.Select(fa => fa.ToString()).Concat(NamedArguments.Select(na => na.ToString())).ToArray()) + ")"; str += "(type: " + Type.Handle.ToString() + ", ctor: " + Constructor.Handle.ToString(); return(str); }