示例#1
0
        protected static void AddDefault <T>(string name, T value, XElement xml)
        {
            XElement nestedType = new XElement(RuntimeSerialisationHelper.CleanName(name));

            if (value is IEnumerable)
            {
                foreach (object enumerableProperty in (IEnumerable)value)
                {
                    nestedType.Add(new XElement(RuntimeSerialisationHelper.CleanName(enumerableProperty.GetType().Name), enumerableProperty.ToString()));
                }
            }
            else
            {
                if (RuntimeSerialisationHelper.IsSimpleType(typeof(T)))
                {
                    AddSimpleType(name, value, nestedType);
                }
                else
                {
                    nestedType.Add(XmlSummaryWriter <T> .GetSummary(value));
                }
            }

            xml.Add(nestedType);
        }
示例#2
0
        protected static void AddSingleParameterGenericType <T, T2>(string name, object value, XElement xml)
        {
            XElement nestedType = new XElement(RuntimeSerialisationHelper.CleanName(name));

            if (value == null)
            {
                AddSimpleType(name, null, nestedType);
                return;
            }

            if (value is IEnumerable && typeof(T).IsGenericType)
            {
                foreach (T2 enumerableProperty in (IEnumerable)value)
                {
                    nestedType.Add(RuntimeSerialisationHelper.IsSimpleType(typeof(T2))
                        ? new XElement(RuntimeSerialisationHelper.CleanName(enumerableProperty.GetType().Name), ((object)enumerableProperty ?? "null").ToString())
                        : XmlSummaryWriter <T2> .GetSummary(enumerableProperty));
                }
            }
            else if (value is IEnumerable)
            {
                foreach (T2 enumerableProperty in (IEnumerable)value)
                {
                    nestedType.Add(RuntimeSerialisationHelper.IsSimpleType(typeof(T2))
                        ? new XElement(RuntimeSerialisationHelper.CleanName(enumerableProperty.GetType().Name), enumerableProperty.ToString())
                        : XmlSummaryWriter <T2> .GetSummary(enumerableProperty));
                }
            }
            else if (value is T2)
            {
                nestedType.Add(XmlSummaryWriter <T2> .GetSummary((T2)value));
            }
            else if (value is T)
            {
                nestedType.Add(XmlSummaryWriter <T> .GetSummary((T)value));
            }

            if (nestedType.Elements().Count() > 0)
            {
                xml.Add(nestedType);
            }
        }
示例#3
0
        protected static void AddDictionary <TKey, TValue>(string name, IDictionary <TKey, TValue> value, XElement xml)
        {
            XElement nestedType = new XElement(RuntimeSerialisationHelper.CleanName(name));

            if (value == null)
            {
                AddSimpleType(name, null, nestedType);
                return;
            }

            foreach (KeyValuePair <TKey, TValue> pair in value)
            {
                nestedType.Add(RuntimeSerialisationHelper.IsSimpleType(typeof(TValue))
                    ? new XElement(RuntimeSerialisationHelper.CleanName(pair.Key.ToString()), pair.Value.ToString())
                    : new XElement(RuntimeSerialisationHelper.CleanName(pair.Key.ToString()), XmlSummaryWriter <TValue> .GetSummary(pair.Value)));
            }

            xml.Add(nestedType);
        }
示例#4
0
 public static XElement Serialise <T>(T entity)
 {
     return(XmlSummaryWriter <T> .GetSummary(entity));
 }