public void GetProperty_will_throw_on_invalid_property_name(IPropertyProvider pp) { Assert.Throws <ArgumentException>(() => pp.GetProperty("")); Assert.Throws <ArgumentException>(() => pp.GetProperty(null)); Assert.Throws <ArgumentException>(() => pp.TryGetProperty("", typeof(object), out _)); Assert.Throws <ArgumentException>(() => pp.TryGetProperty(null, typeof(object), out _)); }
public override bool TryGetMember(GetMemberBinder binder, out object result) { if (binder == null) { throw new ArgumentNullException("binder"); } if (_selfValues.TryGetProperty(binder.Name, typeof(object), out result)) { return(true); } bool flag = this.Data.TryGetValue(binder.Name, out result); if (!flag && this.Parent != null) { return(this.Parent.TryGetMember(binder, out result)); } if (!flag) { result = "undefined"; } // TODO Friendly error message (currently, "TemplateContext doesn't contain a defintion") return(true); }
internal static Type InferPropertyType(IPropertyProvider self, string property) { if (self.TryGetProperty(property, typeof(object), out object value)) { return(value == null ? typeof(object) : value.GetType()); } return(null); }
public bool TryGetProperty(string property, Type propertyType, out object value) { if (FilteredOut(property)) { value = null; return(false); } return(_propertyProvider.TryGetProperty(property, propertyType, out value)); }
public static bool HasProperty(this IPropertyProvider source, string property) { if (source == null) { throw new ArgumentNullException("source"); } object dummy; return(source.TryGetProperty(property, out dummy)); }
public static T GetProperty <T>(this IPropertyProvider source, string property, T defaultValue) { if (source == null) { throw new ArgumentNullException("source"); } object result; if (source.TryGetProperty(property, typeof(T), out result)) { return((T)result); } else { return(defaultValue); } }
public static bool TryGetProperty <T>(this IPropertyProvider source, string property, out T value) { if (source == null) { throw new ArgumentNullException("source"); } object objValue; bool result = source.TryGetProperty(property, typeof(T), out objValue); if (result && objValue is T) { value = (T)objValue; return(true); } else { value = default(T); return(false); } }