コード例 #1
0
        /// <summary>
        /// 获取方法注释。
        /// </summary>
        /// <param name="info">当前方法实例。</param>
        /// <returns>返回方法注释实例。</returns>
        public static MethodDescriptor GetSummary(this MemberInfo info)
        {
            var typeDescriptor = AssemblyDocument.GetTypeDescriptor(info.DeclaringType);

            return(typeDescriptor?.GetMethodDescriptor(info));
        }
コード例 #2
0
 /// <summary>
 /// 是否可以链接。
 /// </summary>
 /// <param name="type">类型实例。</param>
 /// <returns>返回判断结果。</returns>
 public static bool IsLinkable(this Type type)
 {
     return(AssemblyDocument.GetTypeDescriptor(type) != null);
 }
コード例 #3
0
ファイル: TypeExtensions.cs プロジェクト: onetcore/gentings
        /// <summary>
        /// 获取类型定义。
        /// </summary>
        /// <param name="type">当前类型。</param>
        /// <returns>返回接口定义。</returns>
        public static string GetClass(this Type type)
        {
            var typeDescriptor = AssemblyDocument.GetTypeDescriptor(type);
            var builder        = new StringBuilder();

            builder.AppendLine("/// <summary>")
            .Append("/// ").AppendLine(typeDescriptor?.Summary)
            .AppendLine("/// </summary>");
            builder.Append("public ").Append(type.IsEnum ? "enum" : "class").Append(" ").Append(type.Name).AppendLine("{");

            void Append(PropertyInfo info)
            {
                var summary = typeDescriptor?.GetPropertyDescriptor(info.Name)?.Summary;

                if (summary == null)
                {
                    return;
                }

                builder.AppendLine("    /// <summary>")
                .Append("    /// ").AppendLine(summary)
                .AppendLine("    /// </summary>");
                builder.Append("    public ").Append(info.PropertyType.Name)
                .Append(" ").Append(info.Name)
                .AppendLine(" {get; set;}");
            }

            void AppendValue(object value)
            {
                var summary = typeDescriptor?.GetPropertyDescriptor(value.ToString())?.Summary;

                if (summary != null)
                {
                    builder.AppendLine("    /// <summary>")
                    .Append("    /// ").AppendLine(summary)
                    .AppendLine("    /// </summary>");
                }
                builder.Append("    ").Append(value).Append(" = ").AppendFormat("{0:d}", value).AppendLine(",");
            }

            if (type.IsEnum)
            {
                foreach (var value in Enum.GetValues(type))
                {
                    AppendValue(value);
                }
            }
            else
            {
                foreach (var property in type.GetProperties())
                {
                    if (!property.CanRead || !property.CanWrite)
                    {
                        continue;
                    }
                    Append(property);
                }
            }

            builder.AppendLine("}");
            return(builder.ToString());
        }