Esempio n. 1
0
 public ImmutableObject ToImmutable(ImmutableModel immutableModel)
 {
     if (immutableModel == null)
     {
         throw new ArgumentNullException(nameof(immutableModel));
     }
     return(immutableModel.GetObject(this));
 }
Esempio 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);
 }
Esempio 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);
 }
 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;
 }
Esempio 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);
     }
 }
Esempio 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);
        }
Esempio n. 7
0
 public abstract ImmutableObjectBase CreateImmutable(ImmutableModel model);
 internal static ImmutableModelList <T> FromGreenSingleValue(object value, ImmutableModel model, ObjectId context)
 {
     return(new ImmutableModelListFromGreenSingle <T>(value, model, context));
 }
 internal static ImmutableModelList <T> FromObjectIdList(ImmutableList <ObjectId> green, ImmutableModel model)
 {
     return(new ImmutableModelListFromObjectIdListImmutable <T>(green, model));
 }
Esempio n. 10
0
 internal static ImmutableModelList <T> FromGreenList(GreenList green, ImmutableModel model, ObjectId context)
 {
     return(new ImmutableModelListFromGreenListImmutable <T>(green, model, context));
 }
Esempio n. 11
0
 internal ImmutableModelListFromGreenSingle(object greenValue, ImmutableModel model, ObjectId context)
 {
     this.greenValue = greenValue;
     this.model      = model;
     this.context    = context;
 }
Esempio n. 12
0
 internal ImmutableModelListFromObjectIdListImmutable(ImmutableList <ObjectId> green, ImmutableModel model)
 {
     this.green = green;
     this.model = model;
 }
Esempio n. 13
0
 internal ImmutableModelListFromGreenListImmutable(GreenList green, ImmutableModel model, ObjectId context)
 {
     this.green   = green;
     this.model   = model;
     this.context = context;
 }
Esempio n. 14
0
 public void AddModel(ImmutableModel model)
 {
     // TODO
     throw new NotImplementedException();
 }
 internal ImmutableObjectBase CreateImmutable(ImmutableModel model)
 {
     return(this.CreateObjectId().CreateImmutable(model));
 }
Esempio n. 16
0
        public ImmutableObject ToImmutable()
        {
            ImmutableModel immutableModel = this.model.ToImmutable();

            return(immutableModel.GetObject(this));
        }