Exemplo n.º 1
0
        public override ConfigSectionNode ProvideMetadata(MemberInfo member, object instance, IMetadataGenerator context, ConfigSectionNode dataRoot, NodeOverrideRules overrideRules = null)
        {
            var tdoc = member.NonNull(nameof(member)) as Type;

            if (tdoc == null || !typeof(Doc).IsAssignableFrom(tdoc))
            {
                return(null);
            }

            var typed = tdoc.IsSubclassOf(typeof(TypedDoc));

            var    ndoc = dataRoot.AddChildNode("data-doc");
            Schema schema;

            if (instance is Doc doc)
            {
                schema = doc.Schema;
            }
            else if (typed)
            {
                schema = Schema.GetForTypedDoc(tdoc);
            }
            else
            {
                schema = null;
            }

            MetadataUtils.AddMetadataTokenIdAttribute(ndoc, tdoc);
            ndoc.AddAttributeNode("kind", typed ? "typed" : "dynamic");

            CustomMetadataAttribute.Apply(typeof(Schema), schema, context, ndoc, overrideRules);

            return(ndoc);
        }
        public void Car_1()
        {
            var data = Conf.Configuration.NewEmptyRoot();

            CustomMetadataAttribute.Apply(typeof(Car).GetMethod("Draw"), null, null, data);

            data.ToLaconicString(Azos.CodeAnalysis.Laconfig.LaconfigWritingOptions.PrettyPrint).See();

            Aver.AreEqual(123, data.AttrByName("a").ValueAsInt());
            Aver.AreEqual(789, data.AttrByName("b").ValueAsInt());
            Aver.AreEqual(100, data.AttrByName("score").ValueAsInt());
            Aver.AreEqual(0, data.AttrByName("z").ValueAsInt());
            Aver.AreEqual("Generic car", data.AttrByName("description").Value);
            Aver.AreEqual("world", data.Navigate("origin/$country").Value);
        }
        public void BMW_1()
        {
            var data = Conf.Configuration.NewEmptyRoot();

            CustomMetadataAttribute.Apply(typeof(BMW).GetMethod("Draw"), null, null, data);

            data.ToLaconicString(Azos.CodeAnalysis.Laconfig.LaconfigWritingOptions.PrettyPrint).See();

            Aver.AreEqual(123, data.AttrByName("a").ValueAsInt());
            Aver.AreEqual(789, data.AttrByName("b").ValueAsInt());
            Aver.AreEqual(100, data.AttrByName("score").ValueAsInt());
            Aver.AreEqual(190, data.AttrByName("z").ValueAsInt());
            Aver.AreEqual("Bavarian Motor Works", data.AttrByName("description").Value);
            Aver.AreEqual("world", data.Navigate("origin/$country").Value); //was not set on purpose, cloned from EuropeanCar/Car
        }
        public void Toyota_1()
        {
            var data = Conf.Configuration.NewEmptyRoot();

            CustomMetadataAttribute.Apply(typeof(Toyota).GetMethod("Draw"), null, null, data);

            data.ToLaconicString(Azos.CodeAnalysis.Laconfig.LaconfigWritingOptions.PrettyPrint).See();

            Aver.AreEqual(123, data.AttrByName("a").ValueAsInt());
            Aver.AreEqual(-1, data.AttrByName("b").ValueAsInt());
            Aver.AreEqual(137, data.AttrByName("score").ValueAsInt());
            Aver.AreEqual(7, data.AttrByName("z").ValueAsInt());
            Aver.AreEqual("Toyota motors", data.AttrByName("description").Value);
            Aver.AreEqual("jap", data.Navigate("origin/$country").Value);
        }
        public void Cadillac_1()
        {
            var data = Conf.Configuration.NewEmptyRoot();

            CustomMetadataAttribute.Apply(typeof(Cadillac).GetMethod("Draw"), null, null, data);

            data.ToLaconicString(Azos.CodeAnalysis.Laconfig.LaconfigWritingOptions.PrettyPrint).See();

            Aver.AreEqual(123, data.AttrByName("a").ValueAsInt());
            Aver.AreEqual(789, data.AttrByName("b").ValueAsInt());
            Aver.AreEqual(40, data.AttrByName("score").ValueAsInt());
            Aver.AreEqual(0, data.AttrByName("z").ValueAsInt());
            Aver.AreEqual("Luxury item, but unreliable", data.AttrByName("description").Value);
            Aver.AreEqual("usa", data.Navigate("origin/$country").Value); //in spite of XYZ set in config, the American-level override pragma set to stop
        }
        public void Buick_1()
        {
            var data = Conf.Configuration.NewEmptyRoot();

            CustomMetadataAttribute.Apply(typeof(Buick).GetMethod("Draw"), null, null, data);

            data.ToLaconicString(Azos.CodeAnalysis.Laconfig.LaconfigWritingOptions.PrettyPrint).See();

            Aver.AreEqual(-900, data.AttrByName("a").ValueAsInt());
            Aver.AreEqual(789, data.AttrByName("b").ValueAsInt());
            Aver.AreEqual(90, data.AttrByName("score").ValueAsInt());
            Aver.AreEqual(0, data.AttrByName("z").ValueAsInt());
            Aver.AreEqual("Very usable and decent quality", data.AttrByName("description").Value);
            Aver.AreEqual("usa", data.Navigate("origin/$country").Value);
        }
