Beispiel #1
0
        internal bool AddLazyItems(ObjectId oid, ModelProperty property, IEnumerable <LazyValue> values, bool creating)
        {
            bool changed = false;
            GreenModelUpdateContext ctx = null;

            try
            {
                var slot = oid.Descriptor.GetSlot(property);
                do
                {
                    ctx = this.BeginUpdate();
                    foreach (var value in values)
                    {
                        changed = ctx.Updater.AddItem(this.id, oid, slot, creating, false, -1, value);
                    }
                } while (!this.EndUpdate(ctx));
            }
            finally
            {
                this.FinalizeUpdate(ctx);
            }
            return(changed);
        }
Beispiel #2
0
 public LazyEvalEntry(IModelObject symbol, ModelProperty property)
 {
     this.symbol   = symbol;
     this.property = property;
 }
        private void CreateProperties()
        {
            var allProperties = ArrayBuilder <ModelProperty> .GetInstance();

            var properties = ArrayBuilder <ModelProperty> .GetInstance();

            try
            {
                foreach (var baseDescriptor in this.AllBaseDescriptors.Reverse())
                {
                    foreach (var prop in baseDescriptor.allProperties)
                    {
                        if (!allProperties.Contains(prop))
                        {
                            allProperties.Add(prop);
                            if (prop.IsName)
                            {
                                this.nameProperty = prop;
                            }
                            if (prop.IsType)
                            {
                                this.typeProperty = prop;
                            }
                        }
                    }
                }
                allProperties.AddRange(this.declaredProperties);
                foreach (var prop in this.declaredProperties)
                {
                    if (prop.IsName)
                    {
                        this.nameProperty = prop;
                    }
                    if (prop.IsType)
                    {
                        this.typeProperty = prop;
                    }
                }
                foreach (var prop in allProperties)
                {
                    int nameIndex = properties.FindIndex(p => p.Name == prop.Name);
                    if (nameIndex >= 0)
                    {
                        properties.RemoveAt(nameIndex);
                    }
                    foreach (var redefProp in prop.RedefinedProperties)
                    {
                        int index = properties.IndexOf(redefProp);
                        if (index >= 0)
                        {
                            properties.RemoveAt(index);
                        }
                    }
                    properties.Add(prop);
                }
            }
            finally
            {
                ImmutableInterlocked.InterlockedExchange(ref this.allProperties, allProperties.ToImmutableAndFree());
                ImmutableInterlocked.InterlockedExchange(ref this.properties, properties.ToImmutableAndFree());
            }
        }
Beispiel #4
0
 public void MAttachProperty(ModelProperty property)
 {
     this.model.MAttachProperty(this.id, property);
 }
Beispiel #5
0
 protected void SetLazyReference <TImmutableContext, TMutableContext, TImmutable, TMutable>(ModelProperty property, Func <TImmutableContext, IEnumerable <TImmutable> > immutableValue, Func <TMutableContext, IEnumerable <TMutable> > mutableValue)
     where TImmutableContext : ImmutableObject
     where TMutableContext : MutableObject
     where TImmutable : class
     where TMutable : class
 {
     this.model.SetLazyValue(this.id, property, LazyValue.CreateMulti(immutableValue, mutableValue), this.creating);
 }
 public bool MHasDefaultValue(ModelProperty property)
 {
     return(this.model.MHasDefaultValue(this.id, property));
 }
        public T MGetValue <T>(ModelProperty property) where T : struct
        {
            T dummy = default;

            return(this.GetValue <T>(property, ref dummy));
        }
Beispiel #8
0
 protected void SetLazyValue <TContext, T>(ModelProperty property, Func <TContext, T> value)
     where TContext : IModelObject
     where T : struct
 {
     this.model.SetLazyValue(this.id, property, LazyValue.Create(value), this.creating);
 }
Beispiel #9
0
 protected void SetLazyValue <TImmutableContext, TMutableContext, TImmutable, TMutable>(ModelProperty property, Func <TImmutableContext, TImmutable> immutableValue, Func <TMutableContext, TMutable> mutableValue)
     where TImmutableContext : ImmutableObject
     where TMutableContext : MutableObject
     where TImmutable : struct
     where TMutable : struct
 {
     this.model.SetLazyValue(this.id, property, LazyValue.Create(immutableValue, mutableValue), this.creating);
 }
