Represents the information stored about a property in the class schema.
Beispiel #1
0
        /// <summary>
        /// Modifies the attributes for a property in the schema.
        /// </summary>
        /// <param name="key"> The property key of the property to modify. </param>
        /// <param name="attributes"> The new attributes. </param>
        /// <returns> A new schema with the modified property. </returns>
        public HiddenClassSchema SetPropertyAttributes(object key, PropertyAttributes attributes)
        {
            // Package the name and attributes into a struct.
            var transitionInfo = new TransitionInfo()
            {
                Key = key, Attributes = attributes
            };

            // Check if there is a transition to the schema already.
            HiddenClassSchema newSchema = null;

            if (this.modifyTransitions != null)
            {
                this.modifyTransitions.TryGetValue(transitionInfo, out newSchema);
            }

            if (newSchema == null)
            {
                // Create the properties dictionary if it hasn't already been created.
                if (this.properties == null)
                {
                    this.properties = CreatePropertiesDictionary();
                }

                // Check the attributes differ from the existing attributes.
                SchemaProperty propertyInfo;
                if (this.properties.TryGetValue(key, out propertyInfo) == false)
                {
                    throw new InvalidOperationException(string.Format("The property '{0}' does not exist.", key));
                }
                if (attributes == propertyInfo.Attributes)
                {
                    return(this);
                }

                // Create a new schema based on this one.
                var properties = new Dictionary <object, SchemaProperty>(this.properties);
                properties[key] = new SchemaProperty(propertyInfo.Index, attributes);
                newSchema       = new HiddenClassSchema(properties, this.NextValueIndex);

                // Add a transition to the new schema.
                if (this.modifyTransitions == null)
                {
                    this.modifyTransitions = new Dictionary <TransitionInfo, HiddenClassSchema>(1);
                }
                this.modifyTransitions.Add(transitionInfo, newSchema);
            }

            return(newSchema);
        }
        /// <summary>
        /// Modifies the attributes for a property in the schema.
        /// </summary>
        /// <param name="name"> The name of the property to modify. </param>
        /// <param name="attributes"> The new attributes. </param>
        /// <returns> A new schema with the modified property. </returns>
        public HiddenClassSchema SetPropertyAttributes(string name, PropertyAttributes attributes)
        {
            // Package the name and attributes into a struct.
            var transitionInfo = new TransitionInfo() { Name = name, Attributes = attributes };

            // Check if there is a transition to the schema already.
            HiddenClassSchema newSchema = null;
            if (this.modifyTransitions != null)
                this.modifyTransitions.TryGetValue(transitionInfo, out newSchema);

            if (newSchema == null)
            {
                // Create the properties dictionary if it hasn't already been created.
                if (this.properties == null)
                    this.properties = CreatePropertiesDictionary();

                // Check the attributes differ from the existing attributes.
                SchemaProperty propertyInfo;
                if (this.properties.TryGetValue(name, out propertyInfo) == false)
                    throw new InvalidOperationException(string.Format("The property '{0}' does not exist.", name));
                if (attributes == propertyInfo.Attributes)
                    return this;

                // Create a new schema based on this one.
                var properties = new Dictionary<string, SchemaProperty>(this.properties);
                properties[name] = new SchemaProperty(propertyInfo.Index, attributes);
                newSchema = new HiddenClassSchema(properties, this.NextValueIndex);

                // Add a transition to the new schema.
                if (this.modifyTransitions == null)
                    this.modifyTransitions = new Dictionary<TransitionInfo, HiddenClassSchema>(1);
                this.modifyTransitions.Add(transitionInfo, newSchema);
            }

            return newSchema;
        }