本文整理汇总了C#中Rock.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Rock.GetType方法的具体用法?C# Rock.GetType怎么用?C# Rock.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock
的用法示例。
在下文中一共展示了Rock.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComponentDescription
/// <summary>
/// Initializes a new instance of the <see cref="ComponentDescription"/> class.
/// </summary>
/// <param name="id">The id.</param>
/// <param name="service">The service.</param>
public ComponentDescription( int id, Rock.Attribute.IHasAttributes service )
{
Id = id;
Type type = service.GetType();
Name = type.Name;
// Look for a DescriptionAttribute on the class and if found, use its value for the description
// property of this class
var descAttributes = type.GetCustomAttributes( typeof( System.ComponentModel.DescriptionAttribute ), false );
if ( descAttributes != null )
foreach ( System.ComponentModel.DescriptionAttribute descAttribute in descAttributes )
Description = descAttribute.Description;
// If the class has an PropertyAttribute with 'Active' as the key get it's value for the property
// otherwise default to true
if ( service.AttributeValues.ContainsKey( "Active" ) )
Active = bool.Parse( service.AttributeValues["Active"].Value );
else
Active = true;
}
示例2: LoadAttributes
/// <summary>
/// Loads the <see cref="P:IHasAttributes.Attributes"/> and <see cref="P:IHasAttributes.AttributeValues"/> of any <see cref="IHasAttributes"/> object
/// </summary>
/// <param name="item">The item.</param>
public static void LoadAttributes( Rock.Attribute.IHasAttributes item )
{
var attributes = new SortedDictionary<string, List<Web.Cache.Attribute>>();
var attributeValues = new Dictionary<string, KeyValuePair<string, List<Rock.Core.DTO.AttributeValue>>>();
Dictionary<string, PropertyInfo> properties = new Dictionary<string, PropertyInfo>();
Type entityType = item.GetType();
if ( entityType.Namespace == "System.Data.Entity.DynamicProxies" )
entityType = entityType.BaseType;
foreach ( PropertyInfo propertyInfo in entityType.GetProperties() )
properties.Add( propertyInfo.Name.ToLower(), propertyInfo );
Rock.Core.AttributeService attributeService = new Rock.Core.AttributeService();
foreach ( Rock.Core.Attribute attribute in attributeService.GetByEntity( entityType.FullName ) )
{
if ( string.IsNullOrEmpty( attribute.EntityQualifierColumn ) ||
( properties.ContainsKey( attribute.EntityQualifierColumn.ToLower() ) &&
( string.IsNullOrEmpty( attribute.EntityQualifierValue ) ||
properties[attribute.EntityQualifierColumn.ToLower()].GetValue( item, null ).ToString() == attribute.EntityQualifierValue ) ) )
{
Rock.Web.Cache.Attribute cachedAttribute = Rock.Web.Cache.Attribute.Read(attribute);
if ( !attributes.ContainsKey( cachedAttribute.Category ) )
attributes.Add( cachedAttribute.Category, new List<Web.Cache.Attribute>() );
attributes[cachedAttribute.Category].Add( cachedAttribute );
attributeValues.Add( attribute.Key, new KeyValuePair<string, List<Rock.Core.DTO.AttributeValue>>( attribute.Name, attribute.GetValues( item.Id ) ) );
}
}
item.Attributes = attributes;
item.AttributeValues = attributeValues;
}
示例3: LoadAttributes
/// <summary>
/// Loads the <see cref="P:IHasAttributes.Attributes" /> and <see cref="P:IHasAttributes.AttributeValues" /> of any <see cref="IHasAttributes" /> object
/// </summary>
/// <param name="entity">The item.</param>
/// <param name="rockContext">The rock context.</param>
public static void LoadAttributes( Rock.Attribute.IHasAttributes entity, RockContext rockContext )
{
if ( entity != null )
{
Dictionary<string, PropertyInfo> properties = new Dictionary<string, PropertyInfo>();
Type entityType = entity.GetType();
if ( entityType.Namespace == "System.Data.Entity.DynamicProxies" )
entityType = entityType.BaseType;
rockContext = rockContext ?? new RockContext();
// Check for group type attributes
var groupTypeIds = new List<int>();
if ( entity is GroupMember || entity is Group || entity is GroupType )
{
// Can't use GroupTypeCache here since it loads attributes and would result in a recursive stack overflow situation
var groupTypeService = new GroupTypeService( rockContext );
GroupType groupType = null;
if ( entity is GroupMember )
{
var group = ( (GroupMember)entity ).Group ?? new GroupService( rockContext )
.Queryable().AsNoTracking().FirstOrDefault(g => g.Id == ( (GroupMember)entity ).GroupId );
if ( group != null )
{
groupType = group.GroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == group.GroupTypeId );
}
}
else if ( entity is Group )
{
groupType = ( (Group)entity ).GroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == ( (Group)entity ).GroupTypeId );
}
else
{
groupType = ( (GroupType)entity );
}
while ( groupType != null )
{
groupTypeIds.Insert( 0, groupType.Id );
// Check for inherited group type id's
if ( groupType.InheritedGroupTypeId.HasValue )
{
groupType = groupType.InheritedGroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == ( groupType.InheritedGroupTypeId ?? 0 ) );
}
else
{
groupType = null;
}
}
}
foreach ( PropertyInfo propertyInfo in entityType.GetProperties() )
properties.Add( propertyInfo.Name.ToLower(), propertyInfo );
Rock.Model.AttributeService attributeService = new Rock.Model.AttributeService( rockContext );
Rock.Model.AttributeValueService attributeValueService = new Rock.Model.AttributeValueService( rockContext );
var inheritedAttributes = new Dictionary<int, List<Rock.Web.Cache.AttributeCache>>();
if ( groupTypeIds.Any() )
{
groupTypeIds.ForEach( g => inheritedAttributes.Add( g, new List<Rock.Web.Cache.AttributeCache>() ) );
}
else
{
inheritedAttributes.Add( 0, new List<Rock.Web.Cache.AttributeCache>() );
}
var attributes = new List<Rock.Web.Cache.AttributeCache>();
// Get all the attributes that apply to this entity type and this entity's properties match any attribute qualifiers
var entityTypeCache = Rock.Web.Cache.EntityTypeCache.Read( entityType);
if ( entityTypeCache != null )
{
int entityTypeId = entityTypeCache.Id;
foreach ( var attribute in attributeService.Queryable()
.AsNoTracking()
.Where( a => a.EntityTypeId == entityTypeCache.Id )
.Select( a => new
{
a.Id,
a.EntityTypeQualifierColumn,
a.EntityTypeQualifierValue
}
) )
{
// group type ids exist (entity is either GroupMember, Group, or GroupType) and qualifier is for a group type id
if ( groupTypeIds.Any() && (
( entity is GroupMember && string.Compare( attribute.EntityTypeQualifierColumn, "GroupTypeId", true ) == 0 ) ||
//.........这里部分代码省略.........
示例4: LoadAttributes
/// <summary>
/// Loads the <see cref="P:IHasAttributes.Attributes" /> and <see cref="P:IHasAttributes.AttributeValues" /> of any <see cref="IHasAttributes" /> object
/// </summary>
/// <param name="entity">The item.</param>
/// <param name="rockContext">The rock context.</param>
public static void LoadAttributes( Rock.Attribute.IHasAttributes entity, RockContext rockContext )
{
if ( entity != null )
{
Dictionary<string, PropertyInfo> properties = new Dictionary<string, PropertyInfo>();
Type entityType = entity.GetType();
if ( entityType.IsDynamicProxyType() )
{
entityType = entityType.BaseType;
}
rockContext = rockContext ?? new RockContext();
// Event item's will load attributes for child calendar items. Use this to store the child values.
var altEntityIds = new List<int>();
// Check for group type attributes
var groupTypeIds = new List<int>();
if ( entity is GroupMember || entity is Group || entity is GroupType )
{
// Can't use GroupTypeCache here since it loads attributes and would result in a recursive stack overflow situation
var groupTypeService = new GroupTypeService( rockContext );
GroupType groupType = null;
if ( entity is GroupMember )
{
var group = ( (GroupMember)entity ).Group ?? new GroupService( rockContext )
.Queryable().AsNoTracking().FirstOrDefault(g => g.Id == ( (GroupMember)entity ).GroupId );
if ( group != null )
{
groupType = group.GroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == group.GroupTypeId );
}
}
else if ( entity is Group )
{
groupType = ( (Group)entity ).GroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == ( (Group)entity ).GroupTypeId );
}
else
{
groupType = ( (GroupType)entity );
}
while ( groupType != null )
{
groupTypeIds.Insert( 0, groupType.Id );
// Check for inherited group type id's
if ( groupType.InheritedGroupTypeId.HasValue )
{
groupType = groupType.InheritedGroupType ?? groupTypeService
.Queryable().AsNoTracking().FirstOrDefault( t => t.Id == ( groupType.InheritedGroupTypeId ?? 0 ) );
}
else
{
groupType = null;
}
}
}
// Check for registration template type attributes
int? registrationTemplateId = null;
if ( entity is RegistrationRegistrant )
{
RegistrationInstance registrationInstance = null;
var registration = ( (RegistrationRegistrant)entity ).Registration ?? new RegistrationService( rockContext )
.Queryable().AsNoTracking().FirstOrDefault( r => r.Id == ( (RegistrationRegistrant)entity ).RegistrationId );
if ( registration != null )
{
registrationInstance = registration.RegistrationInstance ?? new RegistrationInstanceService( rockContext )
.Queryable().AsNoTracking().FirstOrDefault( r => r.Id == registration.RegistrationInstanceId );
if ( registrationInstance != null )
{
registrationTemplateId = registrationInstance.RegistrationTemplateId;
}
}
}
// Get the calendar ids for any event items
var calendarIds = new List<int>();
if ( entity is EventItem )
{
var calendarItems = ( (EventItem)entity ).EventCalendarItems.ToList() ?? new EventCalendarItemService( rockContext )
.Queryable().AsNoTracking().Where( c => c.EventItemId == ( (EventItem)entity ).Id ).ToList();
calendarIds = calendarItems.Select( c => c.EventCalendarId ).ToList();
altEntityIds = calendarItems.Select( c => c.Id ).ToList();
}
foreach ( PropertyInfo propertyInfo in entityType.GetProperties() )
properties.Add( propertyInfo.Name.ToLower(), propertyInfo );
Rock.Model.AttributeService attributeService = new Rock.Model.AttributeService( rockContext );
//.........这里部分代码省略.........