public CSMethod(CSVisibility vis, CSMethodKind kind, CSType type, CSIdentifier name, CSParameterList parms, CSBaseExpression[] baseOrThisCallParms, bool callsBase, CSCodeBlock body, bool isSealed = false) { GenericParameters = new CSGenericTypeDeclarationCollection(); GenericConstraints = new CSGenericConstraintCollection(); Visibility = vis; Kind = kind; Type = type; // no throw on null - could be constructor Name = Exceptions.ThrowOnNull(name, nameof(name)); Parameters = Exceptions.ThrowOnNull(parms, nameof(parms)); CallsBase = callsBase; BaseOrThisCallParameters = baseOrThisCallParms; Body = body; // can be null IsSealed = isSealed; LineCodeElementCollection <ICodeElement> lc = new LineCodeElementCollection <ICodeElement> (new ICodeElement [0], false, true); if (vis != CSVisibility.None) { lc.And(new SimpleElememt(VisibilityToString(vis))).And(SimpleElememt.Spacer); } if (isSealed) { lc.And(new SimpleElememt("sealed")).And(SimpleElememt.Spacer); } lc.And(new SimpleElememt(MethodKindToString(kind))).And(SimpleElememt.Spacer); if (type != null) { lc.And(type).And(SimpleElememt.Spacer); } lc.And(name).And(GenericParameters).And(new SimpleElememt("(")).And(parms).And(new SimpleElememt(")")).And(GenericConstraints); if (body == null) { if (!(kind == CSMethodKind.StaticExtern || kind == CSMethodKind.Interface)) { throw new ArgumentException("Method body is only optional when method kind kind is either StaticExtern or Interface", nameof(body)); } lc.Add(new SimpleElememt(";")); } Add(lc); if (BaseOrThisCallParameters != null) { Add(new CSFunctionCall(CallsBase ? ": base" : ": this", false, BaseOrThisCallParameters)); } if (body != null) { Add(body); } }
public CSInterface(CSVisibility vis, CSIdentifier name, IEnumerable <CSMethod> methods = null) { Visibility = vis; Name = Exceptions.ThrowOnNull(name, "name"); Inheritance = new CSInheritance(); Methods = new List <CSMethod> (); Properties = new List <CSProperty> (); GenericParams = new CSGenericTypeDeclarationCollection(); GenericConstraints = new CSGenericConstraintCollection(); if (methods != null) { Methods.AddRange(methods); } }
public CSClass(CSVisibility vis, CSIdentifier name, IEnumerable <CSMethod> methods = null, bool isStatic = false, bool isSealed = false) { Visibility = vis; IsStatic = isStatic; IsSealed = isSealed; Name = Exceptions.ThrowOnNull(name, "name"); Inheritance = new CSInheritance(); Delegates = new List <CSDelegateTypeDecl> (); Fields = new List <ICodeElement> (); Constructors = new List <CSMethod> (); Methods = new List <CSMethod> (); Properties = new List <CSProperty> (); InnerClasses = new CSClasses(); InnerEnums = new List <CSEnum> (); StaticConstructor = new CSCodeBlock(); GenericParams = new CSGenericTypeDeclarationCollection(); GenericConstraints = new CSGenericConstraintCollection(); if (methods != null) { Methods.AddRange(methods); } }