Skip to content

ClassDeclaration

CSharp class declaration.

import { ClassDeclaration } from "@alloy-js/csharp";
<ClassDeclaration
abstract
attributes={AttributesProp}
baseType={Children}
doc={Children}
file
interfaceTypes={Children[]}
internal
name={string | Namekey}
partial
primaryConstructor={ParameterProps[]}
private
protected
public
refkey={Refkey}
sealed
static
typeParameters={(string | TypeParameterProps)[]}
/>
abstractoptional boolean
attributesoptional AttributesPropDefine attributes to attach
baseTypeoptional ChildrenBase class that this class extends
docoptional ChildrenDoc comment
fileoptional boolean
interfaceTypesoptional Children[]Interfaces this class implements
internaloptional boolean
namestring | Namekey
partialoptional boolean
primaryConstructoroptional ParameterProps[]Set the primary constructor parameters
privateoptional boolean
protectedoptional boolean
publicoptional boolean
refkeyoptional Refkey
sealedoptional boolean
staticoptional boolean
typeParametersoptional (string | TypeParameterProps)[]Type parameters for the class
<ClassDeclaration public name="MyClass">
  <ClassMember public name="MyField" type="int" />
  <ClassConstructor>
    <Parameter name="value" type="int" />
    this.MyField = value;
  </ClassConstructor>
</ClassDeclaration>

This will produce:

public class MyClass
{
  public int MyField;
  public MyClass(int value)
  {
    this.MyField = value;
  }
}