C# Extension Method: Object - GetPropertyValue

CSharp · Console

/Program.cs

// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002736/object-getpropertyvalue

// @nuget: Z.ExtensionMethods
using System;
					
public class Program
{
	public static void Main()
	{
		var obj = new PropertyModel<int>()
		{
			PublicProperty = 3
		};
		
		//C# Extension Method: Object - GetPropertyValue
		Console.WriteLine(obj.GetPropertyValue("PublicProperty"));
		
		obj.PublicProperty = 5;
		
		//C# Extension Method: Object - GetPropertyValue
		Console.WriteLine(obj.GetPropertyValue("PublicProperty"));
	}

    public class PropertyModel<T> : AbstractPropertyModel
    {
        public static int StaticProperty { get; set; }
        public override int OverrideProperty { get; set; }
        public virtual int VirtualProperty { get; set; }
        internal int InternalProperty { get; set; }
        private int PrivateProperty { get; set; }
        protected int ProtectedProperty { get; set; }
        protected internal int ProtectedInternalProperty { get; set; }
        public int PublicProperty { get; set; }
        public int PublicGetterPrivateSetterProperty { get; private set; }
        public int PrivateGetterPublicSetterProperty { private get; set; }
        public T GenericProperty { get; set; }
        public T this[T param1, int param2] { get { return param1; }}
        public override int AbstractProperty { get; set; }
    }

    public abstract class AbstractPropertyModel
    {
        public abstract int AbstractProperty { get; set; }
        public virtual int OverrideProperty { get; set; }
    }
}
;