Sample of reading properties

CSharp · Console

/Program.cs

using System;
using System.Linq;
					
public class Program
{
	public class Filter 
	{
		public int Var1 { get; set; }
		public int Var2 { get; set; }
		public int Var3 { get; set; }
		
		public Filter() {
			Var1 = 1;
			Var2 = 2;
			Var3 = 3;
		}
	}
	public static void Main()
	{
		var filter = new Filter();
		var filterType = filter.GetType();
		var readableProperties = filterType.GetProperties().Where( p => p.GetGetMethod() != null );

		foreach (var property in readableProperties) 
		{
			var value = (int)property.GetValue( filter );
			Console.WriteLine( "{0} =  {1}", property.Name, value + 3 );
		}
	}
}
;