using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Artemis.Core.Modules;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Core;
///
/// Represents a path that points to a property in data model
///
public class DataModelPath : IStorageModel, IDisposable
{
private readonly List _segments;
private Expression>? _accessorLambda;
private bool _disposed;
///
/// Creates a new instance of the class pointing directly to the target
///
/// The target at which this path starts
public DataModelPath(DataModel target)
{
Target = target ?? throw new ArgumentNullException(nameof(target));
Path = "";
Entity = new DataModelPathEntity();
_segments = new List();
Save();
Initialize();
SubscribeToDataModelStore();
}
///
/// Creates a new instance of the class pointing to the provided path
///
/// The target at which this path starts
/// A point-separated path
public DataModelPath(DataModel target, string path)
{
Target = target ?? throw new ArgumentNullException(nameof(target));
Path = path ?? throw new ArgumentNullException(nameof(path));
Entity = new DataModelPathEntity();
_segments = new List();
Save();
Initialize();
SubscribeToDataModelStore();
}
///
/// Creates a new instance of the class based on an existing path
///
/// The path to base the new instance on
public DataModelPath(DataModelPath dataModelPath)
{
if (dataModelPath == null)
throw new ArgumentNullException(nameof(dataModelPath));
Target = dataModelPath.Target;
Path = dataModelPath.Path;
Entity = new DataModelPathEntity();
_segments = new List();
Save();
Initialize();
SubscribeToDataModelStore();
}
///
/// Creates a new instance of the class based on a
///
///
public DataModelPath(DataModelPathEntity entity)
{
Path = entity.Path;
Entity = entity;
_segments = new List();
Load();
Initialize();
SubscribeToDataModelStore();
}
///
/// Gets the data model at which this path starts
///
public DataModel? Target { get; private set; }
///
/// Gets the data model ID of the if it is a
///
public string? DataModelId => Target?.Module.Id;
///
/// Gets the point-separated path associated with this
///
public string Path { get; private set; }
///
/// Gets a boolean indicating whether all are valid
///
public bool IsValid => _segments.Count != 0 && _segments.All(p => p.Type != DataModelPathSegmentType.Invalid);
///
/// Gets a read-only list of all segments of this path
///
public IReadOnlyCollection Segments => _segments;
///
/// Gets the entity used for persistent storage
///
public DataModelPathEntity Entity { get; }
internal Func