private void ParseMetadata(Type entityType)
        {
            //type info
            TikEntityAttribute entityAttr = entityType.GetCustomAttributes(false).FirstOrDefault(a => a is TikEntityAttribute) as TikEntityAttribute;

            if (entityAttr != null)
            {
                entityInfo = entityAttr;
            }
            else
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Entity {0} is not marked by {1} attribute.", entityType, typeof(TikEntityAttribute)));
            }

            //properties info
            propertiesInfo = new Dictionary <string, TikPropertyAttribute>();
            foreach (PropertyInfo propInfo in entityType.GetProperties())
            {
                TikPropertyAttribute propAttr = propInfo.GetCustomAttributes(false).FirstOrDefault(a => a is TikPropertyAttribute) as TikPropertyAttribute;
                if (propAttr != null)
                {
                    Type propType = propAttr.PropertyType;
                    if (propType != propInfo.PropertyType)
                    {
                        throw new InvalidProgramException(string.Format(CultureInfo.CurrentCulture, "Inconsistent property '{0} type in {1}. Real type {2}, declared in TikPropertyAttribute {3}.",
                                                                        propInfo.Name, entityType, propInfo.PropertyType, propType));
                    }
                    propertiesInfo.Add(propAttr.PropertyName, propAttr);
                }
            }
        }
示例#2
0
        private void ParseMetadata(Type entityType)
        {
            //type info
            TikEntityAttribute entityAttr = entityType.GetCustomAttributes(false).FirstOrDefault(a => a is TikEntityAttribute) as TikEntityAttribute;
            if (entityAttr != null)
                entityInfo = entityAttr;
            else
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Entity {0} is not marked by {1} attribute.", entityType, typeof(TikEntityAttribute)));

            //properties info
            propertiesInfo = new Dictionary<string, TikPropertyAttribute>();
            foreach (PropertyInfo propInfo in entityType.GetProperties())
            {
                TikPropertyAttribute propAttr = propInfo.GetCustomAttributes(false).FirstOrDefault(a => a is TikPropertyAttribute) as TikPropertyAttribute;
                if (propAttr != null)
                {
                    Type propType = propAttr.PropertyType;
                    if (propType != propInfo.PropertyType)
                    {
                        throw new InvalidProgramException(string.Format(CultureInfo.CurrentCulture, "Inconsistent property '{0} type in {1}. Real type {2}, declared in TikPropertyAttribute {3}.",
                            propInfo.Name, entityType, propInfo.PropertyType, propType));
                    }
                    propertiesInfo.Add(propAttr.PropertyName, propAttr);
                }
            }
        }