Ejemplo n.º 1
0
        private void AddSerializer(StringBuilder source, IFieldSymbol field,
                                   char delimiter)
        {
            string fieldName = $"this.{field.FieldName()}";

            source.Append($"return {fieldName} != null ? string.Join('{delimiter}', {fieldName}) : null;");
        }
Ejemplo n.º 2
0
        private void AddDeserializer(StringBuilder source, IFieldSymbol field,
                                     char delimiter)
        {
            var arrayType = field.Type as IArrayTypeSymbol;

            string fieldName = $"this.{field.FieldName()}";

            source.AppendLine($@"
string[] split = value.Split('{delimiter}', StringSplitOptions.RemoveEmptyEntries);
{fieldName} = new {arrayType.ElementType}[split.Length];
for (int i = 0; i < split.Length; i++) {{");
            source.AppendLine(arrayType.ElementType.IsValueType
                ? $"{fieldName}[i] = {arrayType.ElementType}.Parse(split[i].Trim());"
                : $"{fieldName}[i] = split[i].Trim();");
            source.Append('}');
        }