Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new reference of the specified kind to the collection of references, or updates an already existing reference of the given kind.
        /// </summary>
        public static IReference AddReference(this IProductElement container, string kind, string value, bool singleton = false)
        {
            Guard.NotNull(() => container, container);
            Guard.NotNullOrEmpty(() => kind, kind);

            if (singleton == true)
            {
                var existingRef = container.References.FirstOrDefault(r => r.Kind == kind);
                if (existingRef != null)
                {
                    // Update existing reference value.
                    existingRef.Value = value;

                    return(existingRef);
                }
            }

            // Create a new reference
            return(container.CreateReference(r =>
            {
                r.Kind = kind;
                r.Value = value;
            }));
        }