Exemplo n.º 1
0
 /// <summary>
 ///     Publicly available method that converts an enumerable of a Type attributed with an ObjectDefinitionAttribute
 ///     into an enumerable DataEntities projected by the QueryEntity.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="queryEntity"></param>
 /// <returns></returns>
 public static IEnumerable <DataEntity> ToDataEntities <T>(
     IEnumerable <T> data,
     QueryEntity queryEntity,
     ObjDefs ods)
 {
     return(data.Select(x => ObjDefConverter.To(x, ods, queryEntity)));
 }
Exemplo n.º 2
0
        internal static DataEntity ToDataEntity <T>(T a, QueryEntity queryEntity = null)
        {
            var assembly = Assembly.GetAssembly(typeof(T));
            var m        = MetadataReflector.GetAllObjectDefHeaders(assembly);
            var ods      = new ObjDefs(m.Values);

            return(ToDataEntity(a, queryEntity, ods));
        }
        public void TestToDataEntity()
        {
            var ox = new ObjX {
                Abc = "asdf"
            };

            var o = MetadataReflector.BuildObjectDefHeader(typeof(ObjX));

            var enricher   = new ObjDefs(new[] { o });
            var dataEntity = ObjDefConverter.To(ox, enricher);
            var objx       = ObjDefConverter.From <ObjX>(dataEntity, enricher);

            Assert.AreEqual(1, dataEntity.Properties.Count);
            Assert.AreEqual("ObjX", dataEntity.ObjectDefinitionFullName);
            Assert.AreEqual("asdf", objx.Abc);
            Assert.AreNotSame(ox, objx);
        }
        public void TestMutuallyRecursieveGettingAndSetting()
        {
            var o1 = MetadataReflector.BuildObjectDefHeader(typeof(A));
            var o2 = MetadataReflector.BuildObjectDefHeader(typeof(B));

            var enricher = new ObjDefs(new[] { o1, o2 });


            var dataEntity = ObjDefConverter.To(
                Helper.MakeA(), enricher);

            var a = ObjDefConverter.From <A>(dataEntity, enricher);

            Assert.AreEqual(1, dataEntity.Properties.Count);
            Assert.AreEqual("A", dataEntity.ObjectDefinitionFullName);
            Assert.AreEqual("XYZ", a.S);
            Assert.AreEqual("ABC", a.B.A.S);
        }
        public void TestGettingNullLists()
        {
            var o1 = MetadataReflector.BuildObjectDefHeader(typeof(A));
            var o2 = MetadataReflector.BuildObjectDefHeader(typeof(HasLists));
            var ob = MetadataReflector.BuildObjectDefHeader(typeof(B));

            var enricher = new ObjDefs(new[] { o1, o2, ob });

            var hl = new HasLists {
                As = null
            };

            var dataEntity = ObjDefConverter.To(
                hl, enricher);

            var a = ObjDefConverter.From <HasLists>(dataEntity, enricher);

            Assert.AreEqual(0, dataEntity.Properties.Count);
            Assert.AreEqual("HasLists", dataEntity.ObjectDefinitionFullName);
            Assert.IsTrue(a.As.Count == 0);
        }
        public void TestRecursieveGettingAndSetting()
        {
            var oxchild = new Recurser2 {
                S = "asdf"
            };
            var oxRoot = new Recurser2 {
                S = "qwer", R = oxchild
            };
            var o = MetadataReflector.BuildObjectDefHeader(typeof(Recurser2));

            var enricher = new ObjDefs(new[] { o });


            var dataEntity = ObjDefConverter.To(oxRoot, enricher);
            var objx       = ObjDefConverter.From <Recurser2>(dataEntity, enricher);

            Assert.AreEqual(1, dataEntity.Properties.Count);
            Assert.AreEqual("Recurser2", dataEntity.ObjectDefinitionFullName);
            Assert.AreEqual("qwer", objx.S);
            Assert.AreNotSame(oxRoot, objx);

            Assert.AreEqual("asdf", objx.R.S);
        }
        public void TestComplexLists()
        {
            var o1 = MetadataReflector.BuildObjectDefHeader(typeof(A));
            var o2 = MetadataReflector.BuildObjectDefHeader(typeof(HasLists));
            var ob = MetadataReflector.BuildObjectDefHeader(typeof(B));

            var enricher = new ObjDefs(new[] { o1, o2, ob });

            var hl = new HasLists {
                As = new List <A> {
                    Helper.MakeA()
                }
            };

            var dataEntity = ObjDefConverter.To(hl, enricher);

            var a = ObjDefConverter.From <HasLists>(dataEntity, enricher);

            Assert.AreEqual(0, dataEntity.Properties.Count);
            Assert.AreEqual("HasLists", dataEntity.ObjectDefinitionFullName);
            Assert.AreEqual("XYZ", a.As.First().S);
            Assert.AreEqual("ABC", a.As.First().B.A.S);
        }
Exemplo n.º 8
0
 /// <summary>
 ///     Publicly available method that converts a Type attributed with an ObjectDefinitionAttribute
 ///     into a DataEntity projected by the QueryEntity.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="queryEntity"></param>
 /// <returns></returns>
 public static DataEntity ToDataEntity <T>(T data, QueryEntity queryEntity, ObjDefs ods)
 {
     return(ObjDefConverter.To(data, ods, queryEntity));
 }
Exemplo n.º 9
0
 public Reflector(Assembly assembly)
 {
     this.objectDefHeaders = MetadataReflector.GetAllObjectDefHeaders(assembly);
     this.objDefsEnriched  = new ObjDefs(this.objectDefHeaders.Values);
     this.metadata         = MetadataReflector.ReflectMetadata(this.objectDefHeaders);
 }
Exemplo n.º 10
0
 public static T FromDataEntity <T>(DataEntity entity, ObjDefs objDefsEnriched)
     where T : new()
 {
     return(ObjDefConverter.From <T>(entity, objDefsEnriched, entity.ObjectDefinitionFullName));
 }