Export (0) Print
Expand All

ObjectInfo Class

Renders the property names and values of the specified object and of any subobjects that it references.

System.Object
  System.Web.Helpers.ObjectInfo

Namespace:  System.Web.Helpers
Assembly:  System.Web.Helpers (in System.Web.Helpers.dll)

public static class ObjectInfo

The ObjectInfo type exposes the following members.

  NameDescription
Public methodStatic memberPrintRenders the property names and values of the specified object and of any subobjects.
Top

This class represents a helper, which is a component that simplifies web programming in ASP.NET Web Pages. You can use the ObjectInfo class to help analyze and debug ASP.NET Web Pages code by rendering the value of an object to the web page. For a simple object such as a string variable, the class displays the type of the object and its value. For an object that contains multiple items, such as an array with multiple elements or a data object that contains multiple rows, the class displays each element or property and its value.

To display an object's property names and property values, call the Print(Object, Int32, Int32) method and pass the object to it. The method renders each property name and property value on a separate line.

Security noteSecurity Note:

Remove all calls to the Print(Object, Int32, Int32) method from production code. Otherwise, information about the objects in the code will be displayed to site visitors, which might be a security risk.

The following example shows how to use the ObjectInfo class to display information about several variables in the code. Because the code contains an array that has multiple string elements, the method displays each element key and its value.


<!DOCTYPE html>
@{
    var dateInfo = DateTime.Now;
    var greeting = "Welcome!";
    string[] teamMembers = {"Matt", "Joanne", "Robert", "Nancy"};
}
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
<!-- Render the variable values to the page. -->
@ObjectInfo.Print(dateInfo)
@ObjectInfo.Print(greeting)
@ObjectInfo.Print(teamMembers)

    <h1>Team Home Page</h1>
    <p>@greeting  Today is: @dateInfo</p>
    <h2>Our Team</h2>
    <ol>
    @foreach (var name in teamMembers) {
        <li>@name</li>
	}
    </ol>
</body>
</html>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft