private void AddColumnAttributes() { foreach (var propertyDeclaration in classDeclaration.PropertyDeclarations) { if (propertyDeclaration.HasAttribute(Constants.Column)) { continue; } if (!propertyDeclaration.HasGetSet()) { continue; } var columnAttribute = CreateSchemaAttribute(Constants.Column); if (columnAttribute == null) { return; } var columnName = propertyDeclaration.NameIdentifier.Name; var columnNameArgument = factory.CreateArgument(ParameterKind.VALUE, factory.CreateStringLiteralExpression($"{columnName}")); columnAttribute.AddArgumentBefore(columnNameArgument, null); var propertyType = propertyDeclaration.Type; var typeNameArgument = factory.CreateArgument(ParameterKind.VALUE, factory.CreateExpression($"{Constants.TypeName} = $0", GetMappingTypeName(propertyType))); columnAttribute.AddArgumentBefore(typeNameArgument, null); propertyDeclaration.AddAttributeAfter(columnAttribute, propertyDeclaration.Attributes.LastOrDefault()); AddAnnotationAttributesIfNeed(propertyDeclaration); } }
private void AddJsonPropertyAttributes() { foreach (var propertyDeclaration in classDeclaration.PropertyDeclarations) { if (propertyDeclaration.HasAttribute(Constants.JsonProperty)) { continue; } if (!propertyDeclaration.HasGetSet()) { continue; } var attribute = provider.CreateAttribute($"Newtonsoft.Json.{Constants.JsonProperty}Attribute"); if (attribute == null) { return; } var propertyName = propertyDeclaration.NameIdentifier.Name; var propertyNameArgument = factory.CreateArgument(ParameterKind.VALUE, factory.CreateStringLiteralExpression($"{propertyNameTransform(propertyName)}")); attribute.AddArgumentBefore(propertyNameArgument, null); propertyDeclaration.AddAttributeAfter(attribute, propertyDeclaration.Attributes.LastOrDefault()); } }
private static IConstructorInitializer CreateBaseConstructorInitializer( CSharpElementFactory elementFactory, IParameterDeclaration infoParameterDeclaration, IParameterDeclaration contextParameterDeclaration) { var result = elementFactory.CreateBaseConstructorInitializer(); var infoArgumentExpression = elementFactory.CreateExpression("$0", infoParameterDeclaration.DeclaredName); result.AddArgumentBefore(elementFactory.CreateArgument(ParameterKind.VALUE, infoArgumentExpression), null); var contextArgumentExpression = elementFactory.CreateExpression("$0", contextParameterDeclaration.DeclaredName); result.AddArgumentBefore(elementFactory.CreateArgument(ParameterKind.VALUE, contextArgumentExpression), null); return(result); }
private IAttribute CreateContractClassAttribute(IClassDeclaration contractClass) { ITypeElement attributeType = TypeFactory.CreateTypeByCLRName( typeof(ContractClassAttribute).FullName, _provider.PsiModule).GetTypeElement(); var declaredType = contractClass.DeclaredElement; var typeofExpression = _factory.CreateExpression("typeof($0)", declaredType); var attribute = _factory.CreateAttribute(attributeType); attribute.AddArgumentAfter( _factory.CreateArgument(ParameterKind.VALUE, typeofExpression), null); return(attribute); }
private IAttribute CreateContractClassAttribute(string contractClassName) { ITypeElement type = TypeFactory.CreateTypeByCLRName( typeof(ContractClassAttribute).FullName, _provider.PsiModule, _currentFile.GetResolveContext()).GetTypeElement(); var expression = _factory.CreateExpressionAsIs( string.Format("typeof({0})", contractClassName)); var attribute = _factory.CreateAttribute(type); attribute.AddArgumentAfter( _factory.CreateArgument(ParameterKind.VALUE, expression), null); return(attribute); }
/// <summary>Creates an argument that may be passed to invocations.</summary> /// <param name="value">A value for an argument.</param> public ICSharpArgument CreateArgument(string value) { var argumentExpression = _factory.CreateExpression(value); return(_factory.CreateArgument(ParameterKind.VALUE, argumentExpression)); }