Пример #1
0
        /// <summary>
        /// Gets the value of the specified <see cref="ResultProperty"/> that must be set on the target object.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="resultMap">The result map.</param>
        /// <param name="mapping">The mapping.</param>
        /// <param name="target">The target.</param>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public object Get(RequestScope request, IResultMap resultMap, ResultProperty mapping, ref object target, IDataReader reader)
        {
            object result = null;

            IResultMap propertyRresultMap = mapping.NestedResultMap.ResolveSubMap(reader);

            string circularKey = GetCircularKey(propertyRresultMap, reader);
            // Gets the [key, result object] already build
            IDictionary <string, object> buildObjects = request.GetCirularKeys(propertyRresultMap);

            if (buildObjects != null && buildObjects.ContainsKey(circularKey))
            {
                // circular key is already known, so get the existing result object
                result = buildObjects[circularKey];
            }
            else if (circularKey == null || buildObjects == null || !buildObjects.ContainsKey(circularKey))
            {
                // circular key is NOT known, so create a new result object.
                result = resultMapStrategy.Get(request, resultMap, mapping, ref target, reader);

                if (buildObjects == null)
                {
                    buildObjects = new Dictionary <string, object>();
                    request.SetCirularKeys(propertyRresultMap, buildObjects);
                }
                buildObjects[circularKey] = result;
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Processes the specified <see cref="IDataReader"/>.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="resultObject">The result object.</param>
        /// <returns></returns>
        public object Process(RequestScope request, ref IDataReader reader, object resultObject)
        {
            object outObject = resultObject;

            IResultMap resultMap = request.CurrentResultMap.ResolveSubMap(reader);

            string circularKey = GetCircularKey(resultMap, reader);
            // Gets the [key, result object] already build
            IDictionary <string, object> buildObjects = request.GetCirularKeys(resultMap);

            if (buildObjects != null && buildObjects.ContainsKey(circularKey))
            {
                // circular key is already known, so get the existing result object
                outObject = buildObjects[circularKey];
            }
            else if (circularKey == null || buildObjects == null || !buildObjects.ContainsKey(circularKey))
            {
                // circular key is NOT known, so create a new result object.
                if (outObject == null)
                {
                    object[] parameters = null;
                    if (resultMap.Parameters.Count > 0)
                    {
                        parameters = new object[resultMap.Parameters.Count];
                        // Fill parameters array
                        for (int index = 0; index < resultMap.Parameters.Count; index++)
                        {
                            ResultProperty resultProperty = resultMap.Parameters[index];
                            parameters[index] = resultProperty.GetValue(request, ref reader, null);
                        }
                    }

                    outObject = resultMap.CreateInstanceOfResult(parameters);
                }

                // For each Property in the ResultMap, set the property in the object
                for (int index = 0; index < resultMap.Properties.Count; index++)
                {
                    ResultProperty resultProperty = resultMap.Properties[index];
                    resultProperty.PropertyStrategy.Set(request, resultMap, resultProperty, ref outObject, reader, null);
                }

                if (buildObjects == null)
                {
                    buildObjects = new Dictionary <string, object>();
                    request.SetCirularKeys(resultMap, buildObjects);
                }
                buildObjects[circularKey] = outObject;
            }

            return(outObject);
        }