Exemplo n.º 1
0
 public ImmutableObject ToImmutable(ImmutableModel immutableModel)
 {
     if (immutableModel == null)
     {
         throw new ArgumentNullException(nameof(immutableModel));
     }
     return(immutableModel.GetObject(this));
 }
Exemplo n.º 2
0
 internal MutableModel(GreenModel green, ImmutableModel immutableModel)
 {
     this.id             = green.Id;
     this.group          = null;
     this.green          = green;
     this.updater        = new ThreadLocal <GreenModelUpdater>();
     this.readOnly       = false;
     this.objects        = new ConditionalWeakTable <ObjectId, MutableObject>();
     this.immutableModel = new WeakReference <ImmutableModel>(immutableModel);
 }
Exemplo n.º 3
0
 internal MutableModel(ModelId id, MutableModelGroup group, bool readOnly, ImmutableModel immutableModel)
 {
     this.id             = id;
     this.group          = group;
     this.green          = null;
     this.updater        = null;
     this.readOnly       = readOnly;
     this.objects        = null;
     this.immutableModel = new WeakReference <ImmutableModel>(immutableModel);
 }
Exemplo n.º 4
0
 protected ImmutableObjectBase(ObjectId id, ImmutableModel model)
 {
     if (id == null)
     {
         throw new ArgumentNullException(nameof(id));
     }
     if (model == null)
     {
         throw new ArgumentNullException(nameof(model));
     }
     this.id    = id;
     this.model = model;
 }
Exemplo n.º 5
0
 public void AddReference(ImmutableModel reference)
 {
     if (reference.ModelGroup != null)
     {
         GreenModelGroup gmg = reference.ModelGroup.Green;
         foreach (var greenReference in gmg.References)
         {
             this.AddReference(greenReference.Value);
         }
         foreach (var greenModel in gmg.Models)
         {
             this.AddReference(greenModel.Value);
         }
     }
     else
     {
         this.AddReference(reference.Green);
     }
 }
Exemplo n.º 6
0
        public ImmutableModel ToImmutable(bool evaluateLazyValues = true, CancellationToken cancellationToken = default)
        {
            ImmutableModel result;

            if (this.group != null)
            {
                ImmutableModelGroup immutableGroup = this.group.ToImmutable(evaluateLazyValues, cancellationToken);
                if (immutableGroup != null)
                {
                    if (this.readOnly)
                    {
                        result = immutableGroup.GetReference(this.id);
                    }
                    else
                    {
                        result = immutableGroup.GetModel(this.id);
                    }
                    return(result);
                }
            }
            else
            {
                if (evaluateLazyValues)
                {
                    this.EvaluateLazyValues(cancellationToken);
                }
                GreenModel currentGreen = this.Green;
                if (this.immutableModel.TryGetTarget(out result) && result != null && result.Green == currentGreen)
                {
                    return(result);
                }
                else
                {
                    result = new ImmutableModel(currentGreen, this);
                    Interlocked.Exchange(ref this.immutableModel, new WeakReference <ImmutableModel>(result));
                    return(result);
                }
            }
            return(null);
        }
Exemplo n.º 7
0
 public abstract ImmutableObjectBase CreateImmutable(ImmutableModel model);
Exemplo n.º 8
0
 internal static ImmutableModelList <T> FromGreenSingleValue(object value, ImmutableModel model, ObjectId context)
 {
     return(new ImmutableModelListFromGreenSingle <T>(value, model, context));
 }
Exemplo n.º 9
0
 internal static ImmutableModelList <T> FromObjectIdList(ImmutableList <ObjectId> green, ImmutableModel model)
 {
     return(new ImmutableModelListFromObjectIdListImmutable <T>(green, model));
 }
Exemplo n.º 10
0
 internal static ImmutableModelList <T> FromGreenList(GreenList green, ImmutableModel model, ObjectId context)
 {
     return(new ImmutableModelListFromGreenListImmutable <T>(green, model, context));
 }
Exemplo n.º 11
0
 internal ImmutableModelListFromGreenSingle(object greenValue, ImmutableModel model, ObjectId context)
 {
     this.greenValue = greenValue;
     this.model      = model;
     this.context    = context;
 }
Exemplo n.º 12
0
 internal ImmutableModelListFromObjectIdListImmutable(ImmutableList <ObjectId> green, ImmutableModel model)
 {
     this.green = green;
     this.model = model;
 }
Exemplo n.º 13
0
 internal ImmutableModelListFromGreenListImmutable(GreenList green, ImmutableModel model, ObjectId context)
 {
     this.green   = green;
     this.model   = model;
     this.context = context;
 }
Exemplo n.º 14
0
 public void AddModel(ImmutableModel model)
 {
     // TODO
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 internal ImmutableObjectBase CreateImmutable(ImmutableModel model)
 {
     return(this.CreateObjectId().CreateImmutable(model));
 }
Exemplo n.º 16
0
        public ImmutableObject ToImmutable()
        {
            ImmutableModel immutableModel = this.model.ToImmutable();

            return(immutableModel.GetObject(this));
        }