示例#1
0
        /// <summary>
        /// .ctor. Performs reflection scan ot given entity type and its properties.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <remarks>Slow operation.</remarks>
        public TikEntityMetadata(Type entityType)
        {
#if NET20 || NET35 || NET40
            TikEntityAttribute entityAttribute = (TikEntityAttribute)entityType.GetCustomAttributes(true).FirstOrDefault(a => a is TikEntityAttribute);
#else
            TikEntityAttribute entityAttribute = (TikEntityAttribute)entityType.GetTypeInfo().GetCustomAttributes(true).FirstOrDefault(a => a is TikEntityAttribute);
#endif
            if (entityAttribute == null)
            {
                throw new ArgumentException("Entity class must be decorated by TikEntityAttribute attribute.");
            }

            _entityType = entityType;

            EntityPath      = entityAttribute.EntityPath;
            IsReadOnly      = entityAttribute.IsReadOnly;
            IsOrdered       = entityAttribute.IsOrdered;
            IncludeDetails  = entityAttribute.IncludeDetails;
            IncludeProplist = entityAttribute.IncludeProplist;
            IsSingleton     = entityAttribute.IsSingleton;

            //properties
#if NET20 || NET35 || NET40
            _properties = entityType.GetProperties()
#else
            _properties = entityType.GetTypeInfo().GetAllProperties()
#endif
                          .Where(propInfo => propInfo.GetCustomAttribute <TikPropertyAttribute>(true) != null)
                          .Select(propInfo => new TikEntityPropertyAccessor(this, propInfo))
                          .ToDictionary(propDescriptor => propDescriptor.FieldName);
        }
示例#2
0
        /// <summary>
        /// .ctor. Performs reflection scan ot given entity type and its properties.
        /// </summary>
        /// <param name="entityType">Type of the entity.</param>
        /// <remarks>Slow operation.</remarks>
        public TikEntityMetadata(Type entityType)
        {
            TikEntityAttribute entityAttribute = (TikEntityAttribute)entityType.GetCustomAttributes(true).FirstOrDefault(a => a is TikEntityAttribute);

            if (entityAttribute == null)
            {
                throw new ArgumentException("Entity class must be decorated by TikEntityAttribute attribute.");
            }

            EntityPath      = entityAttribute.EntityPath;
            IsReadOnly      = entityAttribute.IsReadOnly;
            IsOrdered       = entityAttribute.IsOrdered;
            IncludeDetails  = entityAttribute.IncludeDetails;
            IncludeProplist = entityAttribute.IncludeProplist;

            //properties
            _properties = entityType.GetProperties()
                          .Where(propInfo => propInfo.GetCustomAttribute <TikPropertyAttribute>(true) != null)
                          .Select(propInfo => new TikEntityPropertyAccessor(this, propInfo))
                          .ToDictionary(propDescriptor => propDescriptor.FieldName);
        }