/// <summary> /// Gets the properties and methods. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> private MClass GetPropertiesAndMethods(Type type, bool includeInherited = true) { MClass mClass = new MClass { Name = type.Name, Guid = type.GUID.ToStringSafe(), Comment = GetComments(type) }; PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | (includeInherited ? BindingFlags.Instance : BindingFlags.Instance | BindingFlags.DeclaredOnly)).Where(m => (m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property)).ToArray(); foreach (PropertyInfo p in properties.OrderBy(i => i.Name).ToArray()) { mClass.Properties.Add(new MProperty { Name = p.Name, IsInherited = p.DeclaringType != type, IsVirtual = p.GetGetMethod() != null && p.GetGetMethod().IsVirtual, IsLavaInclude = p.IsDefined(typeof(LavaIncludeAttribute)), NotMapped = p.IsDefined(typeof(NotMappedAttribute)), Required = p.IsDefined(typeof(RequiredAttribute)), Id = p.MetadataToken, Comment = GetComments(p) }); } MethodInfo[] methods = type.GetMethods(BindingFlags.Public | (includeInherited ? BindingFlags.Instance : BindingFlags.Instance | BindingFlags.DeclaredOnly)).Where(m => !m.IsSpecialName && (m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property)).ToArray(); foreach (MethodInfo m in methods.OrderBy(i => i.Name).ToArray()) { // crazy, right? var param = string.Join(", ", m.GetParameters().Select(pi => { var x = pi.ParameterType + " " + pi.Name; return(x); })); mClass.Methods.Add(new MMethod { Name = m.Name, IsInherited = m.DeclaringType != type, Id = m.MetadataToken, Signature = string.Format("{0}({1})", m.Name, param), Comment = GetComments(m) }); } return(mClass); }
/// <summary> /// Build a "node" of the class/model with its properties and methods inside. /// </summary> /// <param name="aClass"></param> /// <returns></returns> private string ClassNode(MClass aClass) { var sb = new StringBuilder(); if (aClass.Properties.Any() || aClass.Methods.Any()) { if (aClass.Properties.Any()) { sb.AppendLine("<h5 class='font-weight-normal'>Properties</h5><table class='table table-properties'>"); foreach (var property in aClass.Properties.OrderBy(p => p.Name)) { bool?isRequired = gfSettings.GetUserPreference("IsRequired").AsBooleanOrNull(); bool?isDatabase = gfSettings.GetUserPreference("IsDatabase").AsBooleanOrNull(); bool?isLava = gfSettings.GetUserPreference("IsLava").AsBooleanOrNull(); if (isRequired.HasValue && isRequired.Value != property.Required) { continue; } if (isDatabase.HasValue && isDatabase.Value != (!property.NotMapped && !property.IsVirtual)) { continue; } if (isLava.HasValue && isLava.Value != property.IsLavaInclude) { continue; } sb.AppendFormat( "<tr data-id='p{0}' {11}><td class='d-block d-sm-table-cell'>{8}<tt class='cursor-default font-weight-bold {3}' title='{6}'>{1}</tt> {4}{5}</td><td class='d-block d-sm-table-cell'>{9}{2}{12}{10}</td></tr>{7}", property.Id, // 0 HttpUtility.HtmlEncode(property.Name), // 1 (property.Comment != null && !string.IsNullOrWhiteSpace(property.Comment.Summary)) ? " " + property.Comment.Summary : string.Empty, // 2 property.Required ? "required-indicator" : string.Empty, // 3 property.IsLavaInclude ? " <i class='fa fa-bolt fa-fw text-warning unselectable'></i> " : string.Empty, // 4 string.Empty, // 5 property.IsInherited ? "inherited" : string.Empty, // 6 Environment.NewLine, // 7 property.NotMapped || property.IsVirtual ? "<i class='fa fa-square fa-fw o-20'></i> " : "<i class='fa fa-database fa-fw'></i> ", // 8 property.IsObsolete ? "<i class='fa fa-ban fa-fw text-danger' title='no longer supported'></i> <span class='small text-danger'>" + property.ObsoleteMessage + " </span> " : string.Empty, // 9 (property.IsEnum || property.IsDefinedValue) && property.KeyValues != null ? GetStringFromKeyValues(property.KeyValues) : string.Empty, /*10*/ property.IsObsolete ? "class='o-50' title='Obsolete'" : "class=''", (property.IsEnum || property.IsDefinedValue) ? GetStringForEnumOrDefinedType(property) : string.Empty ); } sb.AppendLine("</table>"); } if (aClass.Methods.Any()) { sb.AppendLine("<h4 class='js-model hidden '=>Methods</h4><ul>"); if (aClass.Methods.Where(m => m.IsInherited == false).Count() == 0) { sb.AppendLine("<li class='js-model hidden'><small class='text-muted'><i>all inherited</i></small></li>"); } foreach (var method in aClass.Methods.OrderBy(m => m.Name)) { sb.AppendFormat( "<li data-id='m{0}' class='{3}'><tt class='font-weight-bold'>{1}</tt> {2}{4} {6}</li>{5}", method.Id, HttpUtility.HtmlEncode(method.Signature), (method.Comment != null && !string.IsNullOrWhiteSpace(method.Comment.Summary)) ? " - " + method.Comment.Summary : string.Empty, "js-model hidden ", method.IsInherited ? " (inherited)" : string.Empty, Environment.NewLine, // 5 method.IsObsolete ? "<i class='fa fa-ban fa-fw text-danger' title='no longer supported'></i> <i>" + method.ObsoleteMessage + " </i> " : string.Empty /*6*/); } sb.AppendLine("</ul>"); } } return(sb.ToString()); }
private void ShowData(Guid?categoryGuid, int?entityTypeId) { if (EntityCategories == null) { LoadCategories(); } hfSelectedCategoryGuid.Value = categoryGuid.ToString(); hfSelectedEntityId.Value = null; // Bind Categories rptCategory.DataSource = EntityCategories; rptCategory.DataBind(); pnlModels.Visible = false; pnlKey.Visible = false; lCategoryName.Text = string.Empty; EntityTypeCache entityType = null; var entityTypeList = new List <EntityTypeCache>(); if (categoryGuid.HasValue) { var category = EntityCategories.Where(c => c.Guid.Equals(categoryGuid)).FirstOrDefault(); if (category != null) { lCategoryName.Text = category.Name.SplitCase() + " Models"; pnlModels.Visible = true; entityTypeList = category .RockEntityIds .Select(a => EntityTypeCache.Get(a)) .Where(a => a != null) .OrderBy(et => et.FriendlyName) .ToList(); if (entityTypeId.HasValue) { entityType = entityTypeList.Where(t => t.Id == entityTypeId.Value).FirstOrDefault(); hfSelectedEntityId.Value = entityType != null?entityType.Id.ToString() : null; } else { entityType = entityTypeList.FirstOrDefault(); hfSelectedEntityId.Value = entityTypeList.Any() ? entityTypeList.First().Id.ToString() : null; } } } // Bind Models rptModel.DataSource = entityTypeList; rptModel.DataBind(); string details = string.Empty; nbClassesWarning.Visible = false; pnlClassDetail.Visible = false; if (entityType != null) { try { var type = entityType.GetEntityType(); if (type != null) { pnlKey.Visible = true; var xmlComments = GetXmlComments(); var mClass = new MClass(); mClass.Name = type.Name; mClass.Comment = GetComments(type, xmlComments); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(m => m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property) .ToArray(); foreach (PropertyInfo p in properties.OrderBy(i => i.Name).ToArray()) { #pragma warning disable CS0618 // LavaIncludeAttribute is obsolete var property = new MProperty { Name = p.Name, IsInherited = p.DeclaringType != type, IsVirtual = p.GetGetMethod() != null && p.GetGetMethod().IsVirtual&& !p.GetGetMethod().IsFinal, IsLavaInclude = p.IsDefined(typeof(LavaIncludeAttribute)) || p.IsDefined(typeof(LavaVisibleAttribute)) || p.IsDefined(typeof(DataMemberAttribute)), IsObsolete = p.IsDefined(typeof(ObsoleteAttribute)), ObsoleteMessage = GetObsoleteMessage(p), NotMapped = p.IsDefined(typeof(NotMappedAttribute)), Required = p.IsDefined(typeof(RequiredAttribute)), Id = p.MetadataToken, Comment = GetComments(p, xmlComments, properties), IsEnum = p.PropertyType.IsEnum, IsDefinedValue = p.Name.EndsWith("ValueId") && p.IsDefined(typeof(DefinedValueAttribute)) }; #pragma warning restore CS0618 // LavaIncludeAttribute is obsolete if (property.IsEnum) { property.KeyValues = new Dictionary <string, string>(); var values = p.PropertyType.GetEnumValues(); foreach (var value in values) { property.KeyValues.AddOrReplace((( int )value).ToString(), value.ToString()); } } else if (property.IsDefinedValue) { var definedValueAttribute = p.GetCustomAttribute <Rock.Data.DefinedValueAttribute>(); if (definedValueAttribute != null && definedValueAttribute.DefinedTypeGuid.HasValue) { property.KeyValues = new Dictionary <string, string>(); var definedTypeGuid = definedValueAttribute.DefinedTypeGuid.Value; var definedType = DefinedTypeCache.Get(definedTypeGuid); property.DefinedTypeId = definedType.Id; foreach (var definedValue in definedType.DefinedValues) { property.KeyValues.AddOrReplace(string.Format("{0} = {1}", definedValue.Id, definedValue.Value), definedValue.Description); } } } mClass.Properties.Add(property); } MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance) .Where(m => !m.IsSpecialName && (m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property)) .ToArray(); foreach (MethodInfo m in methods.OrderBy(i => i.Name).ToArray()) { // crazy, right? var param = string.Join(", ", m.GetParameters().Select(pi => { var x = pi.ParameterType + " " + pi.Name; return(x); })); mClass.Methods.Add(new MMethod { Name = m.Name, IsInherited = m.DeclaringType != type, Id = m.MetadataToken, Signature = string.Format("{0}({1})", m.Name, param), Comment = GetComments(m, xmlComments), IsObsolete = m.IsDefined(typeof(ObsoleteAttribute)), ObsoleteMessage = GetObsoleteMessage(m) }); } var pageReference = new Rock.Web.PageReference(CurrentPageReference); pageReference.QueryString = new System.Collections.Specialized.NameValueCollection(); pageReference.QueryString["EntityType"] = entityType.Guid.ToString(); lClassName.Text = mClass.Name; hlAnchor.NavigateUrl = pageReference.BuildUrl(); lClassDescription.Text = mClass.Comment != null ? mClass.Comment.Summary : string.Empty; lClasses.Text = ClassNode(mClass); pnlClassDetail.Visible = true; } else { nbClassesWarning.Text = "Unable to get class details for " + entityType.FriendlyName; nbClassesWarning.Details = entityType.AssemblyName; nbClassesWarning.Dismissable = true; nbClassesWarning.Visible = true; } } catch (Exception ex) { nbClassesWarning.Text = string.Format("Error getting class details for <code>{0}</code>", entityType); nbClassesWarning.Details = ex.Message; nbClassesWarning.Dismissable = true; nbClassesWarning.Visible = true; } } }
/// <summary> /// Build a "node" of the class/model with its properties and methods inside. /// </summary> /// <param name="aClass"></param> /// <returns></returns> private string ClassNode(MClass aClass) { var sb = new StringBuilder(); if (aClass.Properties.Any() || aClass.Methods.Any()) { if (aClass.Properties.Any()) { sb.AppendLine("<h4>Properties</h4><ul class='list-unstyled'>"); foreach (var property in aClass.Properties.OrderBy(p => p.Name)) { bool?isRequired = gfSettings.GetUserPreference("IsRequired").AsBooleanOrNull(); bool?isDatabase = gfSettings.GetUserPreference("IsDatabase").AsBooleanOrNull(); bool?isLava = gfSettings.GetUserPreference("IsLava").AsBooleanOrNull(); if (isRequired.HasValue && isRequired.Value != property.Required) { continue; } if (isDatabase.HasValue && isDatabase.Value != (!property.NotMapped && !property.IsVirtual)) { continue; } if (isLava.HasValue && isLava.Value != property.IsLavaInclude) { continue; } sb.AppendFormat("<li data-id='p{0}' class='{6}'><strong>{9}<tt>{1}</tt></strong>{3}{4}{5}{2}{7}</li>{8}", property.Id, // 0 HttpUtility.HtmlEncode(property.Name), // 1 (property.Comment != null && !string.IsNullOrWhiteSpace(property.Comment.Summary)) ? " - " + property.Comment.Summary : "", // 2 property.Required ? " <strong class='text-danger'>*</strong> " : string.Empty, // 3 property.IsLavaInclude ? " <i class='fa fa-bolt fa-fw text-warning'></i> " : string.Empty, // 4 "", // 5 property.IsInherited ? " js-model hidden " : " ", // 6 property.IsInherited ? " (inherited)" : "", // 7 Environment.NewLine, // 8 property.NotMapped || property.IsVirtual ? "<i class='fa fa-square-o fa-fw'></i> " : "<i class='fa fa-database fa-fw'></i> " // 9 ); } sb.AppendLine("</ul>"); } if (aClass.Methods.Any()) { sb.AppendLine("<h4>Methods</h4><ul>"); if (aClass.Methods.Where(m => m.IsInherited == false).Count() == 0) { sb.AppendLine("<small class='text-muted'><i>all inherited</i></small>"); } foreach (var method in aClass.Methods.OrderBy(m => m.Name)) { sb.AppendFormat("<li data-id='m{0}' class='{3}'><strong><tt>{1}</tt></strong> {2}{4}</li>{5}", method.Id, HttpUtility.HtmlEncode(method.Signature), (method.Comment != null && !string.IsNullOrWhiteSpace(method.Comment.Summary)) ? " - " + method.Comment.Summary : "", method.IsInherited ? " js-model hidden " : " ", method.IsInherited ? " (inherited)" : "", Environment.NewLine); } sb.AppendLine("</ul>"); } } return(sb.ToString()); }
/// <summary> /// Build a "node" of the class/model with its properties and methods inside. /// </summary> /// <param name="aClass"></param> /// <param name="expandedClassNameGuidList"></param> /// <returns></returns> private string ClassNode(MClass aClass) { var sb = new StringBuilder(); var name = HttpUtility.HtmlEncode(aClass.Name); sb.AppendFormat( "<div class='panel panel-block' data-id='{0}'><div class='panel-heading'><h1 class='panel-title rollover-container'>{1}</h1><p class='description'>{2}</p></div>", aClass.Guid, name, aClass.Comment != null ? aClass.Comment.Summary : "" ); if (aClass.Properties.Any() || aClass.Methods.Any()) { sb.AppendFormat("<div class='panel-body'>"); if (aClass.Properties.Any()) { sb.AppendLine("<small class='pull-right js-model-inherited'>Show: <i class='js-model-check fa fa-fw fa-square-o'></i> inherited</small><h4>Properties</h4><ul class='list-unstyled'>"); foreach (var property in aClass.Properties.OrderBy(p => p.Name)) { // data-expanded='false' data-model='Block' data-id='b{0}' sb.AppendFormat("<li data-id='p{0}' class='{6}'><strong>{9}<tt>{1}</tt></strong>{3}{4}{5}{2}{7}</li>{8}", property.Id, // 0 HttpUtility.HtmlEncode(property.Name), // 1 (property.Comment != null && !string.IsNullOrWhiteSpace(property.Comment.Summary)) ? " - " + property.Comment.Summary : "", // 2 property.Required ? " <strong class='text-danger'>*</strong> " : string.Empty, // 3 property.IsLavaInclude ? " <i class='fa fa-bolt fa-fw text-warning'></i> " : string.Empty, // 4 "", // 5 property.IsInherited ? " js-model hidden " : " ", // 6 property.IsInherited ? " (inherited)" : "", // 7 Environment.NewLine, // 8 property.NotMapped || property.IsVirtual ? "<i class='fa fa-square-o fa-fw'></i> " : "<i class='fa fa-database fa-fw'></i> " // 9 ); } sb.AppendLine("</ul>"); } if (aClass.Methods.Any()) { sb.AppendLine("<h4>Methods</h4><ul>"); if (aClass.Methods.Where(m => m.IsInherited == false).Count() == 0) { sb.AppendLine("<small class='text-muted'><i>all inherited</i></small>"); } foreach (var method in aClass.Methods.OrderBy(m => m.Name)) { //<li data-expanded='false' data-model='Block' data-id='b{0}'><span>{1}{2}:{3}</span></li>{4} sb.AppendFormat("<li data-id='m{0}' class='{3}'><strong><tt>{1}</tt></strong> {2}{4}</li>{5}", method.Id, HttpUtility.HtmlEncode(method.Signature), (method.Comment != null && !string.IsNullOrWhiteSpace(method.Comment.Summary)) ? " - " + method.Comment.Summary : "", method.IsInherited ? " js-model hidden " : " ", method.IsInherited ? " (inherited)" : "", Environment.NewLine); } sb.AppendLine("</ul>"); } sb.AppendLine("</div>"); } sb.AppendLine("</div>"); return(sb.ToString()); }
private void ShowData(Guid?categoryGuid, int?entityTypeId) { if (EntityCategories == null) { LoadCategories(); } hfSelectedCategoryGuid.Value = categoryGuid.ToString(); hfSelectedEntityId.Value = null; // Bind Categories rptCategory.DataSource = EntityCategories; rptCategory.DataBind(); pnlModels.Visible = false; pnlKey.Visible = false; lCategoryName.Text = string.Empty; EntityTypeCache entityType = null; var entityTypeList = new List <EntityTypeCache>(); if (categoryGuid.HasValue) { var category = EntityCategories.Where(c => c.Guid.Equals(categoryGuid)).FirstOrDefault(); if (category != null) { lCategoryName.Text = category.Name + " Models"; pnlModels.Visible = true; entityTypeList = category.RockEntityIds.Select(a => EntityTypeCache.Read(a)).Where(a => a != null).ToList(); if (entityTypeId.HasValue) { entityType = entityTypeList.Where(t => t.Id == entityTypeId.Value).FirstOrDefault(); hfSelectedEntityId.Value = entityType != null?entityType.Id.ToString() : null; } else { entityType = entityTypeList.FirstOrDefault(); hfSelectedEntityId.Value = entityTypeList.Any() ? entityTypeList.First().Id.ToString() : null; } } } // Bind Models rptModel.DataSource = entityTypeList; rptModel.DataBind(); string details = string.Empty; nbClassesWarning.Visible = false; if (entityType != null) { try { var type = entityType.GetEntityType(); if (type != null) { pnlKey.Visible = true; var xmlComments = GetXmlComments(); var mClass = new MClass(); mClass.Name = type.Name; mClass.Comment = GetComments(type, xmlComments); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | (BindingFlags.Instance)) .Where(m => (m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property)) .ToArray(); foreach (PropertyInfo p in properties.OrderBy(i => i.Name).ToArray()) { mClass.Properties.Add(new MProperty { Name = p.Name, IsInherited = p.DeclaringType != type, IsVirtual = p.GetGetMethod() != null && p.GetGetMethod().IsVirtual&& !p.GetGetMethod().IsFinal, IsLavaInclude = p.IsDefined(typeof(LavaIncludeAttribute)) || p.IsDefined(typeof(DataMemberAttribute)), NotMapped = p.IsDefined(typeof(NotMappedAttribute)), Required = p.IsDefined(typeof(RequiredAttribute)), Id = p.MetadataToken, Comment = GetComments(p, xmlComments) }); } MethodInfo[] methods = type.GetMethods(BindingFlags.Public | (BindingFlags.Instance)) .Where(m => !m.IsSpecialName && (m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property)) .ToArray(); foreach (MethodInfo m in methods.OrderBy(i => i.Name).ToArray()) { // crazy, right? var param = string.Join(", ", m.GetParameters().Select(pi => { var x = pi.ParameterType + " " + pi.Name; return(x); })); mClass.Methods.Add(new MMethod { Name = m.Name, IsInherited = m.DeclaringType != type, Id = m.MetadataToken, Signature = string.Format("{0}({1})", m.Name, param), Comment = GetComments(m, xmlComments) }); } details = ClassNode(mClass); } else { nbClassesWarning.Text = "Unable to get class details for " + entityType.FriendlyName; nbClassesWarning.Details = entityType.AssemblyName; nbClassesWarning.Dismissable = true; nbClassesWarning.Visible = true; } } catch (Exception ex) { nbClassesWarning.Text = string.Format("Error getting class details for <code>{0}</code>", entityType); nbClassesWarning.Details = ex.Message; nbClassesWarning.Dismissable = true; nbClassesWarning.Visible = true; } } lClasses.Text = details; }
/// <summary> /// Build a "node" of the class/model with its properties and methods inside. /// </summary> /// <param name="aClass"></param> /// <param name="expandedClassNameGuidList"></param> /// <returns></returns> private string ClassNode(MClass aClass) { var sb = new StringBuilder(); string classGuid = this.PageParameter("classGuid"); bool isSelected = false; if (!string.IsNullOrWhiteSpace(classGuid)) { isSelected = aClass.Guid == classGuid; } var name = HttpUtility.HtmlEncode(aClass.Name); sb.AppendFormat( "<div class='panel panel-default' data-id='{0}'><div class='panel-heading js-example-toggle'><h1 class='panel-title rollover-container'><a name='{1}' href='?classGuid={0}#{1}' class='link-address rollover-item' style='margin-left: -20px;'><i class='fa fa-link'></i></a> <strong>{1}</strong> <small class='pull-right'><i class='fa js-toggle {3}'></i> Show Details</small></h1><p class='description'>{2}</p></div>", aClass.Guid, name, aClass.Comment.Summary, isSelected ? "fa-circle" : "fa-circle-o" ); if (aClass.Properties.Any() || aClass.Methods.Any()) { sb.AppendFormat("<div class='panel-body' {0}>", !isSelected ? "style='display: none;'" : string.Empty); if (aClass.Properties.Any()) { sb.AppendLine("<small class='pull-right js-model-inherited'>Show: <i class='js-model-check fa fa-fw fa-square-o'></i> inherited</small><h2>Properties</h2><ul>"); foreach (var property in aClass.Properties.OrderBy(p => p.Name)) { // data-expanded='false' data-model='Block' data-id='b{0}' sb.AppendFormat("<li data-id='p{0}' class='{6}'><strong><tt>{1}</tt></strong>{3}{4}{5}{2}{7}</li>{8}", property.Id, HttpUtility.HtmlEncode(property.Name), (property.Comment != null && !string.IsNullOrWhiteSpace(property.Comment.Summary)) ? " - " + property.Comment.Summary : "", property.Required ? " <strong class='text-danger'>*</strong> " : string.Empty, property.IsLavaInclude ? " <small><span class='tip tip-lava'></span></small> " : string.Empty, property.NotMapped || property.IsVirtual ? " <span class='fa-stack small'><i class='fa fa-database fa-stack-1x'></i><i class='fa fa-ban fa-stack-2x text-danger'></i></span> " : string.Empty, property.IsInherited ? " js-model hidden " : " ", property.IsInherited ? " (inherited)" : "", Environment.NewLine); } sb.AppendLine("</ul>"); } if (aClass.Methods.Any()) { sb.AppendLine("<h2>Methods</h2><ul>"); foreach (var method in aClass.Methods.OrderBy(m => m.Name)) { //<li data-expanded='false' data-model='Block' data-id='b{0}'><span>{1}{2}:{3}</span></li>{4} sb.AppendFormat("<li data-id='m{0}' class='{3}'><strong><tt>{1}</tt></strong> {2}{4}</li>{5}", method.Id, HttpUtility.HtmlEncode(method.Signature), (method.Comment != null && !string.IsNullOrWhiteSpace(method.Comment.Summary)) ? " - " + method.Comment.Summary : "", method.IsInherited ? " js-model hidden " : " ", method.IsInherited ? " (inherited)" : "", Environment.NewLine); } sb.AppendLine("</ul>"); } sb.AppendLine("</div>"); } sb.AppendLine("</div>"); return(sb.ToString()); }
/// <summary> /// Gets the properties and methods. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> private MClass GetPropertiesAndMethods( Type type, bool includeInherited = true ) { MClass mClass = new MClass { Name = type.Name, Guid = type.GUID.ToStringSafe(), Comment = GetComments( type ) }; PropertyInfo[] properties = type.GetProperties( BindingFlags.Public | ( includeInherited ? BindingFlags.Instance : BindingFlags.Instance | BindingFlags.DeclaredOnly ) ).Where( m => ( m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property ) ).ToArray(); foreach ( PropertyInfo p in properties.OrderBy( i => i.Name ).ToArray() ) { mClass.Properties.Add( new MProperty { Name = p.Name, IsInherited = p.DeclaringType != type, IsVirtual = p.GetGetMethod() != null && p.GetGetMethod().IsVirtual, IsLavaInclude = p.IsDefined( typeof( LavaIncludeAttribute ) ), NotMapped = p.IsDefined( typeof( NotMappedAttribute ) ), Required = p.IsDefined( typeof( RequiredAttribute ) ), Id = p.MetadataToken, Comment = GetComments( p ) } ); } MethodInfo[] methods = type.GetMethods( BindingFlags.Public | ( includeInherited ? BindingFlags.Instance : BindingFlags.Instance | BindingFlags.DeclaredOnly ) ).Where( m => !m.IsSpecialName && ( m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property ) ).ToArray(); foreach ( MethodInfo m in methods.OrderBy( i => i.Name ).ToArray() ) { // crazy, right? var param = string.Join( ", ", m.GetParameters().Select( pi => { var x = pi.ParameterType + " " + pi.Name; return x; } ) ); mClass.Methods.Add( new MMethod { Name = m.Name, IsInherited = m.DeclaringType != type, Id = m.MetadataToken, Signature = string.Format( "{0}({1})", m.Name, param ), Comment = GetComments( m ) } ); } return mClass; }
/// <summary> /// Build a "node" of the class/model with its properties and methods inside. /// </summary> /// <param name="aClass"></param> /// <param name="expandedClassNameGuidList"></param> /// <returns></returns> private string ClassNode( MClass aClass ) { var sb = new StringBuilder(); string classGuid = this.PageParameter( "classGuid" ); bool isSelected = false; if ( !string.IsNullOrWhiteSpace( classGuid ) ) { isSelected = aClass.Guid == classGuid; } var name = HttpUtility.HtmlEncode( aClass.Name ); sb.AppendFormat( "<div class='panel panel-default' data-id='{0}'><div class='panel-heading js-example-toggle'><h1 class='panel-title rollover-container'><a name='{1}' href='?classGuid={0}#{1}' class='link-address rollover-item' style='margin-left: -20px;'><i class='fa fa-link'></i></a> <strong>{1}</strong> <small class='pull-right'><i class='fa js-toggle {3}'></i> Show Details</small></h1><p class='description'>{2}</p></div>", aClass.Guid, name, aClass.Comment.Summary, isSelected ? "fa-circle" : "fa-circle-o" ); if ( aClass.Properties.Any() || aClass.Methods.Any() ) { sb.AppendFormat( "<div class='panel-body' {0}>", !isSelected ? "style='display: none;'" : string.Empty ); if ( aClass.Properties.Any() ) { sb.AppendLine( "<small class='pull-right js-model-inherited'>Show: <i class='js-model-check fa fa-fw fa-square-o'></i> inherited</small><h2>Properties</h2><ul>" ); foreach ( var property in aClass.Properties.OrderBy( p => p.Name ) ) { // data-expanded='false' data-model='Block' data-id='b{0}' sb.AppendFormat( "<li data-id='p{0}' class='{6}'><strong><tt>{1}</tt></strong>{3}{4}{5}{2}{7}</li>{8}", property.Id, HttpUtility.HtmlEncode( property.Name ), ( property.Comment != null && !string.IsNullOrWhiteSpace( property.Comment.Summary ) ) ? " - " + property.Comment.Summary : "", property.Required ? " <strong class='text-danger'>*</strong> " : string.Empty, property.IsLavaInclude ? " <small><span class='tip tip-lava'></span></small> " : string.Empty, property.NotMapped || property.IsVirtual ? " <span class='fa-stack small'><i class='fa fa-database fa-stack-1x'></i><i class='fa fa-ban fa-stack-2x text-danger'></i></span> " : string.Empty, property.IsInherited ? " js-model hidden " : " ", property.IsInherited ? " (inherited)" : "", Environment.NewLine ); } sb.AppendLine( "</ul>" ); } if ( aClass.Methods.Any() ) { sb.AppendLine( "<h2>Methods</h2><ul>" ); foreach ( var method in aClass.Methods.OrderBy( m => m.Name ) ) { //<li data-expanded='false' data-model='Block' data-id='b{0}'><span>{1}{2}:{3}</span></li>{4} sb.AppendFormat( "<li data-id='m{0}' class='{3}'><strong><tt>{1}</tt></strong> {2}{4}</li>{5}", method.Id, HttpUtility.HtmlEncode( method.Signature ), ( method.Comment != null && !string.IsNullOrWhiteSpace( method.Comment.Summary ) ) ? " - " + method.Comment.Summary : "", method.IsInherited ? " js-model hidden " : " ", method.IsInherited ? " (inherited)" : "", Environment.NewLine ); } sb.AppendLine( "</ul>" ); } sb.AppendLine( "</div>" ); } sb.AppendLine( "</div>" ); return sb.ToString(); }
private void ShowData(Guid?categoryGuid, int?entityTypeId) { if (EntityCategories == null) { LoadCategories(); } SelectedCategoryGuid = categoryGuid; selectedEntityId = null; // Bind Categories rptCategory.DataSource = EntityCategories; rptCategory.DataBind(); pnlModels.Visible = false; pnlKey.Visible = false; lCategoryName.Text = string.Empty; MEntity entityType = null; var entities = new List <MEntity>(); if (categoryGuid.HasValue) { var category = EntityCategories.Where(c => c.Guid.Equals(categoryGuid)).FirstOrDefault(); if (category != null) { lCategoryName.Text = category.Name + " Models"; pnlModels.Visible = true; entities = category.RockEntities.OrderBy(e => e.FriendlyName).ToList(); if (entityTypeId.HasValue) { entityType = entities.Where(t => t.Id == entityTypeId.Value).FirstOrDefault(); selectedEntityId = entityType != null ? entityType.Id : (int?)null; } else { entityType = entities.FirstOrDefault(); selectedEntityId = entities.Any() ? entities.First().Id : (int?)null; } } } // Bind Models rptModel.DataSource = entities; rptModel.DataBind(); string details = string.Empty; if (entityType != null) { details = "<div class='alert alert-warning'>Error getting class details!</div>"; var type = entityType.GetEntityType(); if (type != null) { pnlKey.Visible = true; var xmlComments = GetXmlComments(); var mClass = new MClass(); mClass.Name = type.Name; mClass.Comment = GetComments(type, xmlComments); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | (BindingFlags.Instance)) .Where(m => (m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property)) .ToArray(); foreach (PropertyInfo p in properties.OrderBy(i => i.Name).ToArray()) { mClass.Properties.Add(new MProperty { Name = p.Name, IsInherited = p.DeclaringType != type, IsVirtual = p.GetGetMethod() != null && p.GetGetMethod().IsVirtual&& !p.GetGetMethod().IsFinal, IsLavaInclude = p.IsDefined(typeof(LavaIncludeAttribute)) || p.IsDefined(typeof(DataMemberAttribute)), NotMapped = p.IsDefined(typeof(NotMappedAttribute)), Required = p.IsDefined(typeof(RequiredAttribute)), Id = p.MetadataToken, Comment = GetComments(p, xmlComments) }); } MethodInfo[] methods = type.GetMethods(BindingFlags.Public | (BindingFlags.Instance)) .Where(m => !m.IsSpecialName && (m.MemberType == MemberTypes.Method || m.MemberType == MemberTypes.Property)) .ToArray(); foreach (MethodInfo m in methods.OrderBy(i => i.Name).ToArray()) { // crazy, right? var param = string.Join(", ", m.GetParameters().Select(pi => { var x = pi.ParameterType + " " + pi.Name; return(x); })); mClass.Methods.Add(new MMethod { Name = m.Name, IsInherited = m.DeclaringType != type, Id = m.MetadataToken, Signature = string.Format("{0}({1})", m.Name, param), Comment = GetComments(m, xmlComments) }); } details = ClassNode(mClass); } } lClasses.Text = details; }