我可以用XML创建一个类吗?连载? [英] Can I make a class from XML? Serialize?

查看:63
本文介绍了我可以用XML创建一个类吗?连载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我需要一种使用

外部xml文件动态更改(或创建)自定义类的方法。这可以完成吗?这是班级看起来像

喜欢:


公共类会员数据

私人_EmailGUID作为字符串

私有_Email为字符串

私有_FirstName为字符串

私有_LastName为字符串

私有_标题为字符串

私人_Company As String

Private _Address As String

Private _PostalCode As Integer

Private _City As String

Private _Phone As字符串

私有_Active为整数

私有_RegDate为DateTime

私有_ChangeDate为DateTime


公开Sub New()

MyBase.New()


_EmailGUID =""

_Email =""

_FirstName =""

_LastName =""

_Title =""

_Company =""

_Address =""

_PostalCode = 0

_City =""

_Phone =""

_Active = 0

_RegDate = Nothing

_ChangeDate = Nothing

_SoftBounces = 0

_HardBounces = 0

_GroupIDs =""


End Sub


公共属性EmailGUID()As String

获取

返回_EmailGUID

结束获取

设置(ByVal值为字符串)

如果((价值无效)OrElse(Value.Length = 0))然后

抛出新例外(电子邮件地址标识符不能为
为空)

结束如果

_EmailGUID =价值

结束套件

结束物业


公共财产电子邮件()作为字符串

获取

返回_Email

结束获取

设置(ByVal值为字符串)

If((Value Is Nothing)OrElse(Value.Length = 0))然后

抛出新例外(电子邮件地址不能为空)

结束如果

_Email =价值

结束集

结束财产


[...]


结束班

谢谢。

问候约拿

Hi guys,

I need a way to dynamically change (or create) a custom class using an
external xml file. Can this be done at all? This is what the class looks
like:

Public Class MemberData
Private _EmailGUID As String
Private _Email As String
Private _FirstName As String
Private _LastName As String
Private _Title As String
Private _Company As String
Private _Address As String
Private _PostalCode As Integer
Private _City As String
Private _Phone As String
Private _Active As Integer
Private _RegDate As DateTime
Private _ChangeDate As DateTime

Public Sub New()
MyBase.New()

_EmailGUID = ""
_Email = ""
_FirstName = ""
_LastName = ""
_Title = ""
_Company = ""
_Address = ""
_PostalCode = 0
_City = ""
_Phone = ""
_Active = 0
_RegDate = Nothing
_ChangeDate = Nothing
_SoftBounces = 0
_HardBounces = 0
_GroupIDs = ""

End Sub

