public string GetRead(string target, ITypeSymbol targetType, IValueSerializationGeneratorContext context) { if (_enums.IsResolvable(targetType)) { var value = VariableHelper.GetName(targetType); if (targetType.IsNullable()) { return($@" string {value}; {context.Read<string>(value)} if (!string.IsNullOrEmpty({value})) {{ {target} = {Enums.GetConverterName(targetType)}.FromString({value}); }}" ); } else { return($@" string {value}; {context.Read<string>(value)} {target} = {Enums.GetConverterName(targetType)}.FromString({value});" ); } } return(null); }
private string GetRead(string target, ITypeSymbol targetType, string formatValue, string stylesValue, IValueSerializationGeneratorContext context) { if (_supportedTypes.Contains(targetType.GetDeclarationGenericFullName())) { var value = VariableHelper.GetName <string>(); return($@" string {value}; {context.Read<string>(value)} {GetParseMethod(value, target, targetType, formatValue, stylesValue, context)}" ); } else if (targetType.IsNullable(out targetType) && _supportedTypes.Contains(targetType.GetDeclarationGenericFullName())) { var value = VariableHelper.GetName <string>(); return($@" string {value}; {context.Read<string>(value)} if (!string.IsNullOrWhiteSpace({value})) {{ {GetParseMethod(value, target, targetType, formatValue, stylesValue, context)} }}" ); } else { return(null); } }
public string GetRead(string target, IPropertySymbol targetProperty, IValueSerializationGeneratorContext context) { if (targetProperty.FindAttributeByShortName("MicrosoftDateTimeFormatAttribute") != null) { var value = VariableHelper.GetName("dateTime"); var targetName = $"{target}.{targetProperty.Name}"; var type = targetProperty.Type; if (_supportedTypes.Contains(type.GetDeclarationGenericFullName())) { return($@" string {value}; {context.Read<string>(value)} {GetParseMethod(value, targetName, type)}" ); } else if (type.IsNullable(out type) && _supportedTypes.Contains(type.GetDeclarationGenericFullName())) { return($@" string {value}; {context.Read<string>(value)} if (!string.IsNullOrWhiteSpace({value})) {{ {GetParseMethod(value, targetName, type)} }}" ); } else { return($"\r\n #error {_nonSupportedTypeError}"); } } else { return(null); } }
public override string Read(string target, bool isNullable, IValueSerializationGeneratorContext context) { var guid = VariableHelper.GetName("guid"); return($@" string {guid}; {context.Read<string>(guid)} if (!string.IsNullOrWhiteSpace({guid})) {{ {target} = Guid.Parse({guid}); }}" ); }
public override string Read(string target, bool isNullable, IValueSerializationGeneratorContext context) { var uri = VariableHelper.GetName("uri"); return($@" string {uri}; {context.Read<string>(uri)} if (!string.IsNullOrEmpty({uri})) {{ {target} = new Uri({uri}, UriKind.RelativeOrAbsolute); }}" ); }