当前位置: 首页>>代码示例>>C#>>正文


C# EntityBase.GetType方法代码示例

本文整理汇总了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;
        }
开发者ID:Novthirteen,项目名称:sconit_timesseiko,代码行数:29,代码来源:EntityHelper.cs

示例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);
                }
            }
        }
开发者ID:sudiparora,项目名称:AASolFW,代码行数:46,代码来源:EntityConverter.cs

示例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);
    }
开发者ID:vishalrajpure,项目名称:SLX_v80_TUV_VFS,代码行数:24,代码来源:SpeedSearch.ascx.cs

示例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);
 }
开发者ID:BrunoCamargos,项目名称:ClientService,代码行数:9,代码来源:Validator.cs

示例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();
        }
开发者ID:guipaa,项目名称:PDF.NET,代码行数:69,代码来源:PdfNetSerialize.cs

示例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);
        }
开发者ID:dekema2,项目名称:c-raft,代码行数:33,代码来源:BlockBase.cs


注:本文中的EntityBase.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。