Skip to content

Instantly share code, notes, and snippets.

@sean-gilliam
Created April 17, 2023 20:04
Show Gist options
  • Save sean-gilliam/e676ab9a221eae19f4b5687e8014ad46 to your computer and use it in GitHub Desktop.
Save sean-gilliam/e676ab9a221eae19f4b5687e8014ad46 to your computer and use it in GitHub Desktop.
data-member-decorator
void Main()
{
string contract = @"
public int keyId { get; set; }
public bool error { get; set; }
public string changeProposal { get; set; }
public string dataCode { get; set; }
public string master { get; set; }
";
var newList = new List<string>();
var split = contract.Split('\n');
for(var i = 0; i < split.Length; i++)
{
if(split[i].Contains("public"))
{
var lsplit = split[i].Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
newList.Add($@" [DataMember(Order = {i - 1}, Name = ""{lsplit[2]}"")]");
newList.Add(split[i].Replace(lsplit[2], lsplit[2].Substring(0, 1).ToUpper() + lsplit[2].Substring(1)));
}
}
for(var i = 0; i < newList.Count; i++)
{
Console.WriteLine(newList[i]);
}
}
[DataMember(Order = 0, Name = "keyId")]
public int KeyId { get; set; }
[DataMember(Order = 1, Name = "error")]
public bool Error { get; set; }
[DataMember(Order = 2, Name = "changeProposal")]
public string ChangeProposal { get; set; }
[DataMember(Order = 3, Name = "dataCode")]
public string DataCode { get; set; }
[DataMember(Order = 4, Name = "master")]
public string Master { get; set; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment