protected CodeMemberField EmitFieldDeclaration(DiagnosticSpecification.Field field) { return(new CodeMemberField { Name = GetBackingFieldName(field), Attributes = MemberAttributes.Private, Type = new CodeTypeReference(field.FieldType.ToCamelCase()) }); }
protected CodeMemberProperty EmitPropertyDeclaration(DiagnosticSpecification.Field field) { var propertyName = field.FieldName.ToCamelCase(); var backingFieldName = GetBackingFieldName(field); var property = new CodeMemberProperty { Name = propertyName, Attributes = MemberAttributes.Public, Type = new CodeTypeReference(field.FieldType.ToCamelCase()) }; var propertyAttributes = new CodeAttributeDeclaration(new CodeTypeReference("FieldName"), new CodeAttributeArgument(new CodePrimitiveExpression(field.FieldName))); property.CustomAttributes.Add(propertyAttributes); property.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), backingFieldName), new CodeVariableReferenceExpression("value"))); property.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), backingFieldName))); return(property); }
private CodeExpression GetEqualsExpression(CodeThisReferenceExpression codeThis, CodeVariableReferenceExpression codeThat, DiagnosticSpecification.Field field) { return(new CodeMethodInvokeExpression( new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(typeof(object)), "Equals"), new CodePropertyReferenceExpression(codeThis, field.FieldName.ToCamelCase()), new CodePropertyReferenceExpression(codeThat, field.FieldName.ToCamelCase()) )); }
protected string GetBackingFieldName(DiagnosticSpecification.Field field) { return($"_{field.FieldName.ToCamelCase()}"); }
private CodeExpression GetPropertyReferenceExpression(DiagnosticSpecification.Field arg) { return(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), arg.FieldName.ToCamelCase())); }