using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Artemis.Core.DataModelExpansions;
namespace Artemis.Core
{
///
/// Represents a path that points to a property in data model
///
public class DataModelPath
{
private readonly LinkedList _segments;
///
/// Creates a new instance of the class
///
/// The data model at which this path starts
/// A string representation of the
public DataModelPath(object dataModel, string path)
{
Target = dataModel ?? throw new ArgumentNullException(nameof(dataModel));
Path = path ?? throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(Path))
throw new ArgumentException("Path cannot be empty");
_segments = new LinkedList();
Initialize(path);
}
///
/// Gets the data model at which this path starts
///
public object Target { get; }
///
/// Gets a string representation of the
///
public string Path { get; }
///
/// Gets a boolean indicating whether all are valid
///
public bool IsValid => Segments.All(p => p.Type != DataModelPathSegmentType.Invalid);
///
/// Gets a read-only list of all segments of this path
///
public IReadOnlyCollection Segments => _segments.ToList().AsReadOnly();
///
/// Gets a boolean indicating whether this data model path can have an inner path because it points to a list
///
public bool CanHaveInnerPath => Segments.LastOrDefault()?.GetPropertyType()?.IsAssignableFrom(typeof(IList)) ?? false;
///
/// Gets the inner path of this path, only available if this path points to a list
///
public DataModelPath InnerPath { get; internal set; }
internal Func