コード例 #1
0
        public ActionResult Edit(string id)
        {
            Good          good          = new Good();
            GoodViewModel goodViewModel = new GoodViewModel();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            good = _goodRepository.Get(x => x.Id == id).FirstOrDefault();

            if (good == null)
            {
                return(HttpNotFound());
            }

            goodViewModel.GoodId         = good.Id;
            goodViewModel.Name           = good.Name;
            goodViewModel.Price          = good.Price;
            goodViewModel.ManufacturerId = good.ManufacturerId;
            goodViewModel.Amount         = good.Amount;
            goodViewModel.TypeId         = good.TypeId;
            goodViewModel.Description    = good.Description;
            goodViewModel.ManufacturerVM = _manufacturerRepository.Get();
            goodViewModel.TypeVM         = _typeRepository.Get();

            return(View(goodViewModel));
        }
        public void Get()
        {
            //Act
            var result = repository.Get(id);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Type));
            Assert.AreEqual(id, result.ID);
        }
コード例 #3
0
        public void Serialize(object value)
        {
            if (value == null)
            {
                return;
            }

            var info = TypeRepository.Get(value.GetType());

            if (info.IsSimple)
            {
                Pack(value);
                return;
            }

            if (info.IsArray)
            {
                var array = (IList)value;
                Pack(array.Count);
                foreach (var item in array)
                {
                    Serialize(item);
                }
                return;
            }

            if (info.IsChild)
            {
                Pack(info.Discriminator.Value);
            }

            var accessor = info.GetAccessor(value);

            var flags = 0u;
            var i     = 1u;

            foreach (var f in info.Fields)
            {
                var x = accessor.Get(f.Index);
                if (x != null)
                {
                    flags |= i;
                }
                i <<= 1;
            }
            Pack(flags);

            foreach (var f in info.Fields)
            {
                var x = accessor.Get(f.Index);
                Serialize(x);
            }
        }
コード例 #4
0
ファイル: Unit.cs プロジェクト: tppApe/UfcppSample
        public override RecordTypeInfo GetType(int discriminator)
        {
            switch ((UnitType)discriminator)
            {
            case UnitType.Fighter: return(TypeRepository.Get(typeof(Fighter)));

            case UnitType.Mage: return(TypeRepository.Get(typeof(Mage)));

            case UnitType.Thief: return(TypeRepository.Get(typeof(Thief)));

            default: return(null);    // throw
            }
        }
コード例 #5
0
ファイル: MySerializer.cs プロジェクト: tppApe/UfcppSample
        public void Serialize(object value)
        {
            if (value == null)
            {
                return;
            }

            var info = TypeRepository.Get(value.GetType());

            if (info.IsSimple)
            {
                _s.WriteLine(value.ToString());
                return;
            }

            if (info.IsArray)
            {
                var array = (IList)value;
                _s.WriteLine(array.Count);
                foreach (var item in array)
                {
                    Serialize(item);
                }
                return;
            }

            if (info.IsChild)
            {
                _s.WriteLine(info.Discriminator.Value);
            }

            var accessor = info.GetAccessor(value);

            foreach (var f in info.Fields)
            {
                _s.WriteLine(f.Name);

                var x = accessor.Get(f.Index);
                Serialize(x);
            }
        }
コード例 #6
0
 public IEnumerable <EntityType> Get() => _repository.Get();
コード例 #7
0
        public void GetType_InexistentType_ShouldReturnNull()
        {
            Type typeById = typeRepositoryInMemory.Get(brokenContainer.Id);

            Assert.IsNull(typeById);
        }
コード例 #8
0
        public object Deserialize(Type t)
        {
            if (t.IsPrimitive)
            {
                if (t == typeof(int))
                {
                    return((int)UnpackNumber());
                }
                if (t == typeof(double))
                {
                    return((double)UnpackNumber());
                }
                if (t == typeof(bool))
                {
                    return((bool)UnpackNumber());
                }
                if (t == typeof(long))
                {
                    return((long)UnpackNumber());
                }
                if (t == typeof(byte))
                {
                    return((byte)UnpackNumber());
                }
                if (t == typeof(sbyte))
                {
                    return((sbyte)UnpackNumber());
                }
                if (t == typeof(short))
                {
                    return((short)UnpackNumber());
                }
                if (t == typeof(ushort))
                {
                    return((ushort)UnpackNumber());
                }
                if (t == typeof(uint))
                {
                    return((uint)UnpackNumber());
                }
                if (t == typeof(ulong))
                {
                    return((ulong)UnpackNumber());
                }
                if (t == typeof(float))
                {
                    return((float)UnpackNumber());
                }
            }
            else if (t == typeof(string))
            {
                return(UnpackString());
            }

            var info = TypeRepository.Get(t);

            if (info.IsArray)
            {
                var length = (int)UnpackNumber();
                var array  = info.GetArray(length);
                var elem   = ((ArrayTypeInfo)info).ElementType.Type;

                for (int i = 0; i < length; i++)
                {
                    var item = Deserialize(elem);
                    array.SetValue(item, i);
                }
                return(array);
            }

            if (info.IsBase)
            {
                var discriminator = (int)UnpackNumber();
                info = info.GetType(discriminator);
            }

            var value    = info.GetInstance();
            var accessor = info.GetAccessor(value);
            var count    = info.Fields.Count();

            var flags = (uint)UnpackNumber();

            foreach (var field in info.Fields)
            {
                if ((flags & 1) == 0)
                {
                    continue;
                }

                flags >>= 1;

                var x = Deserialize(field.Type.Type);
                accessor.Set(field.Index, x);
            }

            return(value);
        }
コード例 #9
0
ファイル: MySerializer.cs プロジェクト: tppApe/UfcppSample
        public object Deserialize(Type t)
        {
            if (t == typeof(int))
            {
                return(int.Parse(_s.ReadLine()));
            }
            if (t == typeof(double))
            {
                return(double.Parse(_s.ReadLine()));
            }
            if (t == typeof(string))
            {
                return(_s.ReadLine());
            }

            var info = TypeRepository.Get(t);

            if (info.IsArray)
            {
                var length = int.Parse(_s.ReadLine());
                var array  = info.GetArray(length);
                var elem   = ((ArrayTypeInfo)info).ElementType.Type;

                for (int i = 0; i < length; i++)
                {
                    var item = Deserialize(elem);
                    array.SetValue(item, i);
                }
                return(array);
            }

            if (info.IsBase)
            {
                var line          = _s.ReadLine();
                var discriminator = int.Parse(line);
                info = info.GetType(discriminator);
            }

            var value    = info.GetInstance();
            var accessor = info.GetAccessor(value);
            var count    = info.Fields.Count();

            while (true)
            {
                var line = _s.ReadLine();
                if (line == null)
                {
                    break;
                }

                var field = info.Fields.First(f => f.Name == line);
                var x     = Deserialize(field.Type.Type);
                accessor.Set(field.Index, x);

                --count;
                if (count == 0)
                {
                    break;
                }
            }

            return(value);
        }