예제 #1
0
        public void InitTest()
        {
            var info = typeof(MambaRuntimeTypeTest).GetProperty("Property");

            var mambaType = new MambaRuntimeType(info);

            Assert.AreEqual("Property", mambaType.Name);
            Assert.AreEqual(typeof(string), mambaType.PropertyType);
            Assert.AreEqual(info, mambaType.Info);

            mambaType.SetValue(this, "Hello");
            Assert.AreEqual("Hello", mambaType.GetValue(this));

            var field = typeof(MambaRuntimeTypeTest).GetField("_myField");

            mambaType = new MambaRuntimeType(field);

            Assert.AreEqual("_myField", mambaType.Name);
            Assert.AreEqual(typeof(string), mambaType.PropertyType);
            Assert.AreEqual(field, mambaType.Info);

            mambaType.SetValue(this, "Hello");
            Assert.AreEqual("Hello", mambaType.GetValue(this));

            var fields     = new [] { info };
            var mambaTypes = MambaRuntimeType.FromPropertiesList(fields);

            Assert.AreEqual(1, mambaTypes.Count);
        }
        public static List <AuditPropertyConfiguration> GetAuditEntityProperties(Type runtimeEntityProperty)
        {
#if NETFRAMEWORK
            using (new Profiling.Profiler(nameof(AuditPropertyConfiguration), Profiling.AppDevSymbolType.ClassOperation, "GetAuditEntityProperties"))
            {
#endif
            var repo = ServiceLocator.Current.GetInstance <IRepositoryBuilder>().CreateRetrieveRepository();

            List <AuditPropertyConfiguration> properties     = new List <AuditPropertyConfiguration>();
            AuditPropertyConfiguration newproperty           = new AuditPropertyConfiguration();
            List <AuditEntityConfiguration> existingEntities = repo.GetAll <AuditEntityConfiguration>();
            AuditEntityConfiguration existingEntity          = new AuditEntityConfiguration();
            foreach (var currentProperty in MambaRuntimeType.FromPropertiesList(runtimeEntityProperty.GetProperties()) ?? Enumerable.Empty <MambaRuntimeType>())
            {
                if ((SkipProperty(currentProperty.Name)))
                {
                    continue;
                }
                newproperty           = new AuditPropertyConfiguration();
                existingEntity        = existingEntities?.FirstOrDefault((a) => a.FullName == Common.GetTypeName(runtimeEntityProperty, true));
                newproperty.Name      = currentProperty.Name;
                newproperty.IsComplex = ((Common.IsPropertyPrimitiveOrSimple(currentProperty)) == false);
                if ((currentProperty.PropertyType.GenericTypeArguments.Length > 0) && (currentProperty.PropertyType.GenericTypeArguments.ToList().FirstOrDefault() != null))
                {
                    newproperty.DataType = Common.GetTypeName(currentProperty.PropertyType.GenericTypeArguments.ToList().FirstOrDefault(), true);
                }
                else
                {
                    newproperty.DataType = Common.GetTypeName(currentProperty.PropertyType, true);
                }
                if (newproperty?.DataType == "System.String")
                {
                    newproperty.IsCollection = false;
                }
                else
                {
                    newproperty.IsCollection = Common.IsPropertyCollection(currentProperty);
                }
                if (existingEntity != null && existingEntity?.Properties?.FirstOrDefault((x) => x.Name == currentProperty.Name) != null)
                {
                    newproperty.IsAuditable = (existingEntity?.Properties?.FirstOrDefault((x) => x.Name == currentProperty.Name)?.IsAuditable ?? false);
                }
                else
                {
                    newproperty.IsAuditable = false;
                }
                properties?.Add(newproperty);
            }
            return(properties);

#if NETFRAMEWORK
        }
#endif
        }
예제 #3
0
        public void IsTypePrimitiveOrSimpleTest()
        {
            var info = typeof(CommonTest).GetProperty("Property");

            var mambaType = new MambaRuntimeType(info);

            Assert.IsTrue(Common.IsTypePrimitiveOrSimple(typeof(String)));
            Assert.IsTrue(Common.IsTypePrimitiveOrSimple(typeof(int)));
            Assert.IsTrue(Common.IsTypeCollection(typeof(List <string>)));

            Assert.IsTrue(Common.IsPropertyPrimitiveOrSimple(info));
            Assert.IsTrue(Common.IsPropertyPrimitiveOrSimple(mambaType));

            info      = typeof(CommonTest).GetProperty("Items");
            mambaType = new MambaRuntimeType(info);

            Assert.IsTrue(Common.IsPropertyCollection(info));
            Assert.IsTrue(Common.IsPropertyCollection(mambaType));
        }