Пример #1
0
        public static ResultMap LoadResultMap(XmlElement xmlNode, SmartSqlMapConfig sqlMapConfig, XmlNamespaceManager xmlNsM)
        {
            ResultMap resultMap = new ResultMap
            {
                Id      = xmlNode.Attributes["Id"].Value,
                Results = new List <Result> {
                }
            };

            LoadCtor(xmlNode, sqlMapConfig, xmlNsM, resultMap);
            LoadResult(xmlNode, sqlMapConfig, xmlNsM, resultMap);
            return(resultMap);
        }
Пример #2
0
        public static ResultMap LoadResultMap(XmlElement xmlNode, SmartSqlMap sqlMap, XmlNamespaceManager xmlNsM)
        {
            ResultMap resultMap = new ResultMap
            {
                Id         = xmlNode.Attributes["Id"].Value,
                Properties = new List <Property> {
                }
            };

            if (resultMap.Id.IndexOf('.') < 0)
            {
                resultMap.Id = $"{sqlMap.Scope}.{resultMap.Id}";
            }
            LoadCtor(xmlNode, sqlMap, xmlNsM, resultMap);
            LoadProperty(xmlNode, sqlMap, xmlNsM, resultMap);
            return(resultMap);
        }
Пример #3
0
        private static void LoadResult(XmlElement xmlNode, SmartSqlMapConfig sqlMapConfig, XmlNamespaceManager xmlNsM, ResultMap resultMap)
        {
            var resultNodes = xmlNode.SelectNodes("//ns:Result", xmlNsM);

            foreach (XmlNode resultNode in resultNodes)
            {
                var result = new Result
                {
                    Property    = resultNode.Attributes["Property"].Value,
                    Column      = (resultNode.Attributes["Column"] ?? resultNode.Attributes["Property"]).Value,
                    TypeHandler = resultNode.Attributes["TypeHandler"]?.Value
                };
                if (!String.IsNullOrEmpty(result.TypeHandler))
                {
                    result.Handler = sqlMapConfig.TypeHandlers.First(th => th.Name == result.TypeHandler).Handler;
                }
                resultMap.Results.Add(result);
            }
        }
Пример #4
0
        private static void LoadCtor(XmlElement xmlNode, SmartSqlMapConfig sqlMapConfig, XmlNamespaceManager xmlNsM, ResultMap resultMap)
        {
            var ctorNode = xmlNode.SelectSingleNode("//ns:Constructor", xmlNsM);

            if (ctorNode != null)
            {
                var argNodes = ctorNode.SelectNodes("//ns:Arg", xmlNsM);
                if (argNodes.Count > 0)
                {
                    var ctorMap = new Constructor
                    {
                        Args = new List <Arg>()
                    };
                    foreach (XmlNode argNode in argNodes)
                    {
                        var arg = new Arg
                        {
                            Column      = argNode.Attributes["Column"].Value,
                            Type        = argNode.Attributes["Type"].Value,
                            TypeHandler = argNode.Attributes["TypeHandler"]?.Value
                        };
                        arg.ArgType = ArgTypeConvert(arg.Type);
                        if (!String.IsNullOrEmpty(arg.TypeHandler))
                        {
                            arg.Handler = sqlMapConfig.TypeHandlers.First(th => th.Name == arg.TypeHandler).Handler;
                        }
                        ctorMap.Args.Add(arg);
                    }
                    resultMap.Constructor = ctorMap;
                }
            }
        }
Пример #5
0
        private static void LoadProperty(XmlElement xmlNode, SmartSqlMapConfig sqlMapConfig, XmlNamespaceManager xmlNsM, ResultMap resultMap)
        {
            var resultNodes = xmlNode.SelectNodes("./ns:Result", xmlNsM);

            foreach (XmlNode resultNode in resultNodes)
            {
                var property = new Property
                {
                    Name        = resultNode.Attributes["Property"].Value,
                    Column      = (resultNode.Attributes["Column"] ?? resultNode.Attributes["Property"]).Value,
                    TypeHandler = resultNode.Attributes["TypeHandler"]?.Value
                };
                if (!String.IsNullOrEmpty(property.TypeHandler))
                {
                    TypeHandler typeHandler = TypeHanderNotNull(sqlMapConfig, property.TypeHandler);
                    property.Handler = typeHandler.Handler;
                }
                resultMap.Properties.Add(property);
            }
        }