public void SetProperty <T>(string propertyName, T value) { PostingProperty property = Properties.FirstOrDefault(p => p.Name == propertyName); if (property == null) { property = new PostingProperty { Posting = this, Name = propertyName }; Properties.Add(property); } object val = value; if (typeof(T) == typeof(int)) { property.IntValue = (int)val; } if (typeof(T) == typeof(string)) { property.StringValue = (string)val; } if (typeof(T) == typeof(double)) { property.DoubleValue = (double)val; } property.Save(); }
public T GetProperty <T>(string propertyName) { if (Properties == null) { return(default(T)); } PostingProperty property = Properties.FirstOrDefault(p => p.Name == propertyName); if (property == null) { return(default(T)); } object o = null; if (typeof(T) == typeof(int)) { o = property.IntValue; } if (typeof(T) == typeof(string)) { o = property.StringValue; } if (typeof(T) == typeof(double)) { o = property.DoubleValue; } return((T)o); }