Beispiel #10
0
 protected T GetReference <T>(ModelProperty property)
     where T : class
 {
     return((T)this.model.GetValue(this.id, property));
 }
Beispiel #11
0
 protected Func <T> GetLazyValue <T>(ModelProperty property)
     where T : struct
 {
     return((Func <T>)(object) this.model.GetLazyValue(this.id, property));
 }
Beispiel #12
0
 protected void SetValue <T>(ModelProperty property, T value)
     where T : struct
 {
     this.model.SetValue(this.id, property, value, this.creating);
 }
Beispiel #13
0
 public T MGetReference <T>(ModelProperty property) where T : class
 {
     return(this.GetReference <T>(property));
 }
Beispiel #14
0
 public T MGetValue <T>(ModelProperty property) where T : struct
 {
     return(this.GetValue <T>(property));
 }
 public object MGet(ModelProperty property)
 {
     return(this.model.MGet(this.id, property));
 }
Beispiel #16
0
 protected Func <T> GetLazyReference <T>(ModelProperty property)
     where T : class
 {
     return((Func <T>) this.model.GetLazyValue(this.id, property));
 }
 public bool MIsSet(ModelProperty property)
 {
     return(this.model.MIsSet(this.id, property));
 }
Beispiel #18
0
 protected void SetLazyReference <T>(ModelProperty property, Func <T> value)
     where T : class
 {
     this.model.SetLazyValue(this.id, property, LazyValue.Create(value), this.creating);
 }
 public bool MHasConcreteValue(ModelProperty property)
 {
     return(this.model.MHasConcreteValue(this.id, property));
 }
Beispiel #20
0
 protected void SetLazyReference <TContext, T>(ModelProperty property, Func <TContext, IEnumerable <T> > value)
     where TContext : IModelObject
     where T : class
 {
     this.model.SetLazyValue(this.id, property, LazyValue.CreateMulti(value), this.creating);
 }
        public T MGetReference <T>(ModelProperty property) where T : class
        {
            T dummy = null;

            return(this.GetReference <T>(property, ref dummy));
        }
