< Back

CType

Mon Jan 13, 2020 8:18 am

NAME CType



SYNOPSIS

Create a new type





SYNTAX

CType [-TypeName] <String> [[-TypeElement] <Object>] [<CommonParameters>]





DESCRIPTION





PARAMETERS

-TypeName <String>

Name of the new type. Include namespace e.g. "MyCompany.MyNamespace.MyClassName"



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-TypeElement <Object>

One or more script blocks or type elements which define class properties and other elements of the class.

The type elements may only contain objects on the list

property, sqlproperty, parent, use, ref,SqlWrapper, SqlTemplateObject, and NoFormatData,

and the script blocks must evaluate to objects of those types.

The script block definition must begin on the same line as the CType invocation,

or must be linked with backtick.



Required? false

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





A type with a given name can only be defined once per PowerShell runspace.

If you need to change it you will need to exit the runspace where it is defined.



-------------------------- EXAMPLE 1 --------------------------



PS C:\\># Creates a type with 4 properties, three of which are displayed in the default formatter.



CType MyCompany.MyNamespace.MyClassName {

parent MyCompany.MyNamespace.MyParentClass

property string PropertyName1 -PropertyTableWidth 20 -PropertyKeywords trim

if ($true)

{

property int PropertyName2 -PropertyTableWidth 15

}

property string PropertyName3 -PropertyTableWidth *

property bool PropertyName4

}









-------------------------- EXAMPLE 2 --------------------------



PS C:\\># Creates a type with 4 properties, three SQL wrappers and one non-wrapped property.



# The non-wrapped property can be set like any other read/write property, the others

# always read from the equivalent property of the wrapped DataRow object.

CType MyCompany.MyNamespace.MyClassName {

parent MyCompany.MyNamespace.MyParentClass

sqlproperty string PropertyName1 -PropertyTableWidth 20 -PropertyKeywords trim

sqlproperty int PropertyName2 -PropertyTableWidth 15

property string PropertyName3 -PropertyTableWidth *

sqlproperty bool PropertyName4

}











RELATED LINKS

Add-CType