/// <summary> /// Adds a property to the collection if it doesn't exist and returns true, otherwise returns false /// </summary> /// <param name="attributeCollection"></param> /// <param name="typedAttribute"></param> /// <returns></returns> public static bool TryAdd(this TypedAttributeCollection attributeCollection, TypedAttribute typedAttribute) { if (!attributeCollection.Any(x => x.AttributeDefinition.Alias == typedAttribute.AttributeDefinition.Alias)) { //NOTE: Here we need to generate an id for this item. // Though Id generation should generally be performed by Hive providers, a TypedAttribute can exist without an // id in the repository when a AttributeDefinition is created on the Schema and there are no TypeEntity revisions // for that schema with the updated AttributeDefinition. if (typedAttribute.Id.IsNullValueOrEmpty()) { typedAttribute.Id = new HiveId(Guid.NewGuid()); } attributeCollection.Add(typedAttribute); return(true); } return(false); }
/// <summary> /// Determines whether the specified attributes contains key. /// </summary> /// <param name="attributes">The attributes.</param> /// <param name="key">The key.</param> /// <returns> /// <c>true</c> if the specified attributes contains key; otherwise, <c>false</c>. /// </returns> public static bool ContainsKey(this TypedAttributeCollection attributes, string key) { //dont' worry about casing.. return(attributes.Any(x => x.AttributeDefinition.Alias.InvariantEquals(key))); }