Exemple #1
0
        public void Initialize(PropertyTypeNode propertyType)
        {
            var parent = propertyType.Parent;

            var attribute = propertyType.PropertyInfo.GetCustomAttributes(typeof(ReadOnlyAttribute), true)?.FirstOrDefault() as ReadOnlyAttribute;

            if (attribute != null || parent != null && parent.Extensions.TryGet <ReadOnlyAttribute, bool>(out var isReadOnly) && isReadOnly)
            {
                propertyType.Extensions.Set <ReadOnlyAttribute, bool>(true);
            }
        }
        private static void Traverse(Type type, Action <PropertyTypeNode> evaluate, PropertyTypeNode node, int depth)
        {
            depth++;

            if (depth > MaxDepth)
            {
                return;
            }

            var properties = type.GetProperties();

            foreach (var property in properties)
            {
                if (!Helpers.IsLattiaProperty(property))
                {
                    continue;
                }

                var currentNode = new PropertyTypeNode(node, property);

                evaluate(currentNode);

                var innerType = property.GetGenericArgument();

                switch (property.GetGenericArgument().ResolveSerializablePropertyType())
                {
                case SerializablePropertyType.Simple:
                    break;

                case SerializablePropertyType.Object:
                    Traverse(innerType, evaluate, currentNode, depth);
                    break;

                case SerializablePropertyType.Enumerable:
                    Traverse(innerType.GetEnumerableItemType(), evaluate, currentNode, depth);
                    break;

                default: throw new NotSupportedException(innerType.FullName);
                }
            }

            depth--;
        }