Beispiel #1
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        public void BeginConstructor(AccessModifier access, string typeName, string baseString, Type[] args, string[] argNames)
        {
            if (args == null || argNames == null || typeName == null)
            {
                throw new ArgumentNullException();
            }

            if (args.Length != argNames.Length)
            {
                throw new ArgumentException("Length of args and argNames must be the same.");
            }

            this.seenTypes.AddRange(args);

            var accessStr = access.Stringify();

            this.WriteLine(string.Join("", new string[]
            {
                accessStr + " ",
                typeName,
                CodeGenerationUtilities.PrintAsParameters(args, argNames, true, false)
            }));

            if (baseString != null)
            {
                this.NewLine();
                this.Indent++;
                this.Write(baseString);
                this.Indent--;
            }

            this.BeginSegment();
        }
Beispiel #2
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        public void BeginMethod(AccessModifier access, Type returnType, string name, Type[] args, string[] argNames, bool isStatic, bool isOverride, bool isExtension)
        {
            if (string.IsNullOrEmpty(name) || args == null || argNames == null)
            {
                throw new ArgumentNullException();
            }

            if (args.Length != argNames.Length)
            {
                throw new ArgumentException("Length of args and argNames must be the same.");
            }

            if (isStatic && isOverride)
            {
                throw new ArgumentException("Method cannot be both static and override.");
            }

            if (isExtension && args.Length == 0)
            {
                throw new ArgumentException("Extension methods must have at least one argument.");
            }

            if (returnType == typeof(void))
            {
                returnType = null;
            }

            if (returnType != null)
            {
                this.seenTypes.Add(returnType);
            }

            this.seenTypes.AddRange(args);

            var accessStr = access.Stringify();

            if (isStatic)
            {
                accessStr += " static";
            }

            if (isOverride)
            {
                accessStr += " override";
            }

            this.WriteLine(string.Join("", new string[]
            {
                accessStr + " ",
                returnType == null ? "void " : returnType.GetNiceName() + " ",
                name,
                CodeGenerationUtilities.PrintAsParameters(args, argNames, true, isExtension)
            }));

            this.BeginSegment();
        }
Beispiel #3
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        public void WriteField(AccessModifier access, Type fieldType, string name)
        {
            if (fieldType == null || string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException();
            }

            this.seenTypes.Add(fieldType);

            this.WriteLine(string.Join(" ", new string[]
            {
                access.Stringify(),
                fieldType.GetNiceName(),
                name
            }) + ";");
        }
Beispiel #4
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        public void BeginProperty(AccessModifier access, Type propertyType, string name, bool isStatic = false)
        {
            if (propertyType == null || string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException();
            }

            this.seenTypes.Add(propertyType);

            this.WriteLine(string.Join(" ", new string[]
            {
                access.Stringify() + (isStatic ? " static" : ""),
                propertyType.GetNiceName(),
                name
            }));

            this.BeginSegment();
        }
Beispiel #5
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        public void WriteAutoProperty(AccessModifier access, Type propertyType, string name, AccessModifier?writeAccess)
        {
            if (propertyType == null || string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException();
            }

            this.seenTypes.Add(propertyType);

            this.WriteLine(string.Concat(new string[]
            {
                access.Stringify() + " ",
                propertyType.GetNiceName() + " ",
                name + " ",
                "{ get; ",
                writeAccess != null ? writeAccess.Value.Stringify() + " " : "",
                "set; }",
                Environment.NewLine
            }));

            this.EmptyLine();
        }
Beispiel #6
0
        /// <summary>
        /// Not yet documented.
        /// </summary>
        public void BeginType(AccessModifier accessModifier, TypeDeclaration declaration, string typeName, Type inheritsFrom, params Type[] implementInterfaces)
        {
            if (typeName.IsNullOrWhitespace())
            {
                throw new ArgumentNullException("className");
            }

            if (implementInterfaces != null)
            {
                for (int i = 0; i < implementInterfaces.Length; i++)
                {
                    Type @interface = implementInterfaces[i];

                    if (@interface == null)
                    {
                        throw new ArgumentNullException("interfaces at index " + i);
                    }

                    if ([email protected])
                    {
                        throw new ArgumentException("The interface type " + @interface.FullName + " at index " + i + " is not an interface.");
                    }
                }
            }

            this.WriteLineIndentation();
            this.Write(accessModifier.Stringify());

            switch (declaration)
            {
            case TypeDeclaration.Class:
                this.Write(" class ");
                break;

            case TypeDeclaration.StaticClass:
                this.Write(" static class ");
                break;

            case TypeDeclaration.SealedClass:
                this.Write(" sealed class ");
                break;

            case TypeDeclaration.Struct:
                this.Write(" struct ");
                break;

            default:
                throw new NotImplementedException(declaration.ToString());
            }

            this.Write(typeName);

            if (inheritsFrom != null || (implementInterfaces != null && implementInterfaces.Length > 0))
            {
                this.Write(" : ");
            }

            if (inheritsFrom != null)
            {
                this.RegisterTypeSeen(inheritsFrom);
                this.Write(inheritsFrom.GetNiceName());
            }

            if (implementInterfaces != null && implementInterfaces.Length > 0)
            {
                this.RegisterTypesSeen(implementInterfaces);

                for (int i = 0; i < implementInterfaces.Length; i++)
                {
                    if (i > 0 || inheritsFrom != null)
                    {
                        this.Write(", ");
                    }

                    this.Write(implementInterfaces[i].GetNiceName());
                }
            }

            this.NewLine();
            this.BeginSegment();
        }