Beispiel #1
0
 protected CodeMemberField EmitFieldDeclaration(DiagnosticSpecification.Field field)
 {
     return(new CodeMemberField
     {
         Name = GetBackingFieldName(field),
         Attributes = MemberAttributes.Private,
         Type = new CodeTypeReference(field.FieldType.ToCamelCase())
     });
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 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())
                ));
 }
Beispiel #4
0
 protected string GetBackingFieldName(DiagnosticSpecification.Field field)
 {
     return($"_{field.FieldName.ToCamelCase()}");
 }
Beispiel #5
0
 private CodeExpression GetPropertyReferenceExpression(DiagnosticSpecification.Field arg)
 {
     return(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), arg.FieldName.ToCamelCase()));
 }