protected override void InvokeInternal(CommandProcessorContext cpc) { // safety check, this should never be hit Debug.Assert(ParentComplexType != null, "InvokeInternal is called when ParentComplexType is null."); if (ParentComplexType == null) { throw new InvalidOperationException("InvokeInternal is called when ParentComplexType is null"); } Debug.Assert(!(Type == null && ComplexType == null), "InvokeInternal is called when Type or ComplexType is null."); if (Type == null && ComplexType == null) { throw new InvalidOperationException("InvokeInternal is called when Type and ComplexType is null"); } // check for uniqueness string msg; if (!ModelHelper.ValidateComplexTypePropertyName(ParentComplexType, Name, true, out msg)) { throw new CommandValidationFailedException(msg); } // check for ComplexType circular definition if (ComplexType != null) { if (ModelHelper.ContainsCircularComplexTypeDefinition(ParentComplexType, ComplexType)) { throw new CommandValidationFailedException( String.Format( CultureInfo.CurrentCulture, Resources.Error_CircularComplexTypeDefinitionOnAdd, ComplexType.LocalName.Value)); } } // create the property Property property = null; if (Type != null) { var conceptualProperty = new ConceptualProperty(ParentComplexType, null); conceptualProperty.ChangePropertyType(Type); property = conceptualProperty; } else { var complexProperty = new ComplexConceptualProperty(ParentComplexType, null); complexProperty.ComplexType.SetRefName(ComplexType); property = complexProperty; } Debug.Assert(property != null, "property should not be null"); if (property == null) { throw new ItemCreationFailureException(); } // set the name and add to the parent entity property.LocalName.Value = Name; ParentComplexType.AddProperty(property); // set other attributes of the property if (Nullable != null) { property.Nullable.Value = (Nullable.Value ? BoolOrNone.TrueValue : BoolOrNone.FalseValue); } XmlModelHelper.NormalizeAndResolve(property); _createdProperty = property; }
private static Property CreateConceptualProperty(ConceptualEntityType parentEntity, string name, string type, InsertPropertyPosition insertPosition) { var property = new ConceptualProperty(parentEntity, null, insertPosition); property.LocalName.Value = name; property.ChangePropertyType(type); return property; }