public static void Save(this NSwagClient client, ITaskItem targetItem) { //A bit of reflection magic to automate properties assignment. client.GetType() .GetProperties() .Where(p => typeof(string).IsAssignableFrom(p.PropertyType)) .ToList() .ForEach(p => targetItem.SetMetadata(nameof(NSwagClient) + p.Name, p.GetValue(client) as string)); }
public static NSwagClient Restore(this ITaskItem sourceItem) { var result = new NSwagClient(); //A bit of reflection magic to automate properties assignment. result.GetType() .GetProperties() .Where(p => typeof(string).IsAssignableFrom(p.PropertyType)) .ToList() .ForEach(p => p.SetValue(result, sourceItem.GetMetadata(nameof(NSwagClient) + p.Name))); return(result); }