コード例 #1
0
        internal static DataContract GetDataContract(DataContract declaredTypeContract, Type declaredType, Type objectType)
        {
            DataContract contract = DataContractSerializer.GetDataContract(declaredTypeContract, declaredType, objectType);

            CheckIfTypeIsReference(contract);
            return(contract);
        }
コード例 #2
0
        public void WriteObject(Stream stream, object graph)
        {
            _jsonSerializer = new JavaScriptSerializer(stream);
            DataContract contract     = RootContract;
            Type         declaredType = contract.UnderlyingType;
            Type         graphType    = (graph == null) ? declaredType : graph.GetType();

            System.Runtime.Serialization.XmlWriterDelegator writer = null;
            if (graph == null)
            {
                _jsonSerializer.SerializeObject(null);
            }
            else
            {
                if (declaredType == graphType)
                {
                    if (contract.CanContainReferences)
                    {
                        XmlObjectSerializerWriteContextComplexJson context = XmlObjectSerializerWriteContextComplexJson.CreateContext(this, contract);
                        context.SerializeWithoutXsiType(contract, writer, graph, declaredType.TypeHandle);
                    }
                    else
                    {
                        WriteObjectInternal(graph, contract, null, false, declaredType.TypeHandle);
                    }
                }
                else
                {
                    XmlObjectSerializerWriteContextComplexJson context = XmlObjectSerializerWriteContextComplexJson.CreateContext(this, RootContract);
                    contract = DataContractSerializer.GetDataContract(contract, declaredType, graphType);

                    if (contract.CanContainReferences)
                    {
                        context.SerializeWithXsiTypeAtTopLevel(contract, writer, graph, declaredType.TypeHandle, graphType);
                    }
                    else
                    {
                        context.SerializeWithoutXsiType(contract, writer, graph, declaredType.TypeHandle);
                    }
                }
            }
        }