private ParameterSyntax GetParameter(ParameterSyntax node) { //Remove contract attributes var attributes = node.AllAttributes() .Where(a => !a.IsContractAttribute(model)) .ToArray(); return(node.WithAttributeLists( SyntaxFactory.List <AttributeListSyntax>() .Add(SyntaxFactory.AttributeList().AddAttributes(attributes)))); }
public static bool HasAnyPreconditionAttribute(this ParameterSyntax @this, SemanticModel model) { if (@this == null) { throw new ArgumentNullException(nameof(@this)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } var attributeTypeSymbol = typeof(ContractAttribute).GetTypeSymbol(model); return(@this.AllAttributes() .Any(a => model.GetTypeInfo(a).Type.InheritsFrom(attributeTypeSymbol))); }
public static bool HasPreconditionAttribute(this ParameterSyntax @this, Contract contract, SemanticModel model) { if (@this == null) { throw new ArgumentNullException(nameof(@this)); } if (contract == null) { throw new ArgumentNullException(nameof(contract)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } var attributeTypeSymbol = contract.AttributeType.GetTypeSymbol(model); return(@this.AllAttributes() .Any(a => model.GetTypeInfo(a).Type.Equals(attributeTypeSymbol))); }
public static IEnumerable <Contract> GetPreconditions(this ParameterSyntax @this, SemanticModel model, IContractProvider contractProvider) { if (@this == null) { throw new ArgumentNullException(nameof(@this)); } if (model == null) { throw new ArgumentNullException(nameof(model)); } if (contractProvider == null) { throw new ArgumentNullException(nameof(contractProvider)); } var attributeTypeSymbol = typeof(ContractAttribute).GetTypeSymbol(model); return(@this.AllAttributes() .Where(a => model.GetTypeInfo(a).Type.InheritsFrom(attributeTypeSymbol)) .Select(a => contractProvider[a.GetText().ToString().Trim()])); }