public void an_adult_has_everything_a_person_has_plus_walking_and_talking() { Adult adult = new Adult(); Baby baby = new Baby(); IList<Person> people = new List<Person> { adult, baby }; // note: both the baby and adult can eat foreach (var person in people) { person.Eat(); } // note: only the adult can walk which will set has walked to true adult.Walk(); adult.HasWalked.ShouldBe(_); // note: because the baby inherits person we can still access HasWalked baby.HasWalked.ShouldBe(_); // note: both the baby and adult have eaten adult.HasEaten.ShouldBe(_); baby.HasEaten.ShouldBe(_); }
public IActionResult Edit(Baby baby) { this.dbContext.Babies.Update(baby); this.dbContext.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public IActionResult Create(Baby baby) { this.dbContext.Babies.Add(baby); this.dbContext.SaveChanges(); return(RedirectToAction("Index")); }
private void ManageBirds(ref float time, ref float deltaTime) { bool motherIsMoving = mother.IsMoving; for (int i = 0; i < babies.Length; i++) { Baby baby = babies[i]; if (baby.IsFrightened) { baby.FrightendRoutine(ref deltaTime); } else { if (motherIsMoving) { //The split is weird, also weird method names baby.CheckForKinDistance(ref deltaTime); baby.GoTowardsKin(ref deltaTime); } else { baby.IdleRoutine(ref time, ref deltaTime); } } } }
public void SpawnFirstBaby() { Baby newBaby = PoolManager.instance.ReuseObject(babyPrefab, wokPan.transform.position + new Vector3(0, .5f, 0), Quaternion.identity).GetComponent <Baby>(); AliveBabies.Add(newBaby); UpdateBabyCount(); }
public async Task<IActionResult> PregnantForm(string code) { var form = await _context.PregnantForm.SingleAsync(x => x.Code.Equals(code)); Baby baby = null; if (form.PatientBabyId != null) baby = await _context.Baby.SingleOrDefaultAsync(x => x.BabyId.Equals(form.PatientBabyId)); var pregnantForm = new PregnantViewModel(form, baby); var tracking = _context.Tracking.Single(x => x.Code.Equals(code)); var activity = _context.Activity.Single(x => x.Code.Equals(code) && x.Status.Equals(_status.Value.REFERRED)); if (!activity.Status.Equals(_status.Value.REFERRED)) activity.Status = _status.Value.REFERRED; tracking.DateSeen = DateTime.Now; activity.DateSeen = DateTime.Now; _context.Update(tracking); _context.Update(activity); var seen = new Seen { FacilityId = UserFacility(), TrackingId = _context.Tracking.Single(x => x.Code.Equals(form.Code)).Id, UpdatedAt = DateTime.Now, CreatedAt = DateTime.Now, UserMd = UserId() }; await _context.AddAsync(seen); await _context.SaveChangesAsync(); return PartialView(pregnantForm); }
private void OnClickRecycle(ButtonScript obj, object args, int param1, int param2) { if (GamePlayer.Instance.BattleBaby == null) { PopText.Instance.Show(LanguageManager.instance.GetValue("NoBabyRecall")); return; } if (AttaclEvent.getInstance.BabyEvent != null) { AttaclEvent.getInstance.BabyEvent(GamePlayer.Instance.BattleBaby.InstId); } BattleActor babyInBattle = Battle.Instance.GetActorByInstId(GamePlayer.Instance.BattleBaby.InstId); if (babyInBattle.isDead == false) { Baby baby = new Baby(); baby.Resize(); baby.InstId = babyInBattle.InstId; baby.SetIprop(PropertyType.PT_TableId, babyInBattle.battlePlayer.tableId_); baby.SetIprop(PropertyType.PT_Level, babyInBattle.battlePlayer.level_); baby.SetIprop(PropertyType.PT_HpCurr, babyInBattle.battlePlayer.hpCrt_); baby.SetIprop(PropertyType.PT_MpCurr, babyInBattle.battlePlayer.mpCrt_); baby.SetIprop(PropertyType.PT_HpMax, babyInBattle.battlePlayer.hpMax_); baby.SetIprop(PropertyType.PT_MpMax, babyInBattle.battlePlayer.mpMax_); displayList_.Add(baby); } AttaclPanel.Instance.CloseBabyWindow(); }
public IActionResult BadSubmit(Baby baby) { return(View(new BabyViewModel() { Baby = baby, })); }
public IActionResult Delete(Baby baby) { this.dbContext.Babies.Remove(baby); this.dbContext.SaveChanges(); return(RedirectToAction("Index")); }
private DateTime CalcMinMaxEventDate(Baby baby, char[] eventTypes, bool min) { IQueryable <Event> events; if (min) { events = (from Event evt in Events where ((evt.BabyId == baby.Id) && (eventTypes.Contains(evt.Type))) orderby evt.StartDate ascending select evt); } else { events = (from Event evt in Events where ((evt.BabyId == baby.Id) && (eventTypes.Contains(evt.Type))) orderby evt.StartDate descending select evt); } foreach (Event evt in events) { return(evt.StartDate); } return(new DateTime()); }
public void HandleEditBabyEvent(int eventId) { _event = _dataService.GetEventById(eventId); _baby = _dataService.GetBabyById(_event.BabyId); Title = _baby.Name + "'s event"; InitWizard("edit event"); }
public async Task <IActionResult> PutBaby(long id, Baby baby) { if (id != baby.Id) { return(BadRequest()); } _context.Entry(baby).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BabyExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IHttpActionResult> PostBaby(Baby baby) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (baby.ImageArray != null && baby.ImageArray.Length > 0) { var stream = new MemoryStream(baby.ImageArray); var guid = Guid.NewGuid().ToString(); var file = $"{guid}.jpg"; var folder = "~/Content/Babies"; var fullPath = $"{folder}/{file}"; var response = FilesHelper.UploadPhoto(stream, folder, file); if (response) { baby.ImagePath = fullPath; } } db.Babies.Add(baby); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = baby.BabyId }, baby)); }
public static SleepActivityViewModel AsViewModel(this SleepActivity model, Baby baby = null) { if (model == null) { return(null); } var startDate = model.StartTime.ToLocalTime(); return(new SleepActivityViewModel { Id = model.Id, StartDate = startDate, StartTime = startDate.TimeOfDay, EndTime = model.EndTime.HasValue ? model.EndTime.Value.ToLocalTime() : (DateTimeOffset?)null, Duration = model.EndTime.HasValue ? model.EndTime.Value - model.StartTime : DateTimeOffset.Now - model.StartTime, Notes = model.Notes, HowBabyFelt = (Feeling?)model.HowBabyFelt, HowParentFelt = (Feeling?)model.HowParentFelt, Baby = baby != null?baby.AsViewModel() : new BabyViewModel { Id = model.BabyId } }); }
public async Task <ApiResult <string> > ModifyAsync(EditBabyViewModel parm) { var res = new ApiResult <string>(); try { int user_id = Config.userid(); Baby baby = parm as Baby; baby.updatedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //更新宝宝信息 await Db.Updateable(baby).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); //更新用户级联表 await Db.Updateable <BabyUser>().SetColumns(it => new BabyUser() { identity = parm.identity }) .Where(it => it.baby_id == parm.id && it.user_id == user_id).ExecuteCommandAsync(); } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error + ex.Message; } return(res); }
public async Task <ApiResult <string> > AddAsync(EditBabyViewModel parm) { var res = new ApiResult <string>(); try { int user_id = Config.userid(); Baby baby = parm as Baby; baby.founder_id = user_id; baby.createdOn = baby.updatedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); baby.avatar_url = string.IsNullOrEmpty(baby.avatar_url) ? "uploads/default_baby-avatar.png" : baby.avatar_url; baby = await Db.Insertable(baby).ExecuteReturnEntityAsync();//插入宝宝表,返回实体 var link = new BabyUser { baby_id = baby.id, user_id = user_id, identity = parm.identity, createdOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; await Db.Insertable(link).ExecuteCommandAsync();//插入宝宝-用户关联表 } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error + ex.Message; } return(res); }
void SetBabyData(Baby ba) { BabyData bdata = BabyData.GetData(ba.GetIprop(PropertyType.PT_TableId)); gongjiLable.text = ba.GetIprop(PropertyType.PT_Attack).ToString(); fangyuLable.text = ba.GetIprop(PropertyType.PT_Defense).ToString(); minjieLable.text = ba.GetIprop(PropertyType.PT_Agile).ToString(); jingshenLable.text = ba.GetIprop(PropertyType.PT_Spirit).ToString(); huifuLable.text = ba.GetIprop(PropertyType.PT_Reply).ToString(); bishaLable.text = ba.GetIprop(PropertyType.PT_Crit).ToString(); mingzhongLable.text = ba.GetIprop(PropertyType.PT_Hit).ToString(); fanjiLable.text = ba.GetIprop(PropertyType.PT_counterpunch).ToString(); shanduoLable.text = ba.GetIprop(PropertyType.PT_Dodge).ToString(); jinengLable.text = bdata._SkillNum.ToString(); babysuo.SetActive(ba.GetInst().isLock_); instId = ba.InstId; HeadIconLoader.Instance.LoadIcon(EntityAssetsData.GetData(BabyData.GetData(ba.GetIprop(PropertyType.PT_TableId))._AssetsID).assetsIocn_, babyIcon); //iconkuang.spriteName = BabyData.GetPetQuality(bdata._PetQuality); int Magic = bdata._BIG_Magic - ba.gear_[(int)BabyInitGear.BIG_Magic]; int Stama = bdata._BIG_Stama - ba.gear_[(int)BabyInitGear.BIG_Stama]; int Speed = bdata._BIG_Speed - ba.gear_[(int)BabyInitGear.BIG_Speed]; int Power = bdata._BIG_Power - ba.gear_[(int)BabyInitGear.BIG_Power]; int Strength = bdata._BIG_Strength - ba.gear_[(int)BabyInitGear.BIG_Strength]; int num = Magic + Stama + Speed + Power + Strength; pinjiSp.spriteName = BabyData.GetBabyLeveSp(num); }
void RefreshGrowingUp(int uid) { if (GamePlayer.Instance.babies_list_.Count == 0) { ClearText(); } else { enterBtn.isEnabled = true; Uid = uid; Inst = GamePlayer.Instance.GetBabyInst(uid); BabyData bdata = BabyData.GetData(Inst.GetIprop(PropertyType.PT_TableId)); mofaLabel.text = "[-][666666]" + Inst.gear_[(int)BabyInitGear.BIG_Magic].ToString() + "/" + bdata._BIG_Magic; tiliLabel.text = "[-][666666]" + Inst.gear_[(int)BabyInitGear.BIG_Stama].ToString() + "/" + bdata._BIG_Stama; suduLabel.text = "[-][666666]" + Inst.gear_[(int)BabyInitGear.BIG_Speed].ToString() + "/" + bdata._BIG_Speed; qiangduLabel.text = "[-][666666]" + Inst.gear_[(int)BabyInitGear.BIG_Power].ToString() + "/" + bdata._BIG_Power; liLiangLabel.text = "[-][666666]" + Inst.gear_[(int)BabyInitGear.BIG_Strength].ToString() + "/" + bdata._BIG_Strength; type = bdata._Tpye; tiliSlider.value = (Inst.gear_[(int)BabyInitGear.BIG_Stama] * 1f) / (bdata._BIG_Stama * 1f); liliangSlider.value = (Inst.gear_[(int)BabyInitGear.BIG_Strength] * 1f) / (bdata._BIG_Strength * 1f); qiangduSlider.value = (Inst.gear_[(int)BabyInitGear.BIG_Power] * 1f) / (bdata._BIG_Power * 1f); suduSlider.value = (Inst.gear_[(int)BabyInitGear.BIG_Speed] * 1f) / (bdata._BIG_Speed * 1f); mofaSlider.value = (Inst.gear_[(int)BabyInitGear.BIG_Magic] * 1f) / (bdata._BIG_Magic * 1f); int dd = Inst.gear_[(int)BabyInitGear.BIG_Magic] + Inst.gear_[(int)BabyInitGear.BIG_Stama] + Inst.gear_[(int)BabyInitGear.BIG_Speed] + Inst.gear_[(int)BabyInitGear.BIG_Power] + Inst.gear_[(int)BabyInitGear.BIG_Strength]; dangshuLable.text = dd.ToString(); } }
public void Update() { if (CharacterController.INSTANCE.resting) { return; } if (transform.position.y < -50f) { GameObject.Destroy(gameObject); return; } //kill if they fly too high if (rb.velocity.y > 0 && transform.position.y > 3.5f) { if (!dead) { sfx.pitch = .75f + (float)(rand.NextDouble() * .6f); sfx.PlayOneShot(deathSound); } hp = 0; dead = true; bc.enabled = false; anim.enabled = false; rb.gravityScale = 3; } Vector2 origin = bc.bounds.center - (Vector3.up * (bc.bounds.size.y / 2)); isGrounded = Physics2D.OverlapCircle(origin, 0.05f, groundLayer); if (rb.velocity.magnitude < .05f) { anim.SetBool("Running", false); } if (target != null && !target.parent.isBehindObject /*&& sr.flipX == !target.parent.sr.flipX*/) { if (isGrounded) { ChaseTarget(); } } else { if (target == null) { target = GameObject.FindObjectOfType <Baby>(); } if (Time.time > wanderTimer) { wanderTimer = Time.time + wanderInterval; Wander(); anim.SetBool("Attacking", false); } } }
public void HandleNewBabyEvent(int babyId) { _event = null; _baby = _dataService.GetBabyById(babyId); Title = _baby.Name + "'s event"; InitWizard("new event"); }
public async Task <Baby> CreateBaby(PostBabyDTO baby, string userId) { if (baby == null) { throw new ArgumentNullException(nameof(baby)); } var users = unitOfWork.Users.GetAll(); var user = users.FirstOrDefault( user => user.Id == userId); var newBaby = new Baby() { Name = baby.Name, BloodType = baby.BloodType, Allergies = baby.Allergies, Notes = baby.Notes, GenderType = (GenderType)Enum.Parse(typeof(GenderType), baby.GenderType) }; if (user != null) { newBaby.UserId = user.Id; newBaby.User = user; unitOfWork.Babies.Create(newBaby); await unitOfWork.SaveChangesAsync(); return(newBaby); } return(null); }
public void SetData(COM_SellItem sellItem) { sellItem_ = sellItem; ItemData idata = null; BabyData bData = null; if (sellItem.item_.itemId_ != 0) { idata = ItemData.GetData((int)sellItem.item_.itemId_); name_.text = idata.name_; ItemCellUI icell = UIManager.Instance.AddItemInstCellUI(icon_, sellItem_.item_); if (icell == null) { return; } icell.ItemCount = (int)sellItem.item_.stack_; icell.showTips = true; } else { bData = BabyData.GetData((int)sellItem.baby_.properties_[(int)PropertyType.PT_TableId]); name_.text = bData._Name; Baby baby = new Baby(); baby.SetBaby(sellItem.baby_); BabyCellUI cell = UIManager.Instance.AddBabyCellUI(icon_, baby); UIManager.SetButtonEventHandler(cell.gameObject, EnumButtonEvent.OnClick, OnClickIcon, 0, 0); } price_.text = sellItem_.sellPrice.ToString(); }
void Awake() { m_transform = this.transform; m_ani = this.GetComponent <Animator>(); m_player = GameObject.FindGameObjectWithTag(TagName).GetComponent <Baby>(); m_agent = this.GetComponent <NavMeshAgent>(); }
void Start() { // 상속 Adult john = new Adult("john", 28, 173); Baby lisa = new Baby("lisa", 3, 95); Debug.Log(john.age); lisa.Sleep(); // base 키워드 Adult maria = new Adult("maria", 10, 12); maria.Age = 1; maria.SetBaseAge(2); Debug.Log(maria.Age); Debug.Log(maria.GetBaseAge()); // 메서드 오버라이드 Human sujin = new Human("sujin", 12, 147); Baby jake = new Baby("jake", 3, 62); Human chris = new Baby("chris", 6, 110); sujin.Walk(); jake.Walk(); chris.Walk(); }
private void buttonClick(ButtonScript obj, object args, int param1, int param2) { Baby b = null; b = GamePlayer.Instance.GetBabyInst(param1); if (b != null) { if (BankSystem.instance.IsBabyStorageFull()) { PopText.Instance.Show(LanguageManager.instance.GetValue("cankuman")); return; } if (b.isForBattle_) { PopText.Instance.Show(LanguageManager.instance.GetValue("chuzhan")); return; } if (b.GetInst().isShow_) { PopText.Instance.Show(LanguageManager.instance.GetValue("showbaby")); return; } StorageBabyCell bCell = obj.GetComponentInParent <StorageBabyCell> (); sDouble = false; StartCoroutine(DelayOnesortClick(bCell)); } }
static void Main(string[] args) { var baby = new Baby() .SetFirstName("Allie") .SetLastName("Tam") .SetGender(Gender.Girl) .SetBod(new DateTime(2019, 08, 20)); try { var contraction = 0; while (contraction < 10) { Console.WriteLine($"Wife screaming {contraction}..."); System.Threading.Thread.Sleep(500); contraction++; } Console.WriteLine(""); Console.WriteLine("\"Hello World!\""); Console.WriteLine($"My name is {baby.FirstName} {baby.LastName}"); Console.WriteLine($"I am a {baby.Sex}."); Console.WriteLine($"My Birthday is {baby.Bod.ToString("dd-MM-yyyy")}."); } catch (Exception e) { Console.WriteLine(e.Message); } finally { // add these two line to keep the console window open Console.WriteLine("Press enter to close..."); Console.ReadLine(); } }
// PUT api/<controller>/5 /// <summary> /// Update baby /// </summary> /// <remarks> /// Associated User or Admin user can update baby, but not the id. /// </remarks> /// <param name="id"></param> /// <param name="baby"></param> /// <exception cref="HttpResponseException"></exception> public async Task <Dictionary <string, object> > Put(string id, [FromBody] Baby baby) { var currentUser = await _authController.GetVerifiedUser(Request.Headers.Authorization); if (currentUser == null) { throw new HttpResponseException(HttpStatusCode.Unauthorized); } var userBabies = _dataHelpers.BabiesForUserAndRole(currentUser); var currentBaby = userBabies.FirstOrDefault(x => x.Id == id); if (currentBaby == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (baby.DateOfBirth != currentBaby.DateOfBirth) { //todo: add functionality to update birth memory if dob changes. } if (currentUser.Role != BabyMemoryConstants.AdminUserRole || baby.UserId.IsNullOrWhiteSpace()) { baby.UserId = currentBaby.UserId; } baby.Id = id; _context.Save <Baby>(baby); return(ResponseDictionary(baby)); }
public void NullCheck() { if (level == null) { level = GameObject.Find("Level").GetComponent <Level>(); } if (player == null) { player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>(); } if (baby == null) { baby = GameObject.FindGameObjectWithTag("Baby").GetComponent <Baby>(); } if (playerWinPanel == null) { playerWinPanel = GameObject.Find("PlayerWinPanel"); } if (babyWinPanel == null) { babyWinPanel = GameObject.Find("BabyWinPanel"); } if (replayButton == null) { replayButton = GameObject.Find("ReplayButton"); } if (mainmenuButton == null) { mainmenuButton = GameObject.Find("MainMenuButton"); } }
private Dictionary <string, object> ResponseDictionary(Baby baby) { Dictionary <string, object> metadata = new Dictionary <string, object>(); metadata.Add("baby", baby); metadata.Add("url", Url.Route("DefaultApi", new { controller = "babies", id = baby.Id })); var user = _context.Load <User>(baby.UserId); if (user != null) { metadata.Add("user_url", Url.Route("DefaultApi", new { controller = "user", id = user.Id })); } var memories = _context.Query <Memory>(baby.Id, new DynamoDBOperationConfig { IndexName = "BabyIdIndex" }); if (memories != null && memories.Any()) { metadata.Add("memory_url", Url.Route("DefaultApi", new { controller = "memories", baby = baby.Id })); } return(metadata); }
public async Task CreateBaby(Baby baby) { using (IDbConnection db = new SqlConnection(_connectionString)) { await db.ExecuteAsync(CreateBabyStatement(baby)); } }
private async void LoadBaby() { try { Baby baby = await this.BabyInfoViewModel.GetBaby(); if (baby == null) { return; } this.nameEntry.Text = baby.Name; if (!string.IsNullOrEmpty(baby.BirthDate)) { this.birthDatePicker.Date = Convert.ToDateTime(baby.BirthDate); } if (!string.IsNullOrEmpty(baby.BirthTime)) { this.birthTimePicker.Time = TimeSpan.Parse(baby.BirthTime); } this.weightEntry.Text = baby.Weight; this.heightEntry.Text = baby.Height; this.maternityHospitalEntry.Text = baby.MaternityHospital; this.bloodTypePCK.SelectedItem = baby.BloodType; } catch (Exception exp) { await DisplayAlert("Ops", exp.Message, "OK"); } }
void Awake() { baby = GetComponentInChildren<Baby>(); menuItem = GetComponentInChildren<Pushable>(); SetSelected(false); priceText.text = "" + Price; priceText_shadow.text = "" + Price; }
static void Main(string[] args) { Human mammal = new Baby(); mammal.Move(10); for (int i = 0; i < 50; i++) { mammal.GetOlder(); } }
public Baby CreateBaby(Person person1, Person person2) { var bioEngine = new BioEngine(); bioEngine.EnsureReproducibility(person1, person2); var splicedDNA = bioEngine.SpliceDNA(person1.DNA, person2.DNA); var baby = new Baby() { Age = 0, DNA = splicedDNA, Gender = BioEngine.GetRandomGender(), }; return baby; }
static void Main(string[] args) { Console.WriteLine("Hello,C#!"); //value and reference //srtuct pass value Coordinate location; location.x = 10; location.y = 10; AttempTomodifyCoord(location); Console.WriteLine("({0},{1})",location.x,location.y); ModifyCoord(ref location); Console.WriteLine("({0},{1})", location.x, location.y); //object pass reference CoordinateClass newlocation=new CoordinateClass(); newlocation.x = 10; newlocation.y = 10; AttempTomodifyNewCoord(newlocation); Console.WriteLine("({0},{1})", newlocation.x, newlocation.y); ModifyNewCoord(ref newlocation); Console.WriteLine("({0},{1})", newlocation.x, newlocation.y); //enum Days meetingDay = Days.Tuesday | Days.Thursday; Console.WriteLine(meetingDay.ToString()); //装箱转换 ///当值类型被作为引用类型的参数传给方法或者赋值给一个引用类型参数时,堆上将创建一个复制值到值字段的对象 int personID = 111; object boxID = personID; personID = 222; int unboxID = (int)boxID; Console.WriteLine(personID.ToString()); Console.WriteLine(unboxID.ToString()); ///foreach循环中无法改变集合对象,会直接编译器报错 /// 在Java中亦是,只是不会编译报错 String[] stringArray = new String[5]; for (int i=0;i<stringArray.Length;i++) { stringArray[i] = i.ToString(); Console.WriteLine(stringArray[i]); } foreach (String s in stringArray) { ;/// s = "hh";///语法报错 } //C#3.0初始化器 //class成员变量的set get写法 Person person = new Person(); person.id = 2; person.name = "hh"; Console.WriteLine(person.name); //等同于使用初始化器如下 Person person2 = new Person { id = 2, name = "hh" }; Console.WriteLine(person2.name); //as和is操作符 //is只是返bool变量表示是否可以转换成给定类型 //as操作则直接将其转换成给定类型,若失败则返回null //这里说的转换可能是引用转换,也可能是装箱或拆箱操作 Student student = new Student { id=2,name="hhh",school="ss"}; student.school = "Nanjing University"; Console.WriteLine("student {0} a person",student is Person?"is":"is not"); Console.WriteLine("{0}",student.school); Person personFromStudent = student as Person; if (personFromStudent!=null) { Console.WriteLine(personFromStudent.ToString()); } //此时观察personFromStudent的属性,已经没有school这一项了,说明as操作同时进行了类型转换装箱操作 //Console.WriteLine("personFromStudent {0} a Student", personFromStudent is Student?"is":"is not"); //Babe类用于演示C#6.0自动实现属性的初始化器 Baby babe1 = new Baby { name="sss"}; Console.WriteLine(babe1.bornTime); }
public void InheritFrom() { using (var container = new RhetosTestContainer()) { Parent pReadAllow = new Parent() { ID = Guid.NewGuid(), value = 190 }, pReadDeny = new Parent() { ID = Guid.NewGuid(), value = 90 }, pWriteAllow = new Parent() { ID = Guid.NewGuid(), value = 60 }, pWriteDeny = new Parent() { ID = Guid.NewGuid(), value = 160 }; Child cParentReadAllow = new Child() { ID = Guid.NewGuid(), MyParentID = pReadAllow.ID, value = 5 }, cParentReadDeny = new Child() { ID = Guid.NewGuid(), MyParentID = pReadDeny.ID, value = 6 }, cParentWriteAllow = new Child() { ID = Guid.NewGuid(), MyParentID = pWriteAllow.ID, value = 7 }, cParentWriteDeny = new Child() { ID = Guid.NewGuid(), MyParentID = pWriteDeny.ID, value = 8 }; var repositories = container.Resolve<Common.DomRepository>(); var parentRepo = repositories.TestRowPermissions.Parent; var childRepo = repositories.TestRowPermissions.Child; var babyRepo = repositories.TestRowPermissions.Baby; var browseRepo = repositories.TestRowPermissions.ParentBrowse; babyRepo.Delete(babyRepo.All()); childRepo.Delete(childRepo.All()); parentRepo.Delete(parentRepo.All()); parentRepo.Insert(new Parent[] { pReadAllow, pReadDeny, pWriteAllow, pWriteDeny }); childRepo.Insert(new Child[] { cParentReadAllow, cParentReadDeny, cParentWriteAllow, cParentWriteDeny }); { var childAllowRead = childRepo.Filter(childRepo.Query(), new Common.RowPermissionsReadItems()).ToList(); Assert.AreEqual("5, 8", TestUtility.DumpSorted(childAllowRead, a => a.value.ToString())); } { var childAllowWrite = childRepo.Filter(childRepo.Query(), new Common.RowPermissionsWriteItems()).ToList(); Assert.AreEqual("6, 7", TestUtility.DumpSorted(childAllowWrite, a => a.value.ToString())); } // Test combination with rule on child Child cCombo = new Child() { ID = Guid.NewGuid(), MyParentID = pReadAllow.ID, value = 3 }; childRepo.Insert(new Child[] { cCombo }); { var childAllowRead = childRepo.Filter(childRepo.Query(), new Common.RowPermissionsReadItems()).ToList(); Assert.IsTrue(!childAllowRead.Select(a => a.value).Contains(3)); } // Test double inheritance, only write deny case Baby bDenyWrite = new Baby() { ID = Guid.NewGuid(), MyParentID = cParentWriteDeny.ID }; babyRepo.Insert(new Baby[] { bDenyWrite }); { Assert.AreEqual(1, babyRepo.Query().Count()); var babyDenyWrite = babyRepo.Filter(babyRepo.Query(), new Common.RowPermissionsWriteItems()).ToList(); Assert.AreEqual(0, babyDenyWrite.Count()); } // Test inheritance form base data structure { var allowedRead = browseRepo.Filter(browseRepo.Query(), new Common.RowPermissionsReadItems()).ToList(); Assert.AreEqual("160, 190", TestUtility.DumpSorted(allowedRead, item => item.Value2)); var allowedWrite = browseRepo.Filter(browseRepo.Query(), new Common.RowPermissionsWriteItems()).ToList(); Assert.AreEqual("60, 90", TestUtility.DumpSorted(allowedWrite, item => item.Value2)); } } }
public void LinkBaby(Baby _baby, bool _bSuccess) { m_linkedBaby = _baby; m_success = _bSuccess; m_bBabyAte = false; }
void Update() { if(m_bMoving) { float fPerc = Mathf.Min (1.0f, (Time.time - m_timeStart) / m_duration); transform.position = Vector3.Lerp(m_initPos, m_dest, fPerc); if(fPerc >= 1.0f) { m_bMoving = false; } } if(m_linkedBaby != null) { if(!m_bBabyAte) { if(!m_linkedBaby.IsEating()) //Baby just ate { m_bBabyAte = true; MoveTo(Gameplay_Normal.Instance.GetPos_EatOut(), 0.2f); if(m_success) { //Drop prize float fRand = Random.Range(0.0f, 1.0f); float fProb = Gameplay_Normal.Instance.GetBabyData(m_linkedBaby.baby).GetPrizeProbability() * (Gameplay_Normal.Instance.IsPrizeSeasonActive() ? 2.0f : 1.0f); if(fRand <= fProb) { if(BabiesPool.Instance.GetPrize(m_linkedBaby.baby)) { BabiesPool.Instance.GetPrize(m_linkedBaby.baby).Dropped(m_linkedBaby.transform.position); } } } } } else { if(!IsMoving()) //Going Out { transform.localScale = Vector3.one; BabiesPool.Instance.ReturnToPool(m_linkedBaby.transform); CloudPool.Instance.AddObject(transform); m_linkedBaby = null; } } } }