本文整理汇总了C#中EntityBase.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# EntityBase.GetType方法的具体用法?C# EntityBase.GetType怎么用?C# EntityBase.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityBase
的用法示例。
在下文中一共展示了EntityBase.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EntityPropertyEquals
public static bool EntityPropertyEquals(EntityBase entity1, EntityBase entity2, string property)
{
if (!entity1.GetType().Equals(entity2.GetType()))
{
throw new TechnicalException("Type:" + entity1.GetType() +" of Entity1 is not as same as Type:" + entity2.GetType() + " of Entity2");
}
object value1 = entity1;
object value2 = entity2;
string[] fieldArray = property.Split('.');
foreach (string singleField in fieldArray)
{
if (value1 == null && value2 == null)
{
return true;
}
PropertyInfo singlePropInfo = getPropertyInfo(value1, singleField);
value1 = singlePropInfo.GetValue(value1, null);
value2 = singlePropInfo.GetValue(value2, null);
if ((value1 != null && value1.Equals(value2)) || value2 != null)
{
return false;
}
}
return true;
}
示例2: FillData
private static void FillData(IDTO dto, EntityBase entity, bool populateEntityFromDTO)
{
var dtoType = dto.GetType();
var entityType = entity.GetType();
if (!VerifyValidEntityType(entityType, dtoType))
{
throw new EntityConversionException();
}
var properties = dtoType.GetProperties();
var sourceObject = populateEntityFromDTO ? (dto as object) : (entity as object);
var destinationObject = populateEntityFromDTO ? (entity as object) : (dto as object);
foreach (PropertyInfo property in properties)
{
var attributes = property.GetCustomAttributes(typeof(EntityPropertyMappingAttribute), false);
if (attributes.Length == 0)
{
continue;
}
bool skipThisProperty = false;
foreach (object customAttribute in attributes)
{
EntityPropertyMappingAttribute entityPropertyMappingAttribute = (EntityPropertyMappingAttribute)customAttribute;
if (entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.None
|| (populateEntityFromDTO && entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.DTOFromEntity)
|| (!populateEntityFromDTO && entityPropertyMappingAttribute.MappingDirection == MappingDirectionType.EntityFromDTO))
{
skipThisProperty = true;
break;
}
}
if (skipThisProperty)
{
continue;
}
var entityProperty = entityType.GetProperty(property.Name);
var sourceProperty = populateEntityFromDTO ? property : entityProperty;
var destinationProperty = populateEntityFromDTO ? entityProperty : property;
var sourceValue = sourceProperty.GetValue(sourceObject, null);
if (destinationProperty.CanWrite)
{
destinationProperty.SetValue(destinationObject, sourceValue, null);
}
}
}
示例3: ReturnResult
//protected void btnReturnResult_Click(object sender, EventArgs e)
private void ReturnResult()
{
InitializeState();
int index = (string.IsNullOrEmpty(CurrentPageIndex.Value)) ? 0 : int.Parse(CurrentPageIndex.Value);
if (string.IsNullOrEmpty(currentIndex.Value)) return;
whichResultsPage = index;
SpeedSearchService ss = new SpeedSearchService();
SpeedSearchQuery ssq = BuildQuery();
ssq.DocTextItem = int.Parse(currentIndex.Value) + 1000000;
string xml = ss.DoSpeedSearch(ssq.GetAsXml());
Results = SpeedSearchResults.LoadFromXml(xml);
_ResultEntity = (EntityBase)m_EntityContextService.GetEntity();
if (!string.IsNullOrEmpty(_ChildPropertyName))
{
PropertyDescriptor child = TypeDescriptor.GetProperties(_ResultEntity.GetType())[_ChildPropertyName];
_ResultEntity = (EntityBase)child.GetValue(_ResultEntity);
}
PropertyDescriptor resultProp = TypeDescriptor.GetProperties(_ResultEntity.GetType())[_ResultProperty];
resultProp.SetValue(_ResultEntity, Results.Items[0].HighlightedDoc);
DialogService.CloseEventHappened(null, null);
}
示例4: GetPropertyValue
/// <summary>
/// Pega o valor da propriedade da entidade usando reflection
/// </summary>
/// <param name="entityBase"></param>
/// <returns></returns>
protected object GetPropertyValue(EntityBase entityBase)
{
return entityBase.GetType().GetProperty(PropertyName).GetValue(entityBase, null);
}
示例5: BinarySerialize
/// <summary>
/// 二进制序列化
/// </summary>
/// <param name="entity">实体类实例</param>
/// <returns>字节数组</returns>
public static byte[] BinarySerialize(EntityBase entity)
{
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);
Type factEntityType = entity.GetType();
EntityFields ef = EntityFieldsCache.Item(factEntityType);
byte b;
//写入实体类标记
bw.Write(ENTITY_ITEM_FLAG);
int length = entity.PropertyValues.Length-1;
for (int i = 0; i <= length; i++)
{
object obj = entity.PropertyValues[i];
//if (obj == System.DBNull.Value) obj = null;//DBNull.Value在Convert 的时候会失败
//为每个属性添加null标记
if (obj == System.DBNull.Value || obj == null)
b = 0;//NULL标记
else
{
if (length == i) b = byte.MaxValue; else b = 1;//如果标志位为 byte.MaxValue ,则表示已经写入所有的属性字段,可用于以后添加实体属性但又要成功读取原有的记录
}
bw.Write(b); //写入标记
if (b >0 )
{
Type propertyType = ef.GetPropertyType(entity.PropertyNames[i]);
if (propertyType == null)
throw new Exception("PDF.NET实体类序列化错误:未知的实体属性类型,请检查实体类的属性和字段定义是否匹配。");
switch (propertyType.Name )
{
case "Int32":
bw.Write(Convert.ToInt32(obj)); break;
case "String":
bw.Write(Convert.ToString(obj));
break;
case "DateTime":
bw.Write(((DateTime)obj).ToBinary());
break;
case "Int16": bw.Write(Convert.ToInt16(obj)); break;
case "Int64": bw.Write(Convert.ToInt64(obj)); break;
case "Single": bw.Write(Convert.ToSingle(obj)); break;
case "Double": bw.Write(Convert.ToDouble(obj)); break;
case "Decimal": bw.Write(Convert.ToDecimal(obj)); break;
case "Boolean": bw.Write(Convert.ToBoolean(obj)); break;
case "Byte": bw.Write(Convert.ToByte(obj)); break;
case "Char": bw.Write(Convert.ToChar(obj)); break;
case "Byte[]":
Byte[] buffer = (Byte[])obj;
bw.Write(buffer.Length);//写入字节序列的长度
if (buffer.Length > 0)
bw.Write(buffer);
break;
}
}
}
bw.Close();
ms.Close();
return ms.ToArray();
}
示例6: Destroy
/// <summary>
/// Destroy the block
/// </summary>
/// <param name="entity">entity who destroyed the block</param>
/// <param name="block">block that has been destroyed</param>
public virtual void Destroy(EntityBase entity, StructBlock block)
{
BlockDestroyEventArgs eventArgs = RaiseDestroyEvent(entity, block);
if (eventArgs.EventCanceled)
return;
PlaySoundOnDestroy(entity, block);
UpdateWorld(block, true);
// Check if the entity is a player
if ((entity != null) && (entity.GetType() == typeof(Player)))
{
// Check if the player is in creative mode
if (((Player)entity).GameMode == System.Convert.ToByte(1))
{
// Don't drop any items as the player is in creative mode
goto skipDrop;
}
}
DropItems(entity, block);
skipDrop:
DamageItem(entity);
NotifyNearbyBlocks(entity, block);
}