/// <summary> /// Pretend the get on the property object was called /// This will invoke the normal get, going through all the registered getters /// </summary> /// <param name="propertyName">Name of the property</param> public GetInfo Get(string propertyName) { if (!PropertyTypes.TryGetValue(propertyName, out var propertyType)) { propertyType = typeof(object); } var hasValue = _properties.TryGetValue(propertyName, out var value); var getInfo = new GetInfo { Interceptor = this, PropertyName = propertyName, PropertyType = propertyType, CanContinue = true, Value = value, HasValue = hasValue }; foreach (var getter in _getters) { getter.GetterAction(getInfo); if (!getInfo.CanContinue || getInfo.Error != null) { break; } } return(getInfo); }
/// <summary> /// A default implementation of the get logic /// </summary> /// <param name="getInfo">GetInfo</param> private void DefaultGet(GetInfo getInfo) { if (getInfo.PropertyName == null) { getInfo.HasValue = false; return; } if (getInfo.Interceptor.Properties.TryGetValue(getInfo.PropertyName, out var value)) { getInfo.Value = value; getInfo.HasValue = true; } else { // Make sure we return the right default value, when passed by-ref there needs to be a value if (!PropertyTypes.TryGetValue(getInfo.PropertyName, out var propertyType)) { propertyType = typeof(object); } getInfo.Value = propertyType.CreateInstance(); getInfo.HasValue = false; } }