Exemplo n.º 1
0
        /// <summary>
        ///     If this property is a ComplexProperty, this method will visit all scalar properties within a complex property,
        ///     leaving the actions performed on that scalar property up to the caller.
        /// </summary>
        /// <param name="property">Complex Property</param>
        /// <param name="visitorDelegate">ScalarInComplexPropertyVisitorDelegate which defines how the user wants to react to the scalar property</param>
        /// <param name="delimiter">Defines the naming convention for the resulting scalar property (for example, if delimiter = '_', then the scalar property would be: 'complexProp_scalarProp'</param>
        /// <param name="recursive">Boolean to define whether to step into complex properties contained within the complex property (true) or only visit the declared scalar properties (false)</param>
        internal static void VisitComplexProperty(
            this EdmProperty property, ScalarInComplexPropertyVisitorDelegate visitorDelegate, string delimiter, bool recursive)
        {
            var visitedProperties = new HashSet <EdmProperty>();

            VisitComplexPropertyInternal(property, visitorDelegate, property.Name, delimiter, recursive, visitedProperties);
        }
Exemplo n.º 2
0
        private static void VisitComplexPropertyInternal(
            this EdmProperty property, ScalarInComplexPropertyVisitorDelegate visitorDelegate, string namePrefix, string delimiter,
            bool recursive, HashSet <EdmProperty> visitedProperties)
        {
            var complexType = property.TypeUsage.EdmType as ComplexType;

            if (complexType != null)
            {
                foreach (var subProperty in complexType.Properties)
                {
                    var newNamePrefix = String.Format(
                        CultureInfo.CurrentCulture,
                        "{0}{1}{2}", namePrefix, delimiter, subProperty.Name);
                    if (subProperty.IsComplexProperty() && recursive)
                    {
                        if (visitedProperties.Contains(subProperty))
                        {
                            if (subProperty != null &&
                                subProperty.TypeUsage != null &&
                                subProperty.TypeUsage.EdmType.Name != null)
                            {
                                throw new InvalidOperationException(
                                          String.Format(
                                              CultureInfo.CurrentCulture, Resources.ErrorComplexTypeCycle, subProperty.Name,
                                              subProperty.TypeUsage.EdmType.Name));
                            }
                            else
                            {
                                throw new InvalidOperationException(
                                          String.Format(CultureInfo.CurrentCulture, Resources.ErrorNonSpecificComplexTypeCycle, subProperty.Name));
                            }
                        }
                        visitedProperties.Add(subProperty);

                        subProperty.VisitComplexPropertyInternal(
                            visitorDelegate,
                            newNamePrefix,
                            delimiter,
                            recursive,
                            visitedProperties);

                        visitedProperties.Remove(subProperty);
                    }
                    else
                    {
                        visitorDelegate(newNamePrefix, subProperty);
                    }
                }
            }
        }
        private static void VisitComplexPropertyInternal(
            this EdmProperty property, ScalarInComplexPropertyVisitorDelegate visitorDelegate, string namePrefix, string delimiter,
            bool recursive, HashSet<EdmProperty> visitedProperties)
        {
            var complexType = property.TypeUsage.EdmType as ComplexType;
            if (complexType != null)
            {
                foreach (var subProperty in complexType.Properties)
                {
                    var newNamePrefix = String.Format(
                        CultureInfo.CurrentCulture,
                        "{0}{1}{2}", namePrefix, delimiter, subProperty.Name);
                    if (subProperty.IsComplexProperty() && recursive)
                    {
                        if (visitedProperties.Contains(subProperty))
                        {
                            if (subProperty != null
                                && subProperty.TypeUsage != null
                                && subProperty.TypeUsage.EdmType.Name != null)
                            {
                                throw new InvalidOperationException(
                                    String.Format(
                                        CultureInfo.CurrentCulture, Resources.ErrorComplexTypeCycle, subProperty.Name,
                                        subProperty.TypeUsage.EdmType.Name));
                            }
                            else
                            {
                                throw new InvalidOperationException(
                                    String.Format(CultureInfo.CurrentCulture, Resources.ErrorNonSpecificComplexTypeCycle, subProperty.Name));
                            }
                        }
                        visitedProperties.Add(subProperty);

                        subProperty.VisitComplexPropertyInternal(
                            visitorDelegate,
                            newNamePrefix,
                            delimiter,
                            recursive,
                            visitedProperties);

                        visitedProperties.Remove(subProperty);
                    }
                    else
                    {
                        visitorDelegate(newNamePrefix, subProperty);
                    }
                }
            }
        }
 // <summary>
 //     If this property is a ComplexProperty, this method will visit all scalar properties within a complex property,
 //     leaving the actions performed on that scalar property up to the caller.
 // </summary>
 // <param name="property">Complex Property</param>
 // <param name="visitorDelegate">ScalarInComplexPropertyVisitorDelegate which defines how the user wants to react to the scalar property</param>
 // <param name="delimiter">Defines the naming convention for the resulting scalar property (for example, if delimiter = '_', then the scalar property would be: 'complexProp_scalarProp'</param>
 // <param name="recursive">Boolean to define whether to step into complex properties contained within the complex property (true) or only visit the declared scalar properties (false)</param>
 internal static void VisitComplexProperty(
     this EdmProperty property, ScalarInComplexPropertyVisitorDelegate visitorDelegate, string delimiter, bool recursive)
 {
     var visitedProperties = new HashSet<EdmProperty>();
     VisitComplexPropertyInternal(property, visitorDelegate, property.Name, delimiter, recursive, visitedProperties);
 }