public MapJsonModel Map2JsonModel(Map map) { MapJsonModel mjson = new MapJsonModel(); mjson.GameOverCondition = map.GameOverCondition; mjson.Name = map.Name; mjson.Description = map.Description; mjson.PlayerOwnedChemicalsDescription = SemanticObjectController.GenerateChemicals2Text(map.PlayerOwnedChemicals); foreach (var b in map.Blocks.FindAll(m => m.IsActive)) { BlockJsonModel bbj = new BlockJsonModel(); bbj.StrainsInfo = b.Strains == null ? "" : new StrainController().Strains2Text(b.Strains); // b.Strains = null; bbj.ChemicalNamesInfo = SemanticObjectController.GenerateChemicals2Text(b.PublicChemicals); // b.PublicChemicals = null; bbj.BlockType = b.BlockType; bbj.Capacity = b.Capacity; bbj.HexCoor = ObjectHelper.Clone(b.HexCoor); bbj.IsActive = b.IsActive; bbj.StandardCoor = ObjectHelper.Clone(b.StandardCoor); bbj.TotalPopulation = b.TotalPopulation; mjson.Blocks.Add(bbj); } return(mjson); }
public static List <RegulatoryGene> LoadAllRegulartoryGenes() { var allRegulatoryGeneJson = CellWar.Utils.JsonHelper.Json2Object_NT <List <RegulartoryGeneJsonModel> >(GetGameDataPath("reg_gene.json")); List <RegulatoryGene> regulatoryGenes = new List <RegulatoryGene>(); foreach (var geneJson in allRegulatoryGeneJson) { RegulatoryGene gene = new RegulatoryGene(); gene.Type = geneJson.Type; gene.Name = geneJson.Name; gene.Description = geneJson.Description; gene.Length = geneJson.Length; foreach (var cc in geneJson.Condition) { var ch = ObjectHelper.Clone(FindChemicalByName(cc.Chemical)); if (ch != null) { ch.Count = cc.Count; gene.Conditions.Add(ch); } } regulatoryGenes.Add(gene); } AllRegulartoryGenes = regulatoryGenes; return(regulatoryGenes); }
/// <summary> /// 保存更改 /// </summary> public void Save() { if (NodeList.Count == 0) { throw new BusinessException("至少有一条明细!"); } if (NodeList.ToList().Exists(m => String.IsNullOrEmpty(m.ItemName) || String.IsNullOrEmpty(m.ItemName.Trim()))) { throw new BusinessException(" 清单项名称不能为空!"); } List <ContractBoi> lstAddBoi = null; List <ContractBoi> lstDelBoi = null; List <ContractBoi> lstUpdateBoi = null; List <String> lstDelNo = null; List <ContractBoiNode> lstAllNode = NodeList.ToList(); //添加的节点集合 List <ContractBoiNode> lstAddNode = lstAllNode.FindAll(m => m.OriginalBoi == null); //删除的节点集合 lstDelBoi = boq.BoiList.FindAll(m => !lstAllNode.Exists(n => n.OriginalBoi == m)); if (lstAddNode.Count > 0) { lstAddBoi = lstAddNode.ConvertAll <ContractBoi>(m => ObjectHelper.Clone <ContractBoi>(m)); } if (lstDelBoi.Count > 0) { lstDelNo = lstDelBoi.ConvertAll <String>(m => m.ItemNo); } if (updateList.Count > 0) { lstUpdateBoi = updateList.ConvertAll <ContractBoi>(m => ObjectHelper.Clone <ContractBoi>(m)); } //执行保存操作 List <ContractBoiNoInfo> lstAddedInfo = contractBoqService.Save(ProjectNo, null, Boq.BoQName, ObjectHelper.GetDefaultDecimal(Boq.TotalAmount), lstAddBoi, lstUpdateBoi, lstDelNo); lstAddNode.ForEach(m => { //为新增的项填写ItemNo m.ItemNo = lstAddedInfo.Find(n => n.ItemCode == m.ItemCode).ItemNo; //拷贝Boi对象 ContractBoi boi = ObjectHelper.Clone <ContractBoi>(m); //将Boi对象与节点关联起来 m.OriginalBoi = boi; Boq.BoQNo = m.BoQNo; //加入到原始Boq集合中 Boq.BoiList.Add(boi); }); //从原始集合中移除已删除的对象 lstDelBoi.ForEach(m => { Boq.BoiList.Remove(m); }); //清除变化记录集合 updateList.Clear(); //将编辑状态设置为FALSE this.Editing = false; //重新读取数据 Load(); }
internal SubCategory Clone(Category category) { var subCategory = ObjectHelper.Clone(this); subCategory.Category = category; return(subCategory); }
internal OrderItem Clone(Order order) { var orderItem = ObjectHelper.Clone(this); orderItem.Order = order; return(orderItem); }
internal ProductSize Clone(Product product) { var productSize = ObjectHelper.Clone(this); productSize.Product = product; return(productSize); }
public List <RegulatoryGene> CloneRegGeneList(List <RegulatoryGene> regs) { List <RegulatoryGene> newRegs = new List <RegulatoryGene>(); foreach (var reg in regs) { newRegs.Add(ObjectHelper.Clone(reg, reg.GetType())); } return(newRegs); }
/// <summary> /// 加载所有的race /// geneNameList的规范为 r1;c1;c2;r2;c3;r3;c4 /// reg后的cod会被自动归类到该r的支配基因中,读到下一个reg时停止 /// r1;c1;c2;r2;c3;r3;c4 /// 将会转化为 /// r1 - c1 /// c2 /// /// r2 - c3 /// /// r3 - c4 /// </summary> /// <returns></returns> public static List <Race> LoadAllRaces() { var allRaceJson = CellWar.Utils.JsonHelper.Json2Object_NT <List <RaceJsonModel> >(GetGameDataPath("race.json")); AllRaces = new List <Race>(); foreach (var raceJson in allRaceJson) { if (raceJson.CodingGeneNames == "") { continue; } var geneNameList = raceJson.CodingGeneNames.Split(';'); List <RegulatoryGene> regulatoryGenes = new List <RegulatoryGene>(); RegulatoryGene previousReg = null; foreach (var geneName in geneNameList) { var regGene = AllRegulartoryGenes.Find(m => m.Name == geneName); // 首个名字必须为 reg gene if (regGene == null && previousReg == null) { throw new InvalidOperationException("Invalid GeneNames. you should input a reg gene at first of the string list" + "\n current gene name:" + geneName); } else if (regGene == null && previousReg != null) { // 继续增加该reg下的支配cod var codGene = AllCodingGenes.Find(m => m.Name == geneName); if (codGene != null) { previousReg.DominatedGenes.Add(codGene); } else { throw new InvalidOperationException("No gene named: " + geneName + "\n you should call LoadAllRaces() after LoadAllCodingGenes"); } } else if (regGene != null) { // 开始添加下一个reg previousReg = ObjectHelper.Clone(regGene, regGene.GetType()); regulatoryGenes.Add(previousReg); } } AllRaces.Add(new Race { Name = raceJson.Name, MaxLength = raceJson.MaxLength, RegulatoryGenes = regulatoryGenes }); } return(AllRaces); }
public object Clone() { var user = ObjectHelper.Clone(this); if (Roles != null) user.Roles = Roles .Select(r => (Role) r.Clone()) .ToArray(); return user; }
/// <summary> /// build the init table info. /// </summary> /// <param name="name"></param> /// <param name="fileName"></param> /// <returns></returns> private Table BuildInitTableInfo(string name, string fileName) { var oldTable = (Table)null; mTableStore.Tables.TryGetValue(name, out oldTable); var tableInfo = new Table(); tableInfo.Name = name; if (oldTable != null) { tableInfo.Desc = oldTable.Desc; tableInfo.Classes = oldTable.Classes; } var excelCeils = ExcelHelper.ReadExcel(fileName); for (var columIndex = 0; columIndex < excelCeils.GetLength(1); columIndex++) { var cell = excelCeils[1, columIndex + 1]; var text = cell != null?cell.ToString() : ""; if (string.IsNullOrEmpty(text)) { continue; } var nameText = (excelCeils[2, columIndex + 1] != null) ? excelCeils[2, columIndex + 1].ToString() : ""; var newMember = new Member(text); if (oldTable != null) { var oldMember = oldTable.Members.Find(x => { return(x.Colume == text); }); if (oldMember != null) { newMember = ObjectHelper.Clone(oldMember); } } newMember.Name = nameText.Trim(); newMember.FieldIndex = tableInfo.Members.Count + 1; if (tableInfo.Members.Count == 0) { newMember.Key = true; } tableInfo.Members.Add(newMember); } return(tableInfo); }
void Awake() { if (Local.AllRaces == null) { return; } #region INIT_UIs UIHelper.InitUIList("UI_RaceList", "UI_Ele_Race", Local.AllRaces, (GameObject g, Race obj) => { g.GetComponent <U3D_RaceElement>().Race = obj; g.name = obj.Name; }); GeneController geneController = new GeneController(); List <CodingGene> allCods = ObjectHelper.Clone(Local.AllCodingGenes); geneController.RemoveAllInternalGene(ref allCods); UIHelper.InitUIList("UI_CodList", "UI_Ele_Cod", allCods, (GameObject g, CodingGene obj) => { g.GetComponent <U3D_CodElement>().CodingGene = ObjectHelper.Clone(obj); g.name = obj.Name; }); List <RegulatoryGene> allRegs = ObjectHelper.Clone(Local.AllRegulartoryGenes); geneController.RemoveAllInternalGene(ref allRegs); UIHelper.InitUIList("UI_RegList", "UI_Ele_Reg", allRegs, (GameObject g, RegulatoryGene obj) => { g.GetComponent <U3D_RegElement>().RegulatoryGene = ObjectHelper.Clone(obj, obj.GetType()); g.name = obj.Name; }); UIHelper.InitUIList("UI_LabStrainList", "UI_Ele_LabStrain", Save.Strains, (GameObject g, Strain obj) => { g.GetComponent <U3D_StrainElement>().Strain = obj; g.name = obj.Name; }, ref UIStrainElement); #endregion // 没有Strain实例表示创建新的Strain if (LabCurrent.Strain == null) { // 为新创建的strain实例指定一个默认race // 注,race文件一定不能为空,不然会爆炸 LabCurrent.Strain = new Strain(GameData.Local.AllRaces[0]); } UITextMaxLength = GameObject.Find("UI_MaxLength"); gameObject.SetActive(false); }
public override object Clone() { var parameterClone = (Parameter <T>)Activator.CreateInstance(GetType()); parameterClone.ValueType = ValueType; parameterClone.Unit = Unit; parameterClone.Enabled = Enabled; parameterClone.Description = (Description != null) ? Description.Clone() as string : ""; parameterClone.Name = (Name != null) ? Name.Clone() as string : ""; parameterClone.DefaultValue = ObjectHelper.Clone <T>(DefaultValue); parameterClone.Value = ObjectHelper.Clone <T>(Value); return(parameterClone); }
public object Clone() { var parcel = ObjectHelper.Clone(this); if (Orders != null) { parcel.Orders = Orders .Select(o => o.Clone(parcel)) .ToArray(); } return(parcel); }
public object Clone() { var category = ObjectHelper.Clone(this); if (SubCategories != null) { category.SubCategories = SubCategories .Select(sc => sc.Clone(category)) .ToArray(); } return(category); }
public object Clone() { var product = ObjectHelper.Clone(this); if (ProductSizes != null) { product.ProductSizes = ProductSizes .Select(ps => ps.Clone(product)) .ToArray(); } return(product); }
public Order CloneOrder(Order order) { var clonedOrder = ObjectHelper.Clone(order); //reset the identifiers clonedOrder.Id = 0; clonedOrder.Guid = Guid.NewGuid().ToString(); clonedOrder.CreatedOn = DateTime.UtcNow; clonedOrder.OrderStatus = OrderStatus.New; foreach (var oi in clonedOrder.OrderItems) { oi.Id = 0; } return(clonedOrder); }
internal Order Clone(Parcel parcel) { var order = ObjectHelper.Clone(this); order.Parcel = parcel; if (OrderItems != null) { order.OrderItems = OrderItems .Select(oi => oi.Clone(order)) .ToArray(); } return(order); }
/// <summary> /// 游戏性问题 #22 /// https://github.com/bennycui99/Cellwar.Game/issues/22 /// </summary> public static void TestDeathGeneImportChemical_Usable() { CodingGene g = new CodingGene { Name = "g", ImportChemicalName = "c", ImportChemicalIntercept = 1, ImportChemicalCoeffeicient = 0.01f, }; Chemical c = new Chemical { Name = "c", Count = 10 }; Strain s = new Strain(); s.PrivateChemicals.Add(ObjectHelper.Clone(c)); Block b = new Block(); GameData.Local.AllChemicals = new List <Chemical>(); GameData.Local.AllChemicals.Add(ObjectHelper.Clone(c)); c.Count = 100; b.PublicChemicals.Add(ObjectHelper.Clone(c)); CodingGeneController ctor = new CodingGeneController(); ctor.ImportChemical(ref s, ref b, ref g); // Debug.Log(b.PublicChemicals.Find(cc => cc.Name == "c").Count); Debug.Log(s.PrivateChemicals.Find(cc => cc.Name == "c").Count); Debug.Assert(b.PublicChemicals.Find(cc => cc.Name == "c").Count < 100); // s.PrivateChemicals.Clear(); ctor.ImportChemical(ref s, ref b, ref g); Debug.Log(b.PublicChemicals.Find(cc => cc.Name == "c").Count); Debug.Log(s.PrivateChemicals.Find(cc => cc.Name == "c").Count); Debug.Assert(b.PublicChemicals.Find(cc => cc.Name == "c").Count < 100); GameData.Local.AllChemicals = null; }
public void OnPointerDown( PointerEventData eventData ) { var regs = LabCurrent.Strain.PlayerSelectedGenes; var reg = regs.Find( m => m.Name == RegulatoryGene.Name ); if( Input.GetMouseButtonDown( 0 ) ) { // Left if( reg == null ) { regs.Add( reg = ObjectHelper.Clone( RegulatoryGene, RegulatoryGene.GetType() ) ); } else { regs.Remove( reg ); } SwitchCodingGeneList( reg ); } if( Input.GetMouseButtonDown( 1 ) && GetComponent<Toggle>().isOn ) { // Right SwitchCodingGeneList( reg ); } U3D_LabSceneLoad.FreshLength(); }
public IActionResult SaveEmailMessage(EmailMessageModel model) { var emailMessage = model.Id > 0 ? _emailService.Get(model.Id) : null; if (emailMessage == null) { return(NotFound()); } //clone the message and insert again var newEmailMessage = ObjectHelper.Clone(emailMessage); newEmailMessage.Id = 0; newEmailMessage.EmailBody = model.EmailBody; newEmailMessage.IsSent = false; newEmailMessage.SendingDate = DateTime.UtcNow; _emailService.Queue(newEmailMessage); return(R.Success.Result); }
public void OnPointerClick(PointerEventData eventData) { var dominatedGenes = LabCurrent.RegulatoryGene.DominatedGenes; var cod = dominatedGenes.Find(m => m.Name == CodingGene.Name); if (GetComponent <Toggle>().isOn) { if (cod == null) { dominatedGenes.Add(ObjectHelper.Clone(CodingGene)); } } else { dominatedGenes.Remove(cod); } U3D_LabSceneLoad.FreshLength(); }
public void Clone_Should_Clone_Object() { // Arrange var obj = new TestClass2 { TestProperty1 = 3454, TestProperty2 = new TestClass1() }; // Act var clone = ObjectHelper.Clone(obj); // Assert Assert.AreEqual(obj.TestProperty1, clone.TestProperty1); Assert.IsNotNull(clone.TestProperty2); Assert.AreNotSame(obj.TestProperty2, clone.TestProperty2); Assert.AreEqual(obj.TestProperty3, clone.TestProperty3); Assert.IsNull(clone.TestProperty5); Assert.AreEqual(default(int), clone.TestProperty6); }
/// <summary> /// 将reg-cod规范的字符串转化为reg list对象 /// geneNameList的规范为 r1;c1;c2;r2;c3;r3;c4 /// reg后的cod会被自动归类到该r的支配基因中,读到下一个reg时停止 /// r1;c1;c2;r2;c3;r3;c4 /// 将会转化为 /// r1 - c1 /// c2 /// /// r2 - c3 /// /// r3 - c4 /// </summary> /// <returns></returns> public static List <RegulatoryGene> GenerateText2RegGeneObjects(string geneNames) { var geneNameList = geneNames.Split(';'); List <RegulatoryGene> regulatoryGenes = new List <RegulatoryGene>(); RegulatoryGene previousReg = null; foreach (var geneName in geneNameList) { var regGene = Local.AllRegulartoryGenes.Find(m => m.Name == geneName); // 首个名字必须为 reg gene if (regGene == null && previousReg == null) { throw new InvalidOperationException("Invalid GeneNames. you should input a reg gene at first of the string list" + "\n current gene name:" + geneName); } else if (regGene == null && previousReg != null) { // 继续增加该reg下的支配cod var codGene = Local.AllCodingGenes.Find(m => m.Name == geneName); if (codGene != null) { previousReg.DominatedGenes.Add(codGene); } else { throw new InvalidOperationException("No gene named: " + geneName + "\n you should call LoadAllRaces() after LoadAllCodingGenes"); } } else if (regGene != null) { // 开始添加下一个reg previousReg = ObjectHelper.Clone(regGene, regGene.GetType()); regulatoryGenes.Add(previousReg); } } return(regulatoryGenes); }
/// <summary> /// Syncs property values from working fields to reference fields. /// </summary> public override void Sync() { try { __Version = _Version; __Sheets = ObjectHelper.Clone <EquatableBindingList <Sheet> >(_Sheets, Ssepan.Utility.SerializationFormat.DataContract); //DEBUG:(breaks Dirty flag) //force Dirty to False in sheets Equal comparison base.Sync(); //Note:where we have cloned collections; the collection comparison will never find the orignla items in the cloned collection if it is looking at identity vs content--SJS //if (Dirty) //{ // throw new ApplicationException("Sync failed."); //} } catch (Exception ex) { Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error); throw; } }
protected void Page_Load(object sender, EventArgs e) { popo p1 = new popo() { Bir = DateTime.Now.AddDays(1), Name = "niejunhua", Num = 1, Car = new Car { Name = "is a car" } }; popo p2 = new popo() { Bir = DateTime.Now.AddDays(12), Name = "niejunhua1", Num = 1 }; popo p3 = ObjectHelper.Clone <popo>(p1); Response.Write("y7uanshizhi:" + p1.Name + "," + p1.Car.Name); p1.Car.Name = "ssssssscar"; p1.Name = "jenny"; Response.Write("<br/>复制后:" + p1.Name + "," + p1.Car.Name); //var itemArr = ObjectHelper.Compare<popo>(p1, p2); //foreach (var item in itemArr[0]) //{ // Response.Write(item.Key + " " + item.Value + "<br/>"); //} //Response.Write("new:<br/>"); //foreach (var item in itemArr[1]) //{ // Response.Write(item.Key + " " + item.Value + "<br/>"); //} }
public object Clone() { return(ObjectHelper.Clone(this)); }
private void RoleSelect() { LoginUser tempUser = null; if (AppConfig.CurrentLoginUser != null) { tempUser = ObjectHelper.Clone(AppConfig.CurrentLoginUser); tempUser.LoginOrg = AppConfig.CurrentLoginUser.LoginOrg; //缓存用户的登录机构 } AppConfig.CurrentLoginUser = new LoginUser(LoginInfor.LoginName); if (AppConfig.CurrentLoginUser.RoleCount > 1) { frmSelectRole selectrole = new frmSelectRole(this); if (selectrole.ShowDialog() == DialogResult.Cancel) { if (!IsChangeRoles) { ForceClose(); } else { AppConfig.CurrentLoginUser = tempUser; //还原用户登录机构 return; } } LoadRoleInfo(); } else if (AppConfig.CurrentLoginUser.RoleCount == 1) { if (AppConfig.CurrentLoginUser.LstFGSOrgs.Count > 1 || AppConfig.CurrentLoginUser.LstProject.Count > 1) { frmSelectRole selectrole = new frmSelectRole(this); if (selectrole.ShowDialog() == DialogResult.Cancel) { if (!IsChangeRoles) { ForceClose(); } else { AppConfig.CurrentLoginUser = tempUser; //还原用户登录机构 return; } } } else { string roleStr = ""; switch (AppConfig.CurrentLoginUser.LoginRole) { case AppConfig.ManagerRole.GrpMngr: AppConfig.CurrentLoginUser.LoginOrg = AppConfig.CurrentLoginUser.LstGrpOrgs[0]; roleStr = "业主"; break; case AppConfig.ManagerRole.FGSMngr: AppConfig.CurrentLoginUser.LoginOrg = AppConfig.CurrentLoginUser.LstFGSOrgs[0]; roleStr = "监理"; break; case AppConfig.ManagerRole.XMBMngr: CacheOrg project = new CacheOrg(); roleStr = "标段管理员"; break; } if (AppConfig.CurrentLoginUser.LoginRole == AppConfig.ManagerRole.XMBMngr) { AppConfig.SelectProject = new MeteringPaymentClient().GetIProjectInfoService().GetCurrencyAndExchangeRate(AppConfig.CurrentLoginUser.LstProject[0]); RoleInfo = "当前登录角色:" + AppConfig.SelectProject.ProjectName + "-" + roleStr; } else { RoleInfo = "当前登录角色:" + AppConfig.CurrentLoginUser.LoginOrg.BidName + "-" + roleStr; } } LoadRoleInfo(); } else if (AppConfig.CurrentLoginUser.RoleCount == 0) { XtraMessageBox.Show("无系统权限,请联系管理员"); ForceClose(); } }