Asp.net Control: Properties

12/02/2009

Property packaged component state is rapid application development (RAD) nature. They allow users to custom design-time environment for components. The construction of the property in Visual Basic to support several versions, but not provided by an object, such as C, Java object-oriented programming language. (In the JavaBeans properties is to support an indirect access method adhere to a naming convention.) Is. NET Framework brings RAD Data Communications to simplify object-oriented programming support as a world-class programming construct object properties.

We'll look at the property construct first. Then we'll look at naming guidelines for properties and the advantages of exposing properties.

The Property Construct
Properties such as areas that are accessible through fieldlike pension but implemented using accessor methods. The following example shows a simple construction that specifies a property name public property in class Person:
public class Person {
// The private field below is not part of the property
// construct but contains data that holds the value of
// the Name property.
private string _name;
public string Name {
get {
return _name;
}
set {
_name = value;
}
}
}

The boldface elements—get, set, and value—are keywords in the C# property syntax. The compiler transforms the code in the get and set blocks into methods that are called property accessors. The get accessor—also called the getter—retrieves the value of the property, while the set accessor—also called the setter—assigns a value to the property. The value identifier denotes the implicit parameter that is passed into the setter.

C# does not have a keyword named property. However, Visual Basic .NET does use the Property keyword as shown in the following example, which shows the keywords in Visual Basic .NET property syntax in boldface:
Private String _name
Public Property Name() As String
Get
Return _name
End Get
Set (ByVal value As String)
_name = value
End Set
End Property

In contrast with C#, value in Visual Basic .NET is not a keyword in property syntax.

Although the get and set accessors are equivalent to methods, they cannot be invoked as methods in C# and Visual Basic .NET but are indirectly accessed by code that assigns or retrieves a property.

The syntax for setting a property is the same as that for setting a field. When you are setting a property, the assigned value must match the declared type of the property:

Person aPerson = new Person();
aPerson.Name = "John"; //Type of Name is string.

The property construct allows you to abstract the storage and implementation of a property from the clients of your component. In our example, a private field holds the data for the Name property. While the backing data for a property is often a private field, the data could reside elsewhere—for example, on disk or in a database—or it could be generated dynamically, as in a property that returns the system time.

Attribute can be defined get and set accessors, or just a single access device. Only get access to an attribute is a read-only attribute, and only set accessor attribute is a write-only property. Although the CLR allows write-only attribute. NET Framework Design Guidelines to stop them. If your component requires a write-only property, you should implement a method, rather than the property provide the same functionality.

A property can have any access level allowed by the runtime, including public, private, protected, or internal. In C# and Visual Basic .NET, the access level of a property applies to both accessors; it is not possible to have a different access level for each accessor.

Although the get and set accessors can not directly access methods, they are semantically equivalent method. In addition, they can perform any program logic, is covered, and throw an exception. In the next two sections, we will tell you how to override the property and property accessor of value for examination.

Posted in: asp.net| Tags: Programming string Property person name class value asp construction rad

Viewing Object Structure (Get-Member)

07/25/2009

Because objects play such a central role in Windows PowerShell, there are several native commands designed to work with arbitrary object types. The most important one is the Get-Member command.

The simplest technique for analyzing the objects that a command returns is to pipe the output of that command to the Get-Member cmdlet. The Get-Member cmdlet shows you the formal name of the object type and a complete listing of its members. The number of elements that are returned can sometimes be overwhelming. For example, a process object can have over 100 members.

To see all of the members of a Process object and page the output so you can view all of it, type:

PS> Get-Process | Get-Member | Out-Host -Paging

The output from this command will look something like this:

TypeName: System.Diagnostics.Process

Name MemberType Definition

---- ---------- ----------

Handles AliasProperty Handles = Handlecount

Name AliasProperty Name = ProcessName

NPM AliasProperty NPM = NonpagedSystemMemorySize

PM AliasProperty PM = PagedMemorySize

VM AliasProperty VM = VirtualMemorySize

WS AliasProperty WS = WorkingSet

add_Disposed Method System.Void add_Disposed(Event...

...

We can make this long list of information more usable by filtering for elements we want to see. The Get-Member command lets you list only members that are properties. There are several forms of properties. The cmdlet displays properties of any type if we set the Get-MemberMemberType parameter to the value Properties. The resulting list is still very long, but a bit more manageable:

PS> Get-Process | Get-Member -MemberType Properties

TypeName: System.Diagnostics.Process

Name MemberType Definition

---- ---------- ----------

Handles AliasProperty Handles = Handlecount

Name AliasProperty Name = ProcessName

...

ExitCode Property System.Int32 ExitCode {get;}

...

Handle Property System.IntPtr Handle {get;}

...

CPU ScriptProperty System.Object CPU {get=$this.Total...

...

Path ScriptProperty System.Object Path {get=$this.Main...

...

Note:

The allowed values of MemberType are AliasProperty, CodeProperty, Property, NoteProperty, ScriptProperty, Properties, PropertySet, Method, CodeMethod, ScriptMethod, Methods, ParameterizedProperty, MemberSet, and All.

There are over 60 properties for a process. The reason Windows PowerShell often shows only a handful of properties for any well-known object is that showing all of them would produce an unmanageable amount of information.

Note:

Windows PowerShell determines how to display an object type by using information stored in XML files that have names ending in .format.ps1xml. The formatting data for process objects, which are .NET System.Diagnostics.Process objects, is stored in PowerShellCore.format.ps1xml.

If you need to look at properties other than those that Windows PowerShell displays by default, you will need to format the output data yourself. This can be done by using the format cmdlets.

Posted in: Software| Tags: PowerShell Handle Alias Object Structure Get-Member out-Hosting Paging Process Property ProcessName Allowed MemberType Determine

Hot Posts

Latest posts

Tags

Others

Sponsors

asp.net interview questions