/// <summary>
        /// Visits a QueryStructuralValue and returns the clr value of the structural value
        /// </summary>
        /// <param name="value">The QueryStructuralValue which contains the clr value of the structural type : complex/entity  type</param>
        /// <returns>The clr instance of the structural value</returns>
        public object Visit(QueryStructuralValue value)
        {
            object clrInstance = null;

            if (this.objectLookup.TryGetValue(value, out clrInstance))
            {
                return(clrInstance);
            }

            ExceptionUtilities.CheckObjectNotNull(value.Type as IQueryClrType, "Structural type does not implement IQueryClrType");

            IQueryClrType clrTypeQueryable = value.Type as IQueryClrType;
            Type          clrType          = clrTypeQueryable.ClrType;

            ExceptionUtilities.CheckObjectNotNull(clrType, "ClrType should not be null");

            clrInstance = clrType.GetConstructor(Type.EmptyTypes).Invoke(null);
            this.objectLookup.Add(value, clrInstance);

            foreach (var member in value.MemberNames)
            {
                QueryValue   queryValue     = value.GetValue(member);
                var          memberValue    = queryValue.Accept(this);
                PropertyInfo memberProperty = clrType.GetProperty(member);
                memberProperty.SetValue(clrInstance, memberValue, null);
            }

            return(clrInstance);
        }
Пример #2
0
        /// <summary>
        /// Prints an entity graph
        /// </summary>
        /// <param name="rootQueryValue">The root element of the Query</param>
        /// <param name="maximumPayloadDepth">Indicates how far within the payload graph to traverse.</param>
        /// <returns>Returns a string to help visualize the Entity graph</returns>
        public string PrettyPrint(QueryValue rootQueryValue, int maximumPayloadDepth)
        {
            this.maxDepth = maximumPayloadDepth;
            ExceptionUtilities.CheckArgumentNotNull(rootQueryValue, "rootQueryValue");
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            this.builder      = new StringBuilder();
            this.currentDepth = 0;
            rootQueryValue.Accept(this);

            return(this.builder.ToString());
        }