public static string BuildPath(IStructureProperty parent, string name) { if (parent == null) return name; return string.Concat(parent.Path, ".", name); }
public IndexAccessor(IStructureProperty property, DataTypeCode dataTypeCode) : base(property) { _callstack = GetCallstack(Property); _callstack.Reverse(); DataTypeCode = dataTypeCode; }
public static string BuildPath(IStructureProperty property) { if (property.IsRootMember) return property.Name; return string.Concat(BuildPath(property.Parent), ".", property.Name); }
private static IList <object> ExtractValuesForEnumerableNode <T>(T nodes, IStructureProperty property) where T : IEnumerable { var values = new List <object>(); foreach (var node in nodes) { if (node == null) { values.Add(null); continue; } var nodeValue = property.GetValue(node); if (nodeValue == null) { values.Add(null); continue; } if (ValueIsEnumerable(nodeValue)) { values.AddRange(CollectionOfValuesToList((IEnumerable)nodeValue)); } else { values.Add(nodeValue); } } return(values); }
public virtual IStructureProperty CreateChildPropertyFrom(IStructureProperty parent, PropertyInfo propertyInfo) { return new StructureProperty( ConvertInfo(propertyInfo, parent), DynamicPropertyFactory.GetterFor(propertyInfo), DynamicPropertyFactory.SetterFor(propertyInfo)); }
protected virtual StructurePropertyInfo ConvertInfo(PropertyInfo propertyInfo, IStructureProperty parent = null) { return new StructurePropertyInfo( propertyInfo.Name, propertyInfo.PropertyType, parent, GetUniqueMode(propertyInfo)); }
public StructurePropertyInfo(string name, Type dataType, IStructureProperty parent = null, UniqueModes?uniqueMode = null) { Ensure.That(name, "name").IsNotNullOrWhiteSpace(); Ensure.That(dataType, "dataType").IsNotNull(); Parent = parent; Name = name; DataType = dataType; UniqueMode = uniqueMode; }
public StructurePropertyInfo(string name, Type dataType, IStructureProperty parent = null, UniqueModes? uniqueMode = null) { Ensure.That(name, "name").IsNotNullOrWhiteSpace(); Ensure.That(dataType, "dataType").IsNotNull(); Parent = parent; Name = name; DataType = dataType; UniqueMode = uniqueMode; }
public StructureType(Type type, IStructureProperty idProperty = null, IStructureProperty concurrencyTokenProperty = null, IStructureProperty timeStampProperty = null, IStructureProperty[] indexableProperties = null, IStructureProperty[] containedStructureProperties = null) { Ensure.That(type, "type").IsNotNull(); Type = type; IdProperty = idProperty; ConcurrencyTokenProperty = concurrencyTokenProperty; TimeStampProperty = timeStampProperty; IndexableProperties = indexableProperties ?? new IStructureProperty[] { }; ContainedStructureProperties = containedStructureProperties ?? new IStructureProperty[] { }; }
private static IList <object> ExtractValuesForSimpleNode(object node, IStructureProperty property) { var currentValue = property.GetValue(node); if (currentValue == null) { return(null); } if (!property.IsEnumerable) { return new[] { currentValue } } ; return(CollectionOfValuesToList((IEnumerable)currentValue)); }
public IdAccessor(IStructureProperty property) : base(property) { if (!property.IsRootMember) { throw new SisoDbException(ExceptionMessages.IdAccessor_InvalidLevel); } if (!StructureId.IsValidDataType(property.DataType)) { throw new SisoDbException(ExceptionMessages.IdAccessor_UnsupportedPropertyType.Inject(Property.DataType.Name)); } IdType = StructureId.GetIdTypeFrom(property.DataType); _getter = StructureIdGetters.For(IdType, Property.DataType); _setter = StructureIdSetters.For(IdType, Property.DataType); }
private static List <IStructureProperty> GetCallstack(IStructureProperty property) { if (property.IsRootMember) { return new List <IStructureProperty> { property } } ; var props = new List <IStructureProperty> { property }; props.AddRange( GetCallstack(property.Parent)); return(props); }
protected virtual PropertyInfo[] GetEnumerableIndexablePropertyInfos(PropertyInfo[] properties, IStructureProperty parent = null, ICollection<string> nonIndexablePaths = null, ICollection<string> indexablePaths = null) { if (properties.Length == 0) return new PropertyInfo[0]; var filteredProperties = properties.Where(p => !p.PropertyType.IsSimpleType() && p.PropertyType.IsEnumerableType() && !p.PropertyType.IsEnumerableBytesType()); if (nonIndexablePaths != null && nonIndexablePaths.Any()) filteredProperties = filteredProperties.Where(p => !nonIndexablePaths.Contains( PropertyPathBuilder.BuildPath(parent, p.Name))); if (indexablePaths != null && indexablePaths.Any()) filteredProperties = filteredProperties.Where(p => indexablePaths.Contains( PropertyPathBuilder.BuildPath(parent, p.Name))); return filteredProperties.ToArray(); }
protected virtual IStructureProperty[] GetIndexableProperties( IReflect type, IStructureProperty parent, ICollection<string> nonIndexablePaths, ICollection<string> indexablePaths) { var initialPropertyInfos = GetIndexablePropertyInfos(type); if (initialPropertyInfos.Length == 0) return new IStructureProperty[] { }; var properties = new List<IStructureProperty>(); var simplePropertyInfos = GetSimpleIndexablePropertyInfos(initialPropertyInfos, parent, nonIndexablePaths, indexablePaths); properties.AddRange(simplePropertyInfos.Select(spi => PropertyFactory.CreateChildPropertyFrom(parent, spi))); initialPropertyInfos = initialPropertyInfos.Where(p => !simplePropertyInfos.Contains(p)).ToArray(); foreach (var complexPropertyInfo in GetComplexIndexablePropertyInfos(initialPropertyInfos, parent, nonIndexablePaths, indexablePaths)) { var complexProperty = PropertyFactory.CreateChildPropertyFrom(parent, complexPropertyInfo); var simpleComplexProps = GetIndexableProperties( complexProperty.DataType, complexProperty, nonIndexablePaths, indexablePaths); var beforeCount = properties.Count; properties.AddRange(simpleComplexProps); if (properties.Count == beforeCount && complexProperty.DataType.IsValueType) properties.Add(complexProperty); } foreach (var enumerablePropertyInfo in GetEnumerableIndexablePropertyInfos(initialPropertyInfos, parent, nonIndexablePaths, indexablePaths)) { var enumerableProperty = PropertyFactory.CreateChildPropertyFrom(parent, enumerablePropertyInfo); if (enumerableProperty.ElementDataType.IsSimpleType()) { properties.Add(enumerableProperty); continue; } var elementProperties = GetIndexableProperties( enumerableProperty.ElementDataType, enumerableProperty, nonIndexablePaths, indexablePaths); properties.AddRange(elementProperties); } return properties.ToArray(); }
protected MemberAccessorBase(IStructureProperty property) { Property = property; }
public virtual DataTypeCode Convert(IStructureProperty property) { return Convert(property.ElementDataType ?? property.DataType, property.Name); }
internal static IIndexAccessor CreateFor(IStructureProperty property) { return new IndexAccessor(property, DataTypeConverter.Convert(property)); }