示例#1
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);
        }
示例#2
0
        public static string WriteQueryString(this object receiver,
                                              string modelName, QueryStringOutput output)
        {
            if (receiver == null)
            {
                return(null);
            }

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

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

            return(builder.ToString());
        }
示例#3
0
        public static object CreateObject(this object receiver, string method, string modelName,
                                          WriteSettings settings, QName root)
        {
            TkDebug.AssertArgumentNullOrEmpty(method, "method", null);
            TkDebug.AssertArgumentNull(settings, "settings", null);

            if (receiver == null)
            {
                return(null);
            }

            IObjectSerializer serializer = CreateSerializer(method);
            object            writer     = serializer.CreateWriter(null, settings);

            using (writer as IDisposable)
            {
                SerializerUtil.WriteSerializer(serializer, writer, receiver, modelName, settings, root, null);
                return(writer);
            }
        }
示例#4
0
        //public static string WriteToString(this object receiver, string method,
        //    WriteSettings settings, QName root)
        //{
        //    return WriteToString(receiver, method, null, settings, root);
        //}

        public static string WriteToString(this object receiver, string method, string modelName,
                                           WriteSettings settings, QName root)
        {
            TkDebug.AssertArgumentNullOrEmpty(method, "method", null);
            TkDebug.AssertArgumentNull(settings, "settings", null);

            if (receiver == null)
            {
                return(null);
            }

            IObjectSerializer serializer = CreateSerializer(method);
            MemoryStream      stream     = new MemoryStream();
            object            writer     = serializer.CreateWriter(stream, settings);

            using (writer as IDisposable)
            {
                SerializerUtil.WriteSerializer(serializer, writer, receiver, modelName, settings, root, null);
                byte[] data = stream.ToArray();
                return(settings.Encoding.GetString(data, 0, data.Length));
            }
        }