天天看点

将SerializableAttribute序列化为xml

从这个例子中,你可以知道:

1,如何将stream转化为string

2,如何将searializableattribute属性序列化为xml

有metadataobject定义为:

将SerializableAttribute序列化为xml
将SerializableAttribute序列化为xml

/// <remarks/>

[system.xml.serialization.xmlincludeattribute(typeof(actionparameter))]

[system.xml.serialization.xmlincludeattribute(typeof(action))]

[system.xml.serialization.xmlincludeattribute(typeof(associationgroup))]

[system.xml.serialization.xmlincludeattribute(typeof(typedescriptor))]

[system.xml.serialization.xmlincludeattribute(typeof(parameter))]

[system.xml.serialization.xmlincludeattribute(typeof(filterdescriptor))]

[system.xml.serialization.xmlincludeattribute(typeof(identifier))]

[system.xml.serialization.xmlincludeattribute(typeof(lobsysteminstance))]

[system.xml.serialization.xmlincludeattribute(typeof(individuallysecurablemetadataobject))]

[system.xml.serialization.xmlincludeattribute(typeof(methodinstance))]

[system.xml.serialization.xmlincludeattribute(typeof(association))]

[system.xml.serialization.xmlincludeattribute(typeof(method))]

[system.xml.serialization.xmlincludeattribute(typeof(entity))]

[system.xml.serialization.xmlincludeattribute(typeof(lobsystem))]

[system.xml.serialization.xmlincludeattribute(typeof(model))]

[system.codedom.compiler.generatedcodeattribute("xsd", "2.0.50727.3038")]

[system.serializableattribute()]

[system.diagnostics.debuggerstepthroughattribute()]

[system.componentmodel.designercategoryattribute("code")]

[system.xml.serialization.xmltypeattribute(namespace = "http://schemas.microsoft.com/windows/2007/businessdatacatalog")]

public abstract partial class metadataobject

{

private localizeddisplayname[] localizeddisplaynamesfield;

private property[] propertiesfield;

private string namefield;

private string defaultdisplaynamefield;

private bool iscachedfield;

public metadataobject()

this.iscachedfield = true;

}

[system.xml.serialization.xmlarrayitemattribute(isnullable = false)]

public localizeddisplayname[] localizeddisplaynames

get

return this.localizeddisplaynamesfield;

set

this.localizeddisplaynamesfield = value;

public property[] properties

return this.propertiesfield;

this.propertiesfield = value;

[system.xml.serialization.xmlattributeattribute()]

public string name

return this.namefield;

this.namefield = value;

public string defaultdisplayname

return this.defaultdisplaynamefield;

this.defaultdisplaynamefield = value;

[system.componentmodel.defaultvalueattribute(true)]

public bool iscached

return this.iscachedfield;

this.iscachedfield = value;

将SerializableAttribute序列化为xml

下面一个函数将其转化为xml的string:

将SerializableAttribute序列化为xml
将SerializableAttribute序列化为xml

public static string getxmlfrommodel(metadataobject metadataobject)

memorystream ms = new memorystream();

xmlserializer serializer = new xmlserializer(metadataobject.gettype());

serializer.serialize(ms, metadataobject);

return system.text.asciiencoding.ascii.getstring(ms.toarray(), 0, ms.toarray().length);

将SerializableAttribute序列化为xml
下一篇: GAC简介