直接访问对象的完整字符串表示形式
我正在尝试将对象的内容记录到文本文件中。如果我在立即窗口中对对象本身进行 debug.print
操作,它会打印对象属性的所有值:
?mDb.DatabaseOptions
{Microsoft.SqlServer.Management.Smo.DatabaseOptions}
AnsiNullDefault: False
...
UserData: Nothing
但是,我似乎无法在代码中将其作为字符串访问,因为类型不匹配。我假设我可以使用 .ToString
方法获取此信息,但返回的只是没有任何属性或值的对象描述:
?mDb.DatabaseOptions.ToString
"Microsoft.SqlServer.Management.Smo.DatabaseOptions"
我缺少什么?
I am trying to log the contents of an object to a text file. If I do a debug.print
of the object itself in the immediate window, it prints all of the values of the object's properties:
?mDb.DatabaseOptions
{Microsoft.SqlServer.Management.Smo.DatabaseOptions}
AnsiNullDefault: False
...
UserData: Nothing
However, I can't seem to access this as a string in code due to a type mismatch. I assumed I could get this information using the .ToString
method, but all that returns is the object description with none of the properties or values:
?mDb.DatabaseOptions.ToString
"Microsoft.SqlServer.Management.Smo.DatabaseOptions"
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
.ToString 是基础对象上的函数(请参阅 http:// msdn.microsoft.com/en-us/library/system.object.tostring.aspx)。 Debug.Write 是一个可以迭代写入值的属性的函数。
正如 Stu 所说,您可以使用反射自己完成此操作。
您还可以添加/更改跟踪侦听器以在其他位置写出信息。
.ToString is a function on the base object (see http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx). Debug.Write is a function that can iterate though the properties writing the values.
As Stu said you can do this yourself using Reflection.
You could also add/change the trace listeners to write out the information else where.
Debug.Print 为您枚举所有属性。这就是您要找的吗?如果是这样,您将必须通过反射检查所有属性。
Debug.Print enumerates all properties for you. Is that what you are looking for? If so, you will have to examine all properties through reflection.