예제 #1
0
        protected virtual object[] GetArgValues(XmlNode contentNode, Type[] argTypes, Func <Type, IParcer> valueParcerResolver)
        {
            if (contentNode.ChildNodes.Count < argTypes.Length)
            {
                return(null);
            }
            XmlNodeList xmlChildNodes = contentNode.ChildNodes;
            var         result        = new object[argTypes.Length];

            for (int i = 0; i < argTypes.Length; i++)
            {
                Type    currentType = argTypes[i];
                IParcer parcer      = valueParcerResolver(currentType);
                result[i] = parcer.ParceNodeValue(xmlChildNodes[i]);
            }
            return(result);
        }
예제 #2
0
        protected virtual void AssignContentToList(IList list, XmlNodeList contentNodes, Func <Type, IParcer> valueParcerResolver)
        {
            Assert.ArgumentNotNull(list, "list");
            var listGenericArgument = this.GetListGenericArgumentType(list.GetType());

            if (listGenericArgument == null)
            {
                throw new Exception("Unexpected value");
            }
            IParcer parcer = valueParcerResolver(listGenericArgument);

            if (parcer == null)
            {
                return;
            }
            foreach (XmlNode contentNode in contentNodes)
            {
                try
                {
                    object contentValue = null;
                    if (contentNode.FirstChild != null)
                    {
                        contentValue = parcer.ParceNodeValue(contentNode.FirstChild);
                    }
                    if (contentValue == null)
                    {
                        contentValue = parcer.ParceNodeValue(contentNode);
                    }
                    if (contentValue == null)
                    {
                        continue;
                    }
                    if (!listGenericArgument.IsInstanceOfType(contentValue))
                    {
                        continue;
                    }
                    list.Add(contentValue);
                }
                catch (Exception ex)
                {
                    Log.Error("Can't parce node value", ex, this);
                }
            }
        }
예제 #3
0
        public virtual void AssignContent(XmlNode contentNode, object instance, Type instanceType, Func <Type, IParcer> valueParcerResolver)
        {
            var     nodeName  = contentNode.Name;
            XmlNode nodeValue = contentNode.FirstChild;

            if (nodeValue == null)
            {
                return;
            }
            var property = instanceType.GetProperty(nodeName);

            if (property == null)
            {
                return;
            }
            if (!property.CanWrite)
            {
                return;
            }
            var     propertyType = property.PropertyType;
            IParcer parcer       = valueParcerResolver(propertyType);

            if (parcer == null)
            {
                return;
            }
            object contentValue = parcer.ParceNodeValue(nodeValue);

            if (contentValue == null)
            {
                return;
            }
            if (!propertyType.IsInstanceOfType(contentValue))
            {
                return;
            }
            property.SetValue(instance, contentValue, null);
        }