예제 #1
0
        virtual public string SerializeToString()
        {
            Type          type       = m_dataType.GetType();
            ISerializable serializer = null;

            Type serializerType = Type.GetType(GetType().Namespace + "." + type.Name + "Serializer", false, true);

            if (serializerType != null)
            {
                serializer = (ISerializable)Activator.CreateInstance(serializerType, new object[] { m_dataType });
            }

            if (serializer == null)
            {
                serializer = new FieldSerializer(m_dataType);
            }

            if (serializer != null)
            {
                return(serializer.SerializeToString());
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #2
0
        virtual public void Serialize(Stream stream, Encoding encoding)
        {
            Type          type       = m_dataType.GetType();
            ISerializable serializer = null;

            Type serializerType = Type.GetType(GetType().Namespace + "." + type.Name + "Serializer", false, true);

            if (serializerType != null)
            {
                serializer = (ISerializable)Activator.CreateInstance(serializerType, new object[] { m_dataType });
            }

            if (serializer == null)
            {
                if (m_dataType is EncodableDataType)
                {
                    serializer = new EncodableDataTypeSerializer(m_dataType as EncodableDataType);
                }
                else
                {
                    serializer = new FieldSerializer(m_dataType);
                }
            }

            if (serializer != null)
            {
                string value = m_dataType.Name;

                if (serializer is IParameterSerializable)
                {
                    IParameterSerializable paramSerializer = (IParameterSerializable)serializer;
                    List <Parameter>       Parameters      = paramSerializer.Parameters;
                    if (Parameters.Count > 0)
                    {
                        List <string> values = new List <string>();
                        foreach (Parameter p in Parameters)
                        {
                            ParameterSerializer pSerializer = new ParameterSerializer(p);
                            values.Add(pSerializer.SerializeToString());
                        }

                        value += ";" + string.Join(";", values.ToArray());
                    }
                }

                value += ":";
                value += serializer.SerializeToString();
                value += "\r\n";

                ISerializable clSerializer = new ContentLineSerializer(value);
                if (clSerializer != null)
                {
                    clSerializer.Serialize(stream, encoding);
                }
            }
        }