private void AddBaseDescriptor(ModelObjectDescriptor baseDescriptor)
        {
            if (this.initializedBaseDescriptors)
            {
                throw new InvalidOperationException("Cannot add a base descriptor to an initialized descriptor.");
            }
            ImmutableArray <ModelObjectDescriptor> oldBaseDescriptors;
            ImmutableArray <ModelObjectDescriptor> newBaseDescriptors;

            do
            {
                oldBaseDescriptors = this.baseDescriptors;
                if (!oldBaseDescriptors.Contains(baseDescriptor))
                {
                    newBaseDescriptors = oldBaseDescriptors.Add(baseDescriptor);
                }
                else
                {
                    newBaseDescriptors = oldBaseDescriptors;
                }
            } while (ImmutableInterlocked.InterlockedCompareExchange(ref this.baseDescriptors, newBaseDescriptors, oldBaseDescriptors) != oldBaseDescriptors);
            if (baseDescriptor.IsScope)
            {
                this.metaFlags |= MetaModelObjectFlags.Scope;
            }
            if (baseDescriptor.IsType)
            {
                this.metaFlags |= MetaModelObjectFlags.Type;
            }
        }
 private ModelObjectDescriptor(Type descriptorType)
 {
     this.initialized = false;
     this.initializedBaseDescriptors = false;
     this.descriptorType             = descriptorType;
     this.annotations = descriptorType.GetCustomAttributes(false).OfType <Attribute>().ToImmutableArray();
     this.metaFlags   = MetaModelObjectFlags.None;
     foreach (var annot in this.annotations)
     {
         if (annot is ModelObjectDescriptorAttribute)
         {
             ModelObjectDescriptorAttribute da = (ModelObjectDescriptorAttribute)annot;
             this.idType        = da.IdType;
             this.immutableType = da.ImmutableType;
             this.mutableType   = da.MutableType;
         }
         else if (annot is LocalAttribute)
         {
             this.metaFlags |= MetaModelObjectFlags.Local;
         }
         else if (annot is ScopeAttribute)
         {
             this.metaFlags |= MetaModelObjectFlags.Scope;
         }
         else if (annot is LocalScopeAttribute)
         {
             this.metaFlags |= MetaModelObjectFlags.LocalScope;
         }
         else if (annot is TypeAttribute)
         {
             this.metaFlags |= MetaModelObjectFlags.Type;
         }
     }
     this.nameProperty       = null;
     this.typeProperty       = null;
     this.emptyGreenObject   = GreenObject.Empty;
     this.baseDescriptors    = ImmutableArray <ModelObjectDescriptor> .Empty;
     this.declaredProperties = ImmutableArray <ModelProperty> .Empty;
     this.slotMap            = ImmutableDictionary <ModelProperty, Slot> .Empty;
     this.slots         = ImmutableArray <Slot> .Empty;
     this.allProperties = ImmutableArray <ModelProperty> .Empty;
 }