I need to parse my class for some purpose to come up with specific text string for each property.
namespace MyNameSpace
{
[MyAttribute]
public class MyClass
{
[MyPropertyAttribute(DefaultValue = "Default Value 1")]
public static string MyProperty1
{
get { return "hello1"; }
}
[MyPropertyAttribute(DefaultValue = "Default Value 2")]
public static string MyProperty2
{
get { return "hello2"; }
}
}
}
Here is my linq query to parse the file where this class lives
var lines =
from line in File.ReadAllLines(@"c:\someFile.txt")
where line.Contains("public static string ")
select line.Split(' ').Last();
foreach (var line in lines)
{
Console.WriteLine(string.Format("\"{0}\", ", line));
}
I am trying to output the following but I don’t know how to write the linq query for this.
{"MyProperty1", "Default Value 1"}
{"MyProperty2", "Default Value 2"}
Regular expressions may be a simpler solution:
Sample output:
Demo: http://ideone.com/D1AUBK