Пример #1
0
            public string   Generate(string content)
            {
                StringBuilder buffer = UONUtility.GetBuffer();

                buffer.Append("[[\"");

                for (int i = 0; i < this.registeredTypes.Count; i++)
                {
                    if (i > 0)
                    {
                        buffer.Append("\",\"");
                    }

                    string typeStringified = this.registeredTypes[i].GetShortAssemblyType();
                    if (Type.GetType(typeStringified) == null)
                    {
                        Debug.Log("Type \"" + typeStringified + "\" becomes null.");
                    }

                    buffer.Append(typeStringified);
                }

                buffer.Append("\"],");
                buffer.Append(content);
                buffer.Append(']');

                return(UONUtility.ReturnBuffer(buffer));
            }
Пример #2
0
        public override string  Serialize(UON.SerializationData data, object o)
        {
            int refIndex;

            if (data.GetReferenceIndex(o, out refIndex) == true)
            {
                return("#" + refIndex);
            }

            StringBuilder buffer = UONUtility.GetBuffer();
            IList         array  = o as IList;

            data.workingType = UONUtility.GetArraySubType(data.workingType);

            buffer.Append('[');

            foreach (object element in array)
            {
                string raw = data.ToUON(element);

                if (string.IsNullOrEmpty(raw) == false)
                {
                    if (buffer.Length > 1)
                    {
                        buffer.Append(',');
                    }

                    buffer.Append(raw);
                }
            }

            buffer.Append(']');

            return(UONUtility.ReturnBuffer(buffer));
        }
Пример #3
0
        public override string  Serialize(UON.SerializationData data, object o)
        {
            int refIndex;

            if (data.GetReferenceIndex(o, out refIndex) == true)
            {
                return("#" + refIndex);
            }

            StringBuilder buffer = UONUtility.GetBuffer();

            FieldInfo[]       fields;
            IUONSerialization serializationInterface = o as IUONSerialization;

            if (serializationInterface != null)
            {
                serializationInterface.OnSerializing();
            }

            if (this.typesFields.TryGetValue(data.workingType, out fields) == false)
            {
                fields = UONUtility.GetFieldsHierarchyOrdered(data.workingType, typeof(object), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).ToArray();
            }

            buffer.Append('{');

            foreach (FieldInfo field in fields)
            {
#if NETFX_CORE
                if (field.IsDefined(typeof(NonSerializedAttribute)) == false)
#else
                if (field.IsNotSerialized == false)
#endif
                {
                    string raw = data.ToUON(field.GetValue(o));

                    if (string.IsNullOrEmpty(raw) == false)
                    {
                        if (buffer.Length > 1)
                        {
                            buffer.Append(',');
                        }

                        buffer.Append('"');
                        buffer.Append(field.Name);
                        buffer.Append("\":");
                        buffer.Append(raw);
                    }
                }
            }

            buffer.Append('}');

            return(UONUtility.ReturnBuffer(buffer));
        }