Пример #1
0
        protected NamedObject ResolveNDO(NamedObject ndo_changes, out string idProperty_Name)
        {
            object to_change        = null;
            string idProperty_Value = Service.GetIdentityFieldValue(ndo_changes, out idProperty_Name);

            if (idProperty_Value == null || idProperty_Value == "0")
            {
                to_change = ResolveCDO(ndo_changes.GetType(), ndo_changes.Name);
            }
            else
            {
                to_change = ResolveCDOByID(ndo_changes.GetType(), idProperty_Value);
            }
            return(to_change as NamedObject);
        }
Пример #2
0
        virtual protected bool Update(NamedObject ndo_changes, out NamedObject to_change)
        {
            string idProperty_Name = null;

            to_change = ResolveNDO(ndo_changes, out idProperty_Name);

            if (to_change != null)
            {
                ObjScope.Transaction.Begin();
                foreach (PropertyInfo pi in ndo_changes.GetType().GetProperties())
                {
                    if (pi.Name == idProperty_Name)
                    {
                        continue;   // do not update Primary Property
                    }
                    object v_changes = pi.GetValue(ndo_changes, null);
                    if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType))
                    {
                        SetProperty(to_change, pi, v_changes);
                    }
                }
                ObjScope.Transaction.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        virtual public bool Add(NamedObject ndo_insert)
        {
            string idProperty_Name = null;
            object check_exist     = ResolveNDO(ndo_insert, out idProperty_Name);

            if (check_exist == null)
            {
                foreach (PropertyInfo pi in ndo_insert.GetType().GetProperties())
                {
                    if (pi.Name == idProperty_Name)
                    {
                        continue;   // do not update Primary Property
                    }
                    object v_changes = pi.GetValue(ndo_insert, null);
                    if (v_changes != null && (pi.CanWrite || v_changes.GetType().IsGenericType))
                    {
                        SetProperty(ndo_insert, pi, v_changes);
                    }
                }
                ObjScope.Transaction.Begin();
                ObjScope.Add(ndo_insert);
                ObjScope.Transaction.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
 public void SetTargetObj(NamedObject target)
 {
     TargetObj = target; TargetObjType = target.GetType();
 }
 public void GetFieldWithOutAttributes()
 {
     NamedObject n = new NamedObject();
     FieldInfoCollection fi = ReflectionUtil.GetFieldsWithOutAttributes(n.GetType(), typeof(XmlElementAttribute), typeof(XmlIgnoreAttribute));
     Assert.AreEqual(0, fi.Count, "Get fields without attributes found attributes even though they are marked!");
     fi = ReflectionUtil.GetFieldsWithOutAttributes(n.GetType(), typeof(AssemblyFlagsAttribute), typeof(AssemblyKeyNameAttribute));
     Assert.AreEqual(2, fi.Count, "Getfields without attributes didn't find all the fields, even though they are marked with other attribute");
     fi = ReflectionUtil.GetFieldsWithOutAttributes(n.GetType(), typeof(XmlIgnoreAttribute));
     Assert.AreEqual(1, fi.Count, "GetFields without attributes didn't filter correctly");
 }
Пример #6
0
        public void TestThatConstructorInitializeNamedObjectWithDescription()
        {
            var fixture     = new Fixture();
            var nameSource  = fixture.CreateAnonymous <string>();
            var nameTarget  = fixture.CreateAnonymous <string>();
            var description = fixture.CreateAnonymous <string>();

            var namedObject = new NamedObject(nameSource, nameTarget, description);

            Assert.That(namedObject, Is.Not.Null);
            Assert.That(namedObject.NameSource, Is.Not.Null);
            Assert.That(namedObject.NameSource, Is.Not.Empty);
            Assert.That(namedObject.NameSource, Is.EqualTo(nameSource));
            Assert.That(namedObject.NameTarget, Is.Not.Null);
            Assert.That(namedObject.NameTarget, Is.Not.Empty);
            Assert.That(namedObject.NameTarget, Is.EqualTo(nameTarget));
            Assert.That(namedObject.Description, Is.Not.Null);
            Assert.That(namedObject.Description, Is.Not.Empty);
            Assert.That(namedObject.Description, Is.EqualTo(description));
            Assert.That(namedObject.ExceptionInfo, Is.Not.Null);
            Assert.That(namedObject.ExceptionInfo, Is.Not.Empty);
            Assert.That(namedObject.ExceptionInfo, Is.EqualTo(string.Format("{0}, NameSource={1}, NameTarget={2}, Description={3}", namedObject.GetType().Name, namedObject.NameSource, namedObject.NameTarget, namedObject.Description)));
            Assert.That(namedObject.MetadataObject, Is.Not.Null);
            Assert.That(namedObject.MetadataObject, Is.EqualTo(namedObject));
        }