/// <summary>
        /// Constructs a new <see cref="CSharpProperty" /> object.
        /// </summary>
        /// <param name="name">The name of this property.</param>
        /// <param name="type">The type of this property.</param>
        /// <param name="accessModifier">The access level of this property.</param>
        /// <param name="isStatic">Whether or not this is a static property.</param>
        /// <param name="isOverride">Whether or not this is overriding a property in a base type.</param>
        /// <param name="hasGetter">Whether or not this property has a getter.</param>
        /// <param name="hasSetter">Whether or not this property has a setter.</param>
        /// <param name="defaultValue">The default value for this property.</param>
        /// <param name="attributes">The attributes on this property.</param>
        /// <param name="documentationComment">The documentation comment for this property.</param>
        public CSharpProperty(
            string name,
            string type,
            CSharpAccessModifier accessModifier = CSharpAccessModifier.Public,
            bool isStatic       = false,
            bool isOverride     = false,
            bool hasGetter      = true,
            bool hasSetter      = true,
            string defaultValue = null,
            IEnumerable <CSharpAttribute> attributes        = null,
            CSharpDocumentationComment documentationComment = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("C# Property name cannot be null or whitespace", nameof(name));
            }
            if (type != null && string.IsNullOrWhiteSpace(type))
            {
                throw new ArgumentException("Property type cannot be empty or whitespace", nameof(name));
            }

            this.Name                 = name;
            this.TypeName             = type ?? throw new ArgumentNullException(nameof(type));
            this.IsStatic             = isStatic;
            this.IsOverride           = isOverride;
            this.AccessModifier       = accessModifier;
            this.HasGetter            = hasGetter;
            this.HasSetter            = hasSetter;
            this.DefaultValue         = defaultValue;
            this.Attributes           = attributes ?? Array.Empty <CSharpAttribute>();
            this.DocumentationComment = documentationComment;
        }
        /// <summary>
        /// Constructs a new <see cref="CSharpMethod" /> object.
        /// </summary>
        /// <param name="name">The name of the method.</param>
        /// <param name="returnType">
        /// The full name of the method's return type.
        /// <para>
        /// If null, the return type will not be shown in the generated output.
        /// </para>
        /// </param>
        /// <param name="body">The method body.</param>
        /// <param name="parameters">The parameters which need to be provided as inputs to this method.</param>
        /// <param name="accessModifier">The access level of the method.</param>
        /// <param name="isStatic">True if this method should be marked as static, otherwise false.</param>
        /// <param name="isOverride">True if this method is overriding a base type's method, otherwise false.</param>
        /// <param name="isAsync">True if this method should be marked as async, otherwise false.</param>
        /// <param name="documentationComment">The method's documentation comment.  The parameters' documentation will automatically be included in this comment.</param>
        public CSharpMethod(
            string name,
            string returnType,
            string body,
            IEnumerable <CSharpParameter> parameters = null,
            CSharpAccessModifier accessModifier      = CSharpAccessModifier.Public,
            bool isStatic   = false,
            bool isOverride = false,
            bool isAsync    = false,
            CSharpDocumentationComment documentationComment = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Method name cannot be null or whitespace", nameof(name));
            }
            if (returnType != null && string.IsNullOrWhiteSpace(returnType))
            {
                throw new ArgumentException("Return type cannot be empty or whitespace", nameof(name));
            }

            this.Name                 = name;
            this.AccessModifier       = accessModifier;
            this.IsStatic             = isStatic;
            this.IsOverride           = isOverride;
            this.IsAsync              = isAsync;
            this.ReturnType           = returnType;
            this.Parameters           = parameters ?? Array.Empty <CSharpParameter>();
            this.Body                 = body ?? string.Empty;
            this.DocumentationComment = documentationComment;

            // Add parameter descriptions into the documentation comment
            string parametersDocumentationComment = this.GetParametersDocumentationComment(this.Parameters);

            if (!string.IsNullOrWhiteSpace(parametersDocumentationComment))
            {
                if (!string.IsNullOrWhiteSpace(this.DocumentationComment?.RawNotes))
                {
                    parametersDocumentationComment += $"{Environment.NewLine}{this.DocumentationComment.RawNotes}";
                }

                this.DocumentationComment = new CSharpDocumentationComment(this.DocumentationComment?.Summary, parametersDocumentationComment);
            }
        }
 /// <summary>
 /// Constructs a new <see cref="CSharpClassConstructor" /> object.
 /// </summary>
 /// <param name="className">The name of the class that contains this constructor.</param>
 /// <param name="accessModifier">The access level of the method.</param>
 /// <param name="parameters">The parameters which need to be provided as inputs to this method.</param>
 /// <param name="baseClassConstructorParameterValues">
 /// The parameter values to pass to the base class' constructor, as they will appear in the code.
 /// <para>
 /// If this is null, the base constructor call will not be visible in the generated output.
 /// Do this either when this constructor's class does not inherit from another class, or
 /// when the constructor should call the base class' default constructor automatically.
 /// </para>
 /// <para>
 /// NOTE: These values will not automatically be sanitized if they are identifiers. For
 /// example, if one of the variables being passed to the base constructor is called "class",
 /// then you should provide the string "@class" instead).
 /// </para>
 /// </param>
 /// <param name="body">The method body.</param>
 /// <param name="documentationComment">
 /// The method's documentation comment. The parameters' documentation will automatically be
 /// included in this comment.
 /// </param>
 public CSharpClassConstructor(
     string className,
     string body,
     CSharpAccessModifier accessModifier      = CSharpAccessModifier.Public,
     IEnumerable <CSharpParameter> parameters = null,
     IEnumerable <string> baseClassConstructorParameterValues = null,
     CSharpDocumentationComment documentationComment          = null)
     : base(
         name: className,
         returnType: null,
         body: body,
         parameters: parameters,
         accessModifier: accessModifier,
         isStatic: false,
         isOverride: false,
         isAsync: false,
         documentationComment: documentationComment)
 {
     this.BaseClassConstructorParameterValues = baseClassConstructorParameterValues ?? Array.Empty <string>();
 }
