public static void Main()
Console.WriteLine("Hello World");
string s = (string)f["Bar"];
f["FirstName"] = "stephany";
if (f.GetType().GetProperty("Rooms44") != null)
Console.WriteLine("Property Exists");
Console.WriteLine("Property Doesn't Exist");
SetValue(f,"CampaignId",cid);
SetValue(f,"Rooms",rooms);
Console.WriteLine(f.Bar.ToString());
Console.WriteLine(f.FirstName.ToString());
Console.WriteLine(f.CampaignId.ToString());
Console.WriteLine(f["FirstName"].ToString());
Console.WriteLine((f["Rooms"]??"null"));
public object this[string propertyName]
get { return this.GetType().GetProperty(propertyName).GetValue(this, null); }
set { this.GetType().GetProperty(propertyName).SetValue(this, value, null); }
public string Bar { get; set; }
public string FirstName { get; set; }
public int CampaignId { get; set; }
public string Rooms { get; set; }
public static void SetValue(object inputObject, string propertyName, object propertyVal)
Type type = inputObject.GetType();
System.Reflection.PropertyInfo propertyInfo = type.GetProperty(propertyName);
Type propertyType = propertyInfo.PropertyType;
var targetType = IsNullableType(propertyInfo.PropertyType) ? Nullable.GetUnderlyingType(propertyInfo.PropertyType) : propertyInfo.PropertyType;
propertyVal = Convert.ChangeType(propertyVal, targetType);
propertyInfo.SetValue(inputObject, propertyVal, null);
private static bool IsNullableType(Type type)
return type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable<>));