Beispiel #1
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());
        }
Beispiel #2
0
 /// <summary>
 /// Generates code for the specified property information.
 /// </summary>
 /// <param name="propertyInfo">The property information.</param>
 /// <returns>System.String.</returns>
 public string Generate(PropertyInfo propertyInfo) => Generate(propertyInfo, PropertyGeneratorOptions.Create(GeneratorMode));