简体   繁体   English

有人可以在C#中帮我解决这个问题吗

[英]Can someone help me solve this in c#

I use xsd.exe /classes cwmp-1-1.xsd to generate c# code. 我使用xsd.exe / classes cwmp-1-1.xsd生成C#代码。

The following code is generated by the tool. 该工具生成以下代码。

public partial class Array 
{
    [System.Xml.Serialization.XmlAnyElementAttribute()]
    public System.Xml.XmlElement[] Any;
    [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
    public string arrayType;
    [System.Xml.Serialization.XmlAttributeAttribute(Form = System.Xml.Schema.XmlSchemaForm.Qualified)]
    public string offset;
    [System.Xml.Serialization.XmlIgnoreAttribute()]
    public bool offsetSpecified;
    [System.Xml.Serialization.XmlAttributeAttribute(DataType = "ID")]
    public string id;
    [System.Xml.Serialization.XmlAttributeAttribute(DataType = "anyURI")]
    public string href;
    [System.Xml.Serialization.XmlAnyAttributeAttribute()]
    public System.Xml.XmlAttribute[] AnyAttr;
}

public partial class EventList : Array
{
}

public partial class EventStruct
{
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string EventCode;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public string CommandKey;
}

public partial class Inform
{
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public DeviceIdStruct DeviceId;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public EventList Event;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public uint MaxEnvelopes;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public System.DateTime CurrentTime;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public uint RetryCount;
    [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
    public ParameterValueList ParameterList;
}

and my code 和我的代码

Inform inform = new Inform();
inform.Event = new EventList();

EventStruct es = new EventStruct();
es.EventCode = "0 BOOTSTRAP";
es.CommandKey = "";

My problem is how to add es to inform.Event 我的问题是如何添加esinform.Event

and how to Serializer/Deserialize class Inform. 以及如何序列化/反序列化类Inform。

1st part of your question. 问题的第一部分。

inform.Event = es;

2nd part of your question, here is some of my code, adapted for your situation. 问题的第二部分,这是我的一些代码,适合您的情况。

To Deserialize: 反序列化:

XmlSerializer serializer = new XmlSerializer(typeof(Inform));
Inform ifnorm = null;
using (StreamReader sr = new StreamReader((FileName))
{
    inform = (Inform)serializer.Deserialize(sr)
}

I think you can figure out the Serialization from this link to the documentation . 我认为您可以从此链接到文档找出序列化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有人可以在C#中帮助我处理数组吗? - Can someone help me with arrays in c#? 我如何在 C# 中执行它有人可以帮助我 - how can i execute this in C# can someone help me 有人可以帮助我使用C#解决此逻辑吗 - Can some one help me solve this logic using C# 有人可以帮我修改此代码,使其在 C# ASP.NET 中工作吗? - Can someone help me to modify this code so it works in C# ASP.NET? 有人可以帮我保存脚本或打开 Monaco api 吗? C# - Can someone help me to save script or open into/from Monaco api? C# 有人可以帮我重构C#linq业务逻辑以提高效率吗? - Can someone help me refactor this C# linq business logic for efficiency? 有人可以为我提供有关C#Datagridview双击行的帮助 - Someone can help me about c# datagridview double click row 有人可以帮我将这个用C#编写的正则表达式转换为javascript吗? - Can someone help me to convert this regex expression written in C# to javascript? 在此特定示例(IP地址表达式)中,有人可以帮助我比较使用F#和C#吗? - Can someone help me compare using F# over C# in this specific example (IP Address expressions)? 有人可以使用C#统一代码为我的测验游戏提供帮助吗 - Can someone help me in my Quiz Game using C# unity code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM