public IPropertyFiller GetFiller(PropertyInfo propertyInfo) { IPropertyFiller result = null; Type objectType = propertyInfo.DeclaringType; while (objectType != null && result == null) { //First try to get a specific filler based on a full type name (including namespace) string fullTypeName = objectType.FullName.ToLowerInvariant(); if (_specificPropertyFillersByObjectType.ContainsKey(fullTypeName)) { IDictionary <string, IPropertyFiller> propertyFillers = _specificPropertyFillersByObjectType[fullTypeName]; result = GetMatchingPropertyFiller(propertyInfo, propertyFillers); } //Second try to get a more generic filler based on only the class name (no namespace) if (result == null) { string classTypeName = objectType.Name.ToLowerInvariant(); if (_specificPropertyFillersByObjectType.ContainsKey(classTypeName)) { IDictionary <string, IPropertyFiller> propertyFillers = _specificPropertyFillersByObjectType[classTypeName]; result = GetMatchingPropertyFiller(propertyInfo, propertyFillers); } } objectType = objectType.GetTypeInfo().BaseType; } if (result == null) { //Finally, grab a generic property filler for that property type if (_genericPropertyFillersByPropertyType.ContainsKey(propertyInfo.PropertyType)) { result = _genericPropertyFillersByPropertyType[propertyInfo.PropertyType]; } else if (propertyInfo.PropertyType.GetTypeInfo().BaseType == typeof(System.Enum)) { result = new EnumFiller(propertyInfo.PropertyType); } else { //TODO: Can we build a custom filler here for other value types that we have not explicitly implemented (eg. long, decimal, etc.) result = new CustomFiller <object>("*", typeof(object), true, () => null); _genericPropertyFillersByPropertyType.Add(propertyInfo.PropertyType, result); } } return(result); }
public IPropertyFiller GetFiller(PropertyInfo propertyInfo) { rwl.EnterReadLock(); var newRegistrations = new Dictionary <Type, IPropertyFiller>(); IPropertyFiller result = null; try { Type objectType = propertyInfo.DeclaringType; while (objectType != null && result == null) { //First try to get a specific filler based on a full type name (including namespace) string fullTypeName = objectType.FullName.ToLowerInvariant(); if (_specificPropertyFillersByObjectType.ContainsKey(fullTypeName)) { IDictionary <string, IPropertyFiller> propertyFillers = _specificPropertyFillersByObjectType[fullTypeName]; result = GetMatchingPropertyFiller(propertyInfo, propertyFillers); } //Second try to get a more generic filler based on only the class name (no namespace) if (result == null) { string classTypeName = objectType.Name.ToLowerInvariant(); if (_specificPropertyFillersByObjectType.ContainsKey(classTypeName)) { IDictionary <string, IPropertyFiller> propertyFillers = _specificPropertyFillersByObjectType[classTypeName]; result = GetMatchingPropertyFiller(propertyInfo, propertyFillers); } } objectType = objectType.GetTypeInfo().BaseType; } if (result == null) { //Finally, grab a generic property filler for that property type if (_genericPropertyFillersByPropertyType.ContainsKey(propertyInfo.PropertyType)) { result = _genericPropertyFillersByPropertyType[propertyInfo.PropertyType]; } else if (propertyInfo.PropertyType.GetTypeInfo().BaseType == typeof(System.Enum)) { result = new EnumFiller(this.GenFu, propertyInfo.PropertyType); } else { //TODO: Can we build a custom filler here for other value types that we have not explicitly implemented (eg. long, decimal, etc.) result = new CustomFiller <object>(GenFu, "*", typeof(object), true, () => null); newRegistrations[propertyInfo.PropertyType] = result; } } } finally { rwl.ExitReadLock(); } if (newRegistrations.Any()) { rwl.EnterWriteLock(); foreach (var newRegistration in newRegistrations) { _genericPropertyFillersByPropertyType[newRegistration.Key] = newRegistration.Value; } rwl.ExitWriteLock(); } return(result); }