示例#4
0
        /// <summary>
        /// Creates a new <see cref="CSharpClass" /> object.
        /// </summary>
        /// <param name="name">The name of the class.</param>
        /// <param name="accessModifier">The class' access modifier.</param>
        /// <param name="baseType">The class' base (super/parent) type.</param>
        /// <param name="interfaces">The interfaces that this class implements.</param>
        /// <param name="attributes">The attributes on this class.</param>
        /// <param name="properties">The properties in this class.</param>
        /// <param name="constructors">The constructor methods for this class.</param>
        /// <param name="methods">The methods in this class.</param>
        /// <param name="isStatic">True if the class should be marked as static, otherwise false.</param>
        /// <param name="documentationComment">The documentation comment on this class.</param>
        public CSharpClass(
            string name,
            CSharpAccessModifier accessModifier               = CSharpAccessModifier.Public,
            IEnumerable <CSharpProperty> properties           = null,
            IEnumerable <CSharpClassConstructor> constructors = null,
            IEnumerable <CSharpMethod> methods = null,
            bool isStatic   = false,
            string baseType = null,
            IEnumerable <string> interfaces                 = null,
            IEnumerable <CSharpAttribute> attributes        = null,
            CSharpDocumentationComment documentationComment = null)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Class name cannot be null or whitespace", nameof(name));
            }

            if (baseType != null && string.IsNullOrWhiteSpace(baseType))
            {
                throw new ArgumentException("Base type name cannot be empty.  Set it to null to remove the base type.", nameof(baseType));
            }

            this.Name           = name;
            this.AccessModifier = accessModifier;
            this.BaseType       = baseType;
            this.IsStatic       = isStatic;
            this.Interfaces     = interfaces == null
                ? Array.Empty <string>().AsEnumerable()
                : new HashSet <string>(interfaces);

            this.Attributes           = attributes ?? Array.Empty <CSharpAttribute>();
            this.Properties           = properties ?? Array.Empty <CSharpProperty>();
            this.Constructors         = constructors ?? Array.Empty <CSharpClassConstructor>();
            this.Methods              = methods ?? Array.Empty <CSharpMethod>();
            this.DocumentationComment = documentationComment;
        }