Beispiel #22
0
        public void Initialize()
        {
            if (this.state == ModelPropertyInitState.Initialized)
            {
                return;
            }
            lock (ModelProperty.lockObject)
            {
                if (this.state == ModelPropertyInitState.Initialized)
                {
                    return;
                }
                if (this.state == ModelPropertyInitState.None)
                {
                    this.InitializeFlags();
                }
                var subsettedPropertiesBuilder = ArrayBuilder <ModelProperty> .GetInstance();

                var redefinedPropertiesBuilder = ArrayBuilder <ModelProperty> .GetInstance();

                var oppositePropertiesBuilder = ArrayBuilder <ModelProperty> .GetInstance();

                foreach (var annot in this.annotations)
                {
                    if (annot is SubsetsAttribute)
                    {
                        SubsetsAttribute      propAnnot  = (SubsetsAttribute)annot;
                        ModelObjectDescriptor descriptor = ModelObjectDescriptor.GetDescriptorForDescriptorType(propAnnot.DeclaringType);
                        ModelProperty         prop       = descriptor.GetDeclaredProperty(propAnnot.PropertyName);
                        if (prop == null)
                        {
                            throw new InvalidOperationException("Error subsetting property: " + this.FullDeclaredName + "->" + prop.FullDeclaredName + ". The subsetted property cannot be found.");
                        }
                        if ((descriptor == this.declaringDescriptor || this.declaringDescriptor.AllBaseDescriptors.Contains(descriptor)))
                        {
                            if (!this.IsUnique)
                            {
                                throw new InvalidOperationException("Error subsetting property: " + this.FullDeclaredName + "->" + prop.FullDeclaredName + ". The subsetting property must be a collection of unique values.");
                            }
                            if (!prop.IsUnique)
                            {
                                throw new InvalidOperationException("Error subsetting property: " + this.FullDeclaredName + "->" + prop.FullDeclaredName + ". The subsetted property must be a collection of unique values.");
                            }
                            subsettedPropertiesBuilder.Add(prop);
                        }
                        else
                        {
                            throw new InvalidOperationException("Error subsetting property: " + this.FullDeclaredName + "->" + prop.FullDeclaredName + ". The subsetted property must come from the current type or from a base type.");
                        }
                    }
                    else if (annot is RedefinesAttribute)
                    {
                        RedefinesAttribute    propAnnot  = (RedefinesAttribute)annot;
                        ModelObjectDescriptor descriptor = ModelObjectDescriptor.GetDescriptorForDescriptorType(propAnnot.DeclaringType);
                        ModelProperty         prop       = descriptor.GetDeclaredProperty(propAnnot.PropertyName);
                        if (prop == null)
                        {
                            throw new InvalidOperationException("Error redefining property: " + this.FullDeclaredName + "->" + prop.FullDeclaredName + ". The redefined property cannot be found.");
                        }
                        if ((descriptor == this.declaringDescriptor || this.declaringDescriptor.AllBaseDescriptors != null && this.declaringDescriptor.AllBaseDescriptors.Contains(descriptor)))
                        {
                            if (this.IsContainment && !prop.IsContainment)
                            {
                                throw new InvalidOperationException("Error redefining property: " + this.FullDeclaredName + "->" + prop.FullDeclaredName + ". The redefining property cannot be a containment if the redefined property is not a containment.");
                            }
                            redefinedPropertiesBuilder.Add(prop);
                        }
                        else
                        {
                            throw new InvalidOperationException("Error redefining property: " + this.FullDeclaredName + "->" + prop.FullDeclaredName + ". The redefined property must come from the current type or from a base type.");
                        }
                    }
                    else if (annot is OppositeAttribute)
                    {
                        OppositeAttribute     propAnnot  = (OppositeAttribute)annot;
                        ModelObjectDescriptor descriptor = ModelObjectDescriptor.GetDescriptorForDescriptorType(propAnnot.DeclaringType);
                        ModelProperty         prop       = descriptor.GetDeclaredProperty(propAnnot.PropertyName);
                        if (prop == null)
                        {
                            throw new InvalidOperationException("Error in setting opposite property: " + this.FullDeclaredName + "->" + propAnnot.DeclaringType + "." + propAnnot.PropertyName + ". The opposite property cannot be found.");
                        }
                        bool foundThisProperty = false;
                        foreach (var oppositeAnnot in prop.annotations)
                        {
                            if (oppositeAnnot is OppositeAttribute)
                            {
                                OppositeAttribute propOppositeAnnot = (OppositeAttribute)oppositeAnnot;
                                if (propOppositeAnnot.DeclaringType == this.declaringDescriptor.DescriptorType &&
                                    propOppositeAnnot.PropertyName == this.name)
                                {
                                    foundThisProperty = true;
                                    break;
                                }
                            }
                        }
                        if (foundThisProperty)
                        {
                            oppositePropertiesBuilder.Add(prop);
                        }
                        else
                        {
                            throw new InvalidOperationException("Error in setting opposite property: " + this.FullDeclaredName + "->" + prop.FullDeclaredName + ". Opposite properties must be mutual.");
                        }
                    }
                    else if (annot is DerivedUnionAttribute)
                    {
                        if (!this.IsUnique)
                        {
                            throw new InvalidOperationException("Error in property: " + this.FullDeclaredName + ". A derived union property must be contain unique values.");
                        }
                        this.flags |= ModelPropertyFlags.DerivedUnion | ModelPropertyFlags.Readonly;
                    }
                }
                subsettedProperties = subsettedPropertiesBuilder.ToImmutableAndFree();
                redefinedProperties = redefinedPropertiesBuilder.ToImmutableAndFree();
                oppositeProperties  = oppositePropertiesBuilder.ToImmutableAndFree();
                this.state          = ModelPropertyInitState.Initialized;
            }
        }