Exemplo n.º 7
0
        public void AmericanCar_1()
        {
            var data = Conf.Configuration.NewEmptyRoot();

            CustomMetadataAttribute.Apply(typeof(AmericanCar).GetMethod("Draw"), null, null, data);

            Console.WriteLine(data.ToLaconicString(Azos.CodeAnalysis.Laconfig.LaconfigWritingOptions.PrettyPrint));

            Aver.AreEqual(123, data.AttrByName("a").ValueAsInt());
            Aver.AreEqual(789, data.AttrByName("b").ValueAsInt());
            Aver.AreEqual(75, data.AttrByName("score").ValueAsInt());
            Aver.AreEqual(0, data.AttrByName("z").ValueAsInt());
            Aver.AreEqual("Cars built in the US", data.AttrByName("description").Value);
            Aver.AreEqual("usa", data.Navigate("origin/$country").Value);
        }
        public void EuropeanCar_1()
        {
            var data = Conf.Configuration.NewEmptyRoot();

            CustomMetadataAttribute.Apply(typeof(EuropeanCar), null, null, data);

            Console.WriteLine(data.ToLaconicString(Azos.CodeAnalysis.Laconfig.LaconfigWritingOptions.PrettyPrint));

            Aver.AreEqual(123, data.AttrByName("a").ValueAsInt());
            Aver.AreEqual(789, data.AttrByName("b").ValueAsInt());
            Aver.AreEqual(100, data.AttrByName("score").ValueAsInt());
            Aver.AreEqual(0, data.AttrByName("z").ValueAsInt());
            Aver.AreEqual("Generic car", data.AttrByName("description").Value);
            Aver.AreEqual("world", data.Navigate("origin/$country").Value); //was not set on purpose, cloned from Car
        }
        public void Honda_1()
        {
            var data = Conf.Configuration.NewEmptyRoot();

            CustomMetadataAttribute.Apply(typeof(Honda), null, null, data);

            Console.WriteLine(data.ToLaconicString(Azos.CodeAnalysis.Laconfig.LaconfigWritingOptions.PrettyPrint));

            Aver.AreEqual(123, data.AttrByName("a").ValueAsInt());
            Aver.AreEqual(789, data.AttrByName("b").ValueAsInt());
            Aver.AreEqual(110, data.AttrByName("score").ValueAsInt());
            Aver.AreEqual(1, data.AttrByName("z").ValueAsInt());
            Aver.AreEqual("Honda motors", data.AttrByName("description").Value);
            Aver.AreEqual("jap", data.Navigate("origin/$country").Value);
        }