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;
}