Public Property EmailGUID() As String
Get
Return _EmailGUID
End Get
Set(ByVal Value As String)
If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
Throw New Exception("The email address identifier cannot be
empty")
End If
_EmailGUID = Value
End Set
End Property

Public Property Email() As String
Get
Return _Email
End Get
Set(ByVal Value As String)
If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
Throw New Exception("The email address cannot be empty")
End If
_Email = Value
End Set
End Property

[...]

End Class
Thanks.
Regards Jonah

推荐答案

你好,


你的意思是在运行期间?如果是这样,那么我不相信。或者你在设计时是否意味着
的意思?如果是,那么它是可能的。但你需要找到一个可以从XML文件中创建一个类的应用程序,或者自己创建一个
,感兴趣的是它的用途是什么?


尼克。


" Jonah Olsson" <乔*** @ IHateSpam.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
Hi there,

Do you mean during Run-time? If so then I don''t believe so. Or do you
mean at Design-time? If so then it is "possible" but you would need to
either find an application that can create a class from an XML file or make
one yourself, out of interest what purpose would it serve?

Nick.

"Jonah Olsson" <jo***@IHateSpam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
嗨伙计们,

我需要一种使用
外部xml文件动态更改(或创建)自定义类的方法。这可以完成吗?这是类看起来像

公共类MemberData
私有_EmailGUID为字符串
私有_Email为字符串
私有_FirstName为字符串
Private _LastName As String
Private _Title As String
Private _Company As String
Private _Address As String
Private _PostalCode As Integer
Private _City As String
Private _Phone As String
Private _Active As Integer
Private _RegDate As DateTime
Private _ChangeDate As DateTime

Public Sub New()
MyBase.New()

_EmailGUID =""
_Email =""
_FirstName =""
_LastName =""
_Title =" ;"
_Company =""
_Address =""
_PostalCode = 0
_City =""
_Phone ="" _Active = 0
_RegDate = Nothing
_ChangeDate = Nothing
_SoftBounces = 0
_HardBounces = 0
_GroupIDs =""

公共属性EmailGUID()As String
获取
返回_EmailGUID
结束获取
设置(ByVal Value As String)
If((Value Is Nothing)OrElse(Value.Length = 0))然后
抛出新的异常(电子邮件地址标识符不能
为空)
结束如果
_EmailGUID =价值
结束集
结束财产

公共财产电子邮件()作为字符串
获取
返回_Email
结束获取
设置(ByVal值为字符串)
If((Value Is Nothing)OrElse(Value.Length = 0))然后
抛出新例外(电子邮件地址不能为空)<结束如果
_Email =价值
结束集
结束财产

[...]

结束类
谢谢。
关于Jonah
Hi guys,

I need a way to dynamically change (or create) a custom class using an
external xml file. Can this be done at all? This is what the class looks
like:

Public Class MemberData
Private _EmailGUID As String
Private _Email As String
Private _FirstName As String
Private _LastName As String
Private _Title As String
Private _Company As String
Private _Address As String
Private _PostalCode As Integer
Private _City As String
Private _Phone As String
Private _Active As Integer
Private _RegDate As DateTime
Private _ChangeDate As DateTime

Public Sub New()
MyBase.New()

_EmailGUID = ""
_Email = ""
_FirstName = ""
_LastName = ""
_Title = ""
_Company = ""
_Address = ""
_PostalCode = 0
_City = ""
_Phone = ""
_Active = 0
_RegDate = Nothing
_ChangeDate = Nothing
_SoftBounces = 0
_HardBounces = 0
_GroupIDs = ""

End Sub

Public Property EmailGUID() As String
Get
Return _EmailGUID
End Get
Set(ByVal Value As String)
If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
Throw New Exception("The email address identifier cannot be empty")
End If
_EmailGUID = Value
End Set
End Property

Public Property Email() As String
Get
Return _Email
End Get
Set(ByVal Value As String)
If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
Throw New Exception("The email address cannot be empty")
End If
_Email = Value
End Set
End Property

[...]

End Class
Thanks.
Regards Jonah



嗨尼克,

这是交易;我正在尝试创建一个Web服务作为引擎运行

用于多个客户端Web应用程序。引擎负责与每个数据库的所有

通信。

我说''each'的原因是客户可能使用自己的SQL服务器。所有

这只是测试,但我在查看示例时提出了这个想法

如何使用XML文件动态创建存储过程

http://www.fawcette.com/xmlmag/ 2002 _... lin_11_05_02 /)。由于

我在包含对

存储过程的调用的函数中使用了MemberData类,我可以使用XML更改SP中的参数

文件,为什么我也不能让MemberData类动态化。


比如,一个客户需要添加部门。到MemberData类。这个

可以很容易地在SP的XML文件中完成,但是如何将它添加到

的MemberData类中呢?我只是不想重新构建整个Web服务

申请。


我不确定我是否解释过这样的人可以理解我... =)


Jonah


Nak < a@a.com> skrev i meddelandet

新闻:uc ************** @ TK2MSFTNGP09.phx.gbl ...
Hi Nick,

Here''s the deal; I''m trying to create a Web Service to be run as an engine
for several client web applications. The engine takes care of all
communication with each database.
The reason I say ''each'' is that a customer may use their own SQL server. All
this is just testing, but I came up with the idea when looking at an example
how to dynamically create stored procedures using XML files
(http://www.fawcette.com/xmlmag/2002_...lin_11_05_02/). Since
I use the MemberData class in the function that contains the call to the
Stored Procedure, and I can change the parameters in the SP using an XML
file, why shouldn''t I be able to also make the MemberData class dynamic.

Say, one customer needs to add "Department" to the MemberData class. This
can easily be done in the XML file for the SP, but how to add it to the
MemberData class? I just don''t want to re-build the entire Web Service
application.

I''m not sure though if I explained this so people can understand me... =)

Jonah

"Nak" <a@a.com> skrev i meddelandet
news:uc**************@TK2MSFTNGP09.phx.gbl...
你好,

你的意思是在运行期间?如果是这样,那么我不相信。或者你在设计时意味着什么?如果是,那么它是可能的。但是你需要找到一个可以从XML文件中创建一个类的应用程序,或者你自己创建一个
,它的目的是什么呢?

