Example #1
0
        public static bool IsInterceptable(this ItemDefinition definition, PropertyInfo property, out IEnumerable <IInterceptableProperty> attributes)
        {
            if (!IsSuitableForInterceptionOrPersistence(property))
            {
                attributes = new IInterceptableProperty[0];
                return(false);
            }

            attributes = definition.GetCustomAttributes <IInterceptableProperty>(property.Name);
            return(ContainsInterceptableDeclaration(attributes));
        }
		private IEnumerable<AttributedProperty> GetInterceptableProperties(ItemDefinition definition)
		{
			// Also include properties on base classes since properties are matched by reference and
			// and we want to intercept calls to properties on base classes with the same name
			for (Type t = definition.ItemType; t != null; t = t.BaseType)
			{
				foreach (var property in t.GetProperties())
				{
					if (!property.CanRead)
						continue;
					if (!property.GetGetMethod().IsVirtual)
						continue;
					if (!property.IsCompilerGenerated())
						continue;

					var attributes = definition.GetCustomAttributes<IInterceptableProperty>(property.Name);
					if (attributes.Any(a => a.PersistAs != PropertyPersistenceLocation.Detail && a.PersistAs != PropertyPersistenceLocation.DetailCollection))
						// some property is persisted as something other than detail or detail collection
						continue;
					if (!attributes.Any(a => a.PersistAs == PropertyPersistenceLocation.Detail || a.PersistAs == PropertyPersistenceLocation.DetailCollection))
						// no property is persisted as detail or detail collection
						continue;

					yield return new AttributedProperty { Property = property, Attribute = attributes.First() };
				}
			}
		}