Esempio n. 1
0
        /// <summary>
        /// Creates a new <see cref="GeneratedType" /> and adds it to this assembly.
        /// </summary>
        /// <param name="namespace">The namespace of the type.</param>
        /// <param name="typeName">The name of the type / class.</param>
        /// <param name="baseType">The base type of the new type, if any.</param>
        /// <returns>A new <see cref="GeneratedType" />.</returns>
        /// <exception cref="ArgumentException">If a type already exists.</exception>
        public GeneratedType AddType(string @namespace, string typeName, Type baseType)
        {
            if (this.GeneratedTypes.Any(t => t.Namespace == @namespace && t.TypeName == typeName))
            {
                throw new ArgumentException($"A type already exists at {@namespace}.{typeName}");
            }

            var generatedType = new GeneratedType(this, typeName, @namespace ?? this._generationRules.AssemblyName);

            if (baseType.IsInterface)
            {
                generatedType.Implements(baseType);
            }
            else
            {
                generatedType.InheritsFrom(baseType);
            }

            this._generatedTypes.Add(generatedType);

            return(generatedType);
        }
 /// <summary>
 /// Creates a new <see cref="GeneratedMethod"/> with no arguments, <typeparamref name="TReturn"/> return type
 /// and the given name and adds it to the given <see cref="GeneratedType" />.
 /// </summary>
 /// <typeparam name="TReturn">The return type of the method.</typeparam>
 /// <param name="type">The type to add to.</param>
 /// <param name="name">The name of the method.</param>
 /// <returns>A new <see cref="GeneratedMethod"/>.</returns>
 public static GeneratedMethod ForNoArg <TReturn>(GeneratedType type, string name)
 {
     return(new GeneratedMethod(type, name, typeof(TReturn), new Argument[0]));
 }