private static void SetValue(object writer, ObjectPropertyInfo info, string fieldName,
                                     object value, WriteSettings settings)
        {
            DictionaryBuilder builder = writer.Convert <DictionaryBuilder>();

            builder.Add(fieldName, ObjectUtil.ToString(info.Converter, value, settings));
        }
        public void WriteObjectElement(ObjectElementAttribute attribute, object writer,
                                       object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            DictionaryBuilder builder = writer.Convert <DictionaryBuilder>();
            QName             name    = info.QName;

            if (attribute.IsMultiple)
            {
                IList list = value.Convert <IList>();
                List <Dictionary <string, object> > itemList =
                    new List <Dictionary <string, object> >(list.Count);
                foreach (var itemValue in list)
                {
                    DictionaryBuilder subBuilder = builder.CreateBuilder();
                    WriteObject(subBuilder, itemValue, info.ModelName, settings, name, null);
                    itemList.Add(subBuilder.Data);
                }
                builder.Add(name.LocalName, itemList);
            }
            else
            {
                DictionaryBuilder subBuilder = builder.CreateBuilder();
                WriteObject(subBuilder, value, info.ModelName, settings, name, null);
                builder.Add(name.LocalName, subBuilder);
            }
        }
Exemple #3
0
        public void Add(string name, DictionaryBuilder builder)
        {
            TkDebug.AssertArgumentNullOrEmpty(name, "name", this);
            TkDebug.AssertArgumentNull(builder, "builder", this);

            if (!(fOutput.IgnoreEmpty && builder.Data.Count == 0))
            {
                fData[name] = builder.Data;
            }
        }
        public void WriteDictionary(DictionaryAttribute attribute, object writer,
                                    object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            IDictionary       dict    = value.Convert <IDictionary>();
            DictionaryBuilder builder = writer.Convert <DictionaryBuilder>();
            QName             name    = info.QName;

            DictionaryBuilder subDict = builder.CreateBuilder();

            foreach (DictionaryEntry item in dict)
            {
                subDict.Add(item.Key.ToString(), ObjectUtil.ToString(info.Converter, item.Value, settings));
            }
            builder.Add(name.LocalName, subDict);
        }
Exemple #5
0
        public static Dictionary <string, Object> WriteDictionary(this object receiver,
                                                                  string modelName, DictionaryOutput output)
        {
            if (receiver == null)
            {
                return(null);
            }

            IObjectSerializer serializer = ObjectExtension.CreateSerializer("Dictionary");
            DictionaryBuilder builder    = new DictionaryBuilder(output);
            object            writer     = serializer.CreateCustomWriter(builder);

            SerializerUtil.WriteSerializer(serializer, writer, receiver, modelName, ObjectUtil.WriteSettings, QName.Toolkit, null);

            return(builder.Data);
        }
        public void WriteDynamicDictionary(DynamicDictionaryAttribute attribute, object writer,
                                           object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            IDictionary       dict    = value.Convert <IDictionary>();
            DictionaryBuilder builder = writer.Convert <DictionaryBuilder>();
            QName             name    = info.QName;

            DictionaryBuilder subDict = builder.CreateBuilder();

            foreach (DictionaryEntry item in dict)
            {
                DictionaryBuilder subDictItem = builder.CreateBuilder();
                WriteObject(subDictItem, item.Value, info.ModelName, settings, name, null);
                subDict.Add(item.Key.ToString(), subDictItem);
            }
            builder.Add(name.LocalName, subDict);
        }
        public void WriteTagElement(TagElementAttribute attribute, object writer,
                                    object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            DictionaryBuilder builder = writer.Convert <DictionaryBuilder>();
            QName             name    = info.QName;

            var infoArray = attribute.ChildElements.CreateOrderPropertyInfoList().ToArray();

            TkDebug.Assert(infoArray.Length == 1, string.Format(ObjectUtil.SysCulture,
                                                                "TagElement的子节点必须有且仅有一个,当前{1}下有{0}个", infoArray.Length, name), this);
            DictionaryBuilder subBuilder = builder.CreateBuilder();

            var item = infoArray[0];

            if (item.IsSingle)
            {
                item.Content.Attribute.WriteObject(this, subBuilder, value,
                                                   settings, item.Content, serializerData);
                builder.Add(name.LocalName, subBuilder);
            }
            else
            {
                IList list = value as IList;
                if (list != null)
                {
                    if (list.Count > 0)
                    {
                        var property = item.Get(list[0].GetType());
                        property.Attribute.WriteObject(this, subBuilder, value, settings,
                                                       property, serializerData);
                        builder.Add(name.LocalName, subBuilder);
                    }
                }
                else
                {
                    var property = item.Get(value.GetType());
                    property.Attribute.WriteObject(this, subBuilder, value, settings,
                                                   property, serializerData);
                    builder.Add(name.LocalName, subBuilder);
                }
            }
        }
        private static void SetValue(object writer, string fieldName, IList value)
        {
            DictionaryBuilder builder = writer.Convert <DictionaryBuilder>();

            builder.Add(fieldName, value);
        }