コード例 #1
0
 private static void ValidateDynamic(MetadataNode node)
 {
     if (node.Metadata.Composition?.AddDynamic == null)
     {
         throw BindingException.FromProperty(node.Identity.Name, $"Dynamic add method not found.");
     }
 }
コード例 #2
0
        public static void Validate(AggregateNode aggregateNode)
        {
            if (aggregateNode.Item == null)
            {
                return;
            }

            foreach (MetadataNode node in aggregateNode.Item.Tree().Skip(1))
            {
                if (!node.Metadata.HasFlag(BindingMetadataFlags.Writable))
                {
                    throw BindingException.FromProperty(node.Identity.Name, $"Property is read-only.");
                }

                if (node.ListIndex == null)
                {
                    ValidateConstructor(node);
                }

                if (node.ListIndex == null && node.HasFlag(NodeFlags.Dynamic))
                {
                    ValidateDynamic(node);
                }
            }
        }
コード例 #3
0
        private static void ValidateConstructor(MetadataNode node)
        {
            NewExpression constructor = node.Metadata.Composition?.Construct;

            if (constructor == null)
            {
                throw BindingException.FromProperty(node.Identity.Name, $"No default constructor defined.");
            }
            else if (!node.Metadata.Type.IsAssignableFrom(constructor.Type))
            {
                throw BindingException.FromProperty(node.Identity.Name, $"No conversion exists between constructor type '{constructor.Type.GetSanitizedName()}' and property type '{node.Metadata.Type.GetSanitizedName()}'.");
            }
        }
コード例 #4
0
        public static void Validate(MetadataNode itemNode)
        {
            foreach (MetadataNode node in itemNode.Tree())
            {
                if (!node.Metadata.HasFlag(BindingMetadataFlags.Item) && !node.Metadata.HasFlag(BindingMetadataFlags.Writable))
                {
                    throw BindingException.FromProperty(node.Identity.Name, $"Property is read-only.");
                }

                if (node.Column == null)
                {
                    ValidateConstructor(node);
                }

                if (node.Column == null && node.HasFlag(NodeFlags.Dynamic))
                {
                    ValidateDynamic(node);
                }
            }
        }