Chapter 9 Caché Function Collection $CLASSNAME Function

Article Directory

Chapter 9 Caché Function Collection $CLASSNAME Function

Returns the name of the class.

Outline

$CLASSNAME(n)

parameter

  • n Optional-object reference (OREF) to the class instance. If omitted, the class name of the current class is returned.

description

$CLASSNAMEReturns the name of the class. Usually, it accepts an object reference (OREF) and returns the corresponding class name. $CLASSNAMEReturn the name of the current class without parameters . $CLASSNAMEAlways return the full class name (for example, %SQL.Statement), not a short version of the class name with the package name omitted (for example, STATEMENT).

$CLASSNAMEFunctionally equivalent to %Library.Basesuperclass %ClassName(1)methods. $CLASSNAMEFunctions %ClassName(1)provide better performance than methods in returning full class names . To return a short version of the class name, you can use %ClassName()or %ClassName(0).

Example

The following example creates an instance of a class. $CLASSNAMEGet the instance OREF and return the corresponding class name:

/// d ##class(PHA.TEST.Function).CLASSNAME()
ClassMethod CLASSNAME()
{
    
    
	SET dynoref = ##class(%SQL.Statement).%New()
	WRITE "instance class name: ",$CLASSNAME(dynoref)
}
DHC-APP>d ##class(PHA.TEST.Function).CLASSNAME()
instance class name: %SQL.Statement

In the following example, $CLASSNAMEthe class name of the current class context is returned without parameters . In this case, it is a DocBook.Utilsclass. This is the $thissame as the class name contained in the special variable:

/// d ##class(PHA.TEST.Function).CLASSNAME1()
ClassMethod CLASSNAME1()
{
    
    
	WRITE "class context: ",$CLASSNAME(),!
	WRITE "class context: ",$THIS
}
DHC-APP>d ##class(PHA.TEST.Function).CLASSNAME1()
class context: PHA.TEST.Function
class context: PHA.TEST.Function

The following example shows that $CLASSNAMEfunctions and %ClassName(1)methods return the same value. It also shows the use %ClassName()method (with no parameters or with 0 parameters) to return a short version of the class name:

/// d ##class(PHA.TEST.Function).CLASSNAME2()
ClassMethod CLASSNAME2()
{
    
    
CurrentClass
	WRITE "current full class name: ",$CLASSNAME(),!
	WRITE "current full class name: ",..%ClassName(1),!
	WRITE "current short class name: ",..%ClassName(0),!
	WRITE "current short class name: ",..%ClassName(),!!
ClassInstance
	SET x = ##class(%SQL.Statement).%New()
	WRITE "oref full class name: ",$CLASSNAME(x),!
	WRITE "oref full class name: ",x.%ClassName(1),!
	WRITE "oref short class name: ",x.%ClassName(0),!
	WRITE "oref short class name: ",x.%ClassName()
}
DHC-APP>d ##class(PHA.TEST.Function).CLASSNAME2()
current full class name: PHA.TEST.Function
current full class name: PHA.TEST.Function
current short class name: Function
current short class name: Function
 
oref full class name: %SQL.Statement
oref full class name: %SQL.Statement
oref short class name: Statement
oref short class name: Statement

Guess you like

Origin blog.csdn.net/yaoxin521123/article/details/108302490