示例#1
0
 /// <summary>
 /// Creates a new item with a given identifier.
 /// </summary>
 /// <remarks>
 /// While the identifier may have any value (except null or the empty string), it must be unique within any
 /// collection to which the item is added.
 /// </remarks>
 /// <param name="id">the unique identifier for the new item</param>
 /// <param name="collectionDefinition">the definition of the collection this item should use to validate
 /// itself</param>
 /// <exception cref="ArgumentException">if the given identifier is null or empty</exception>
 public PivotItem(String id, ICollectionDefinition collectionDefinition)
 {
     m_facets                  = new SortedDictionary <String, List <IComparable> >();
     m_relatedLinks            = new List <PivotLink>();
     this.Id                   = id;
     this.CollectionDefinition = collectionDefinition;
 }
示例#2
0
        internal IComparable ValidateFacetValue(ICollectionDefinition definition, String facetCategoryName, IComparable value)
        {
            IComparable actualValue = value;

            if (definition.FacetCategories.Contains(facetCategoryName))
            {
                PivotFacetCategory existingFacetCategory = definition.FacetCategories[facetCategoryName];

                if ((existingFacetCategory.Type.IsValidValue(value) == false))
                {
                    actualValue = null;
                    if (value is String)
                    {
                        try
                        {
                            actualValue = existingFacetCategory.Type.ParseValue((String)value);
                        }
                        catch (FormatException)
                        {
                            // Do nothing.
                        }
                    }

                    if (actualValue == null)
                    {
                        throw new ArgumentException("Item Id " + this.Id + " has an incompatible value (type: " +
                                                    value.GetType().Name + ") for facet category " + facetCategoryName);
                    }
                }
            }
            else if ((this.ContainingCollection != null) && (this.ContainingCollection.InferFacetCategories))
            {
                PivotFacetType facetType = PivotFacetType.IdentifyType(value);
                this.ContainingCollection.FacetCategories.Add(new PivotFacetCategory(facetCategoryName, facetType));
            }
            else
            {
                throw new ArgumentException("Item Id " + this.Id + " has an incompatible value (type: " +
                                            value.GetType().Name + ") for facet category " + facetCategoryName);
            }

            return(actualValue);
        }