尼克。
Hi there,

Do you mean during Run-time? If so then I don''t believe so. Or do you
mean at Design-time? If so then it is "possible" but you would need to
either find an application that can create a class from an XML file or make one yourself, out of interest what purpose would it serve?

Nick.



我不确定你是否想在运行时这样做,但如果你这样做,可以从中创建一个C#

类XML(嘿,你甚至可以使用XSLT ;-)并使用windows / Microsoft.NET文件夹中的免费

csc.exe(C#编译器)进行编译。


如果你真的想为自己努力,我知道(听到)

是辅助类,可以直接创建没有代码的程序集。这本书和我没有关系,但它们似乎存在。 naaaaaa,选项1将会更便宜

便宜。


Yoz


" Jonah Olsson" <乔*** @ IHateSpam.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
I am not sure if you want to do it at runtime, but if you do, create a C#
class from the XML (hey you can even do it with XSLT ;-) and use the free
csc.exe (C# compiler) in your windows/Microsoft.NET folder to compile.

If you really want to make things hard for yourself, I know (heard) there
are helper classes to create Assemblies straight without code. I don''t have
the book with me, but they seem to exists. naaaaaa, option 1 would be far
cheaper.

Yoz

"Jonah Olsson" <jo***@IHateSpam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
嗨伙计们,

我需要一种使用
外部xml文件动态更改(或创建)自定义类的方法。这可以完成吗?这是类看起来像

公共类MemberData
私有_EmailGUID为字符串
私有_Email为字符串
私有_FirstName为字符串
Private _LastName As String
Private _Title As String
Private _Company As String
Private _Address As String
Private _PostalCode As Integer
Private _City As String
Private _Phone As String
Private _Active As Integer
Private _RegDate As DateTime
Private _ChangeDate As DateTime

Public Sub New()
MyBase.New()

_EmailGUID =""
_Email =""
_FirstName =""
_LastName =""
_Title =" ;"
_Company =""
_Address =""
_PostalCode = 0
_City =""
_Phone ="" _Active = 0
_RegDate = Nothing
_ChangeDate = Nothing
_SoftBounces = 0
_HardBounces = 0
_GroupIDs =""

公共属性EmailGUID()As String
获取
返回_EmailGUID
结束获取
设置(ByVal Value As String)
If((Value Is Nothing)OrElse(Value.Length = 0))然后
抛出新的异常(电子邮件地址标识符不能
为空)
结束如果
_EmailGUID =价值
结束集
结束财产

公共财产电子邮件()作为字符串
获取
返回_Email
结束获取
设置(ByVal值为字符串)
If((Value Is Nothing)OrElse(Value.Length = 0))然后
抛出新例外(电子邮件地址不能为空)<结束如果
_Email =价值
结束集
结束财产

[...]

结束类
谢谢。
关于约拿
Hi guys,

I need a way to dynamically change (or create) a custom class using an
external xml file. Can this be done at all? This is what the class looks
like:

Public Class MemberData
Private _EmailGUID As String
Private _Email As String
Private _FirstName As String
Private _LastName As String
Private _Title As String
Private _Company As String
Private _Address As String
Private _PostalCode As Integer
Private _City As String
Private _Phone As String
Private _Active As Integer
Private _RegDate As DateTime
Private _ChangeDate As DateTime

Public Sub New()
MyBase.New()

_EmailGUID = ""
_Email = ""
_FirstName = ""
_LastName = ""
_Title = ""
_Company = ""
_Address = ""
_PostalCode = 0
_City = ""
_Phone = ""
_Active = 0
_RegDate = Nothing
_ChangeDate = Nothing
_SoftBounces = 0
_HardBounces = 0
_GroupIDs = ""

End Sub

Public Property EmailGUID() As String
Get
Return _EmailGUID
End Get
Set(ByVal Value As String)
If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
Throw New Exception("The email address identifier cannot be empty")
End If
_EmailGUID = Value
End Set
End Property

Public Property Email() As String
Get
Return _Email
End Get
Set(ByVal Value As String)
If ((Value Is Nothing) OrElse (Value.Length = 0)) Then
Throw New Exception("The email address cannot be empty")
End If
_Email = Value
End Set
End Property

[...]

End Class
Thanks.
Regards Jonah



这篇关于我可以用XML创建一个类吗?连载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