/// <summary>
        /// Generates code for the specified method information.
        /// </summary>
        /// <param name="methodInfo">The method information.</param>
        /// <param name="options">The generator options.</param>
        /// <returns>System.String.</returns>
        public string Generate(MethodInfo methodInfo, MethodGeneratorOptions options)
        {
            var sb = new StringBuilder();

            if (options.Access)
            {
                sb.Append(Generator.Access(methodInfo.Attributes));
            }
            if (options.Modifiers)
            {
                sb.Append(Generator.Modifier(methodInfo.Attributes));
            }
            if (options.ReturnType)
            {
                sb.Append(Generator.Generate(methodInfo.ReturnType) + " ");
            }
            if (options.Name)
            {
                sb.Append(methodInfo.Name);
            }
            if (methodInfo.IsGenericMethod)
            {
                sb.Append("<" + Generator.Generate(methodInfo.GetGenericArguments()) + ">");
            }

            //TODO use options
            sb.Append("(");
            sb.Append(Generator.Generate(methodInfo.GetParameters()));
            sb.Append(")");

            if (sb.ToString() == "protected override void Finalize()")
            {
                return($"~{methodInfo.DeclaringType.Name}()");                // Destructor
            }
            return(GeneratorMode == GeneratorMode.InheriteDoc
                                ? sb.ToString().Replace("<", "{").Replace(">", "}")
                                : sb.ToString());
        }
示例#2
0
        /// <summary>
        /// Generates code for the specified field information.
        /// </summary>
        /// <param name="fieldInfo">The field information.</param>
        /// <param name="options">The generator options.</param>
        /// <returns>System.String.</returns>
        public string Generate(FieldInfo fieldInfo, FieldGeneratorOptions options)
        {
            var sb = new StringBuilder();

            if (options.Access)
            {
                sb.Append(Generator.Access((MethodAttributes)fieldInfo.Attributes));
            }
            if (options.Modifiers)
            {
                sb.Append(Generator.Modifier(fieldInfo.Attributes));
            }
            if (options.Type)
            {
                sb.Append(Generator.Generate(fieldInfo.FieldType) + " ");
            }
            if (options.Name)
            {
                sb.Append(fieldInfo.Name);
            }
            //TODO Value;

            return(sb.ToString());
        }
示例#3
0
        /// <summary>
        /// Generates code for the specified property information.
        /// </summary>
        /// <param name="propertyInfo">The property information.</param>
        /// <param name="options">The generator options.</param>
        /// <returns>System.String.</returns>
        public string Generate(PropertyInfo propertyInfo, PropertyGeneratorOptions options)
        {
            var sb     = new StringBuilder();
            var getter = propertyInfo.GetMethod;
            var setter = propertyInfo.SetMethod;

            string access = "";

            if (getter != null && setter != null)
            {
                var getterAccess = Generator.Access(getter.Attributes);
                var setterAccess = Generator.Access(setter.Attributes);
                access = Generator.MaxAccess(getterAccess, setterAccess) + " ";
            }
            else if (getter != null)
            {
                access = Generator.Access(getter.Attributes);
            }
            else if (setter != null)
            {
                access = Generator.Access(setter.Attributes);
            }

            var mi = getter ?? setter;

            if (options.Access)
            {
                sb.Append(access);
            }
            if (options.Modifiers)
            {
                sb.Append(Generator.Modifier(mi.Attributes));
            }
            if (options.Type)
            {
                sb.Append(Generator.Generate(propertyInfo.PropertyType) + " ");
            }


            // Indexer
            if (propertyInfo.Name == "Item" && propertyInfo.GetMethod.GetParameters().Length > 0)
            {
                sb.Append("this[");
                sb.Append(Generator.Generate(propertyInfo.GetMethod.GetParameters()));
                sb.Append("]");
            }
            else
            {
                if (options.Name)
                {
                    sb.Append(propertyInfo.Name);
                }
            }

            if (GeneratorMode == GeneratorMode.InheriteDoc)
            {
                // not body
            }
            else
            {
                sb.Append(" { ");
                if (propertyInfo.CanRead)
                {
                    var getterAccess = Generator.Access(getter.Attributes);
                    if (getterAccess != access)
                    {
                        sb.Append(getterAccess);
                    }
                    sb.Append("get; ");
                }
                if (propertyInfo.CanWrite)
                {
                    var setterAccess = Generator.Access(setter.Attributes);
                    if (setterAccess != access)
                    {
                        sb.Append(setterAccess);
                    }
                    sb.Append("set; ");
                }
                sb.Append("}");
            }
            return(sb.ToString());
        }