public static StructData ParseConfigData(string sConfigData) { int iPos = 0, iPosComment = 0; StructData sd = new StructData(); iPos = sConfigData.IndexOf(';'); if (iPos == -1) { sd.sKey = ""; sd.sValue = sConfigData; sd.sComment = ""; return(sd); } else { iPosComment = sConfigData.IndexOf('|', iPos + 1); sd.sKey = sConfigData.Substring(0, iPos); if (iPosComment == -1) { sd.sValue = sConfigData.Substring(iPos + 1, sConfigData.Length - iPos - 1); sd.sComment = ""; } else { sd.sValue = sConfigData.Substring(iPos + 1, iPosComment - iPos - 1); sd.sComment = sConfigData.Substring(iPosComment + 1, sConfigData.Length - iPosComment - 1); } return(sd); } }
public IData GetData(IData data) { IData result = null; if (Index > -1) { IList ld = data as IList; if (ld != null && Index >= 0 && Index < ld.Count) { result = (IData)ld[Index]; } } if (!string.IsNullOrEmpty(HashKey)) { IDictionary dict = data as IDictionary; if (dict != null && dict.Contains(HashKey)) { result = (IData)dict[HashKey]; } } if (result == null) { StructData structdata = data as StructData; if (structdata != null) { result = structdata[Key]; } } return(result); }
/// <summary> /// 执行数据解析处理 /// </summary> /// <param name="arrMsgRec">接收到的数组</param> /// <param name="length">数组有效长度</param> private void execDataProc(byte[] arrMsgRec, int length) { //if(++recIndex == 20) { // ProcessData(null); // recIndex = 0; //} //return; SerializationUnit seru = new DataDisplay.SerializationUnit(); StructData ms = new StructData(); byte[] destinationArray = new byte[length]; Array.Copy(arrMsgRec, destinationArray, length); List <byte[]> lstrec = execDataStick(destinationArray); foreach (byte[] destinationArr in lstrec) { try { StructData mst = (StructData)seru.DeserializeObject(destinationArr); if (mst.datamain != null) { if (mst.datamain.Length > 0) { //对获取的数据进行逻辑处理 ProcessData(mst); } } } catch (Exception e) { Debug.Write(e.Message); Array.Clear(s2, 0, s2.Length); } } }
public override void Bind(VMBehaviour vm, IData data) { base.Bind(vm, data); if (Source == null) { return; } if (Template == null) { return; } if (data == null) { return; } this.sourceData = Source.GetData(data) as StructData; if (this.sourceData == null) { return; } DoBind(); }
public Entry(string name, Type type, bool readOnly = false, Type enumReturn = null, string valueString = "value", string accessLevel = "public", DataSourceType?dataSourceType = null, string[] extraOnPropertyChanged = null, string dataSourceCustomSorter = "ButtonSorter", bool createPercentField = false, int arrayCount = -1, bool isNullTerminatedString = false, string condition = null, StructData subStruct = null, bool overrideSortIndex = false, bool showAsHex = false) { this.name = name; this.type = type; this.readOnly = readOnly; this.valueString = valueString; this.accessLevel = accessLevel; this.enumReturn = enumReturn; this.dataSourceType = dataSourceType; this.extraOnPropertyChanged = extraOnPropertyChanged; this.dataSourceCustomSorter = dataSourceCustomSorter; this.createPercentField = createPercentField; this.arrayCount = arrayCount; this.isNullTerminatedString = isNullTerminatedString; this.condition = condition; this.subStruct = subStruct; this.overrideSortIndex = overrideSortIndex; this.showAsHex = showAsHex; }
/// <summary> /// 向服务端发送命令 /// </summary> /// <param name="structData"></param> public static void SendCommand(StructData structData) { if (clientSocket != null && clientSocket.Connected) { byte[] sendBytes = seru.SerializeObject(structData); if (sendBytes.Length < 2) { return; } byte[] sendBuf = new byte[sendBytes.Length + 8]; byte[] sendkey1 = System.BitConverter.GetBytes(543215); byte[] sendkey2 = System.BitConverter.GetBytes(567890); try { sendBytes.CopyTo(sendBuf, 4); sendkey1.CopyTo(sendBuf, sendBytes.Length + 4); sendkey2.CopyTo(sendBuf, 0); int n = clientSocket.Send(sendBuf, sendBuf.Length, 0); if (n < 1) { n = clientSocket.Send(sendBuf, sendBuf.Length, 0); } if (n < 1) { n = clientSocket.Send(sendBuf, sendBuf.Length, 0); } } catch (SocketException) { CloseClientSocket(); } catch (ObjectDisposedException) { CloseClientSocket(); } catch { /** 其他非socket异常,不做处理 */ } } }
public void LoadFromFile() { if (!File.Exists(savePath)) { Debug.Log("File not found!"); return; } string json = File.ReadAllText(savePath); try{ StructData DataFromJson = JsonUtility.FromJson <StructData>(json); _enemiesMovementSpeed = DataFromJson._enemiesMovementSpeed2; _movementSpeedHippo = DataFromJson._movementSpeedHippo2; _theNumberOfHitPointsToWin = DataFromJson._theNumberOfHitPointsToWin2; _snowballReloadSpeedHippo = DataFromJson._snowballReloadSpeedHippo2; _periodicityOfEnemyShots = DataFromJson._periodicityOfEnemyShots2; _pointsForHittingTheWeakEnemy = DataFromJson._pointsForHittingTheWeakEnemy2; _pointsForHittingTheMiddleEnemy = DataFromJson._pointsForHittingTheMiddleEnemy2; _pointsForHittingTheStrongEnemy = DataFromJson._pointsForHittingTheStrongEnemy2; EnemiesMovementSpeed.value = DataFromJson._enemiesMovementSpeed2; //Установка UI-компонентам(Slder и Text) параметров считанных из .json MovementSpeedHippo.value = DataFromJson._movementSpeedHippo2; TheNumberOfHitPointsToWin.value = DataFromJson._theNumberOfHitPointsToWin2; SnowballReloadSpeedHippo.value = DataFromJson._snowballReloadSpeedHippo2; PeriodicityOfEnemyShots.value = DataFromJson._periodicityOfEnemyShots2; PointsForHittingTheWeakEnemy.text = DataFromJson._pointsForHittingTheWeakEnemy2.ToString(); PointsForHittingTheMiddleEnemy.text = DataFromJson._pointsForHittingTheMiddleEnemy2.ToString(); PointsForHittingTheStrongEnemy.text = DataFromJson._pointsForHittingTheStrongEnemy2.ToString(); } catch (Exception e) { Debug.Log("Exception: " + e); } }
static void Main(string[] args) { StructData a = new StructData(); a.str = "aaa"; a.p = new byte[1] { 0x0c }; g.str = a.str; g.p = a.p; Console.WriteLine("g.str : " + g.str); Console.WriteLine("a.p : " + a.p[0]); Console.WriteLine("g.p : " + g.p[0]); FuncAAA(a); a.str = "bbb"; a.p[0] = 0xaa; Console.WriteLine("Main call : " + a.str); Console.WriteLine("a.p : " + a.p[0]); Console.WriteLine("g.p : " + g.p[0]); Console.WriteLine("g.str : " + g.str); ///////// Func(a); Console.ReadKey(); }
static void Main(string[] args) { int Numb = 100; // 값형. 이 numb는 스택에 있음. 고로 함수가 종료되는 순간 스택에 있던 값형 자체도 사라지므로 선언된 함수 내에서만 사용 가능. 저 위의 Test함수에서는 사용할 수 없음!!!! // 그런데, 레퍼런스 즉 참조형은 자체는 힙 영역에 있으며, 함수 안에선 그것의 주소를 가르킬 뿐. StructData NewData = new StructData(); // 이게 왜 안돼?? // 아 정말.. 이런것도 안되고.. // --> 이런 마음가짐 x. 마치 한글 문법보고 마음에 안든다고 하는 것과 같은 것. NewData.a = 10; NewData.b = 20; // 참조형(레퍼런스)과 값형이 있다. // Test(NewData); // 테스트 결과로 알 수 있듯, struct는 레퍼런스가 아닌 값형이다!!! // 고로 값이 바뀌지 않는다. struct는 스택에 있다! // 구조체 struct는 값형이다 //くっそお!!!! Console.ReadKey(); }
public static void NotAStructInitializer_DefaultConstructor() { StructData structData = default(StructData); structData.Field = 1; structData.Property = 2; X(Y(), structData); }
public static void NotAStructInitializer_ExplicitConstructor() { StructData structData = new StructData(0); structData.Field = 1; structData.Property = 2; X(Y(), structData); }
public void PackStruct() { var date = MessagePackConvert.ToDateTime(1360370224238); var s = new StructData { Name = "Struct", Value = 112233445566778899 }; var pack = _packer.MakePacket("test1", date, s); Utils.Unpack(pack).Is(@"[ ""test.test1"", [ [ 1360370224.238, { ""Name"" : ""Struct"", ""Value"" : 112233445566778899 } ] ] ]"); }
public static StructData GenerateVMData(LuaTable luaData) { LuaTable strct = luaData.Get <LuaTable>("__vm_value"); StructData strctData = new StructData(); strct.ForEach <string, LuaTable>(delegate(string key, LuaTable el) { strctData.AddField(key, XLuaData.GenerateDataWithLuaTable(el)); }); return(strctData); }
static void Main(string[] args) { StructData NewData = new StructData(); // 참조형과 값형이 있다. // 클래스를 객체화하면 그건 참조형 // 구조체는 값형 NewData.a = 10; NewData.b = 10; // 이걸로 값이 바뀌진 않는다. 구조체는 값형이라... Test(NewData); }
void Update() { var deltaTime = Time.deltaTime; for (int i = 0; i < Count; i++) { #if USE_STRUCTS StructData result = structs[i]; #else ClassData result = classes[i]; #endif result.position += result.velocity * deltaTime; result.rotation = result.rotation * Quaternion.AngleAxis(30 * deltaTime, Vector3.up) * Quaternion.AngleAxis(45 * deltaTime, Vector3.forward); result.velocity += result.acceleration * deltaTime; result.acceleration = (Vector3.zero - result.position) * 0.5f; #if !NO_INTERACTION for (int j = 0; j < Count; j++) { if (i == j) { continue; } #if USE_STRUCTS StructData other = structs[j]; #else ClassData other = classes[j]; #endif var delta = other.position - result.position; var distance = delta.magnitude; if (distance <= 0.001f) { continue; } var dir = delta / distance; result.acceleration -= dir * 0.01f / distance; } #endif result.acceleration /= 1.2f * 10; #if USE_STRUCTS structs[i] = result; #endif } }
private void ReceiveCallBack(IAsyncResult ar) { try { int REnd = m_clientSocket.EndReceive(ar); //string strReceiveData = Encoding.Unicode.GetString(m_receiveBuffer,0,REnd); SerializationUnit seru = new DataDisplay.SerializationUnit(); StructData ms = new StructData(); byte[] destinationArray = new byte[REnd]; Array.Copy(m_receiveBuffer, destinationArray, REnd); List <byte[]> lstrec = execDataStick(destinationArray); foreach (byte[] destinationArr in lstrec) { try { StructData mst = (StructData)seru.DeserializeObject(destinationArr); if (mst.datamain != null) { if (mst.datamain.Length > 0) { //对获取的数据进行逻辑处理 ProcessData(mst); } } } catch (Exception e) { Debug.Write(e.Message); Array.Clear(s2, 0, s2.Length); s2 = new byte[0]; } } // byte[] destinationArray = new byte[REnd]; // // byte[] destinationArray1 = new byte[length]; // Array.Copy(m_receiveBuffer, destinationArray, REnd); //this.Invoke((Action)delegate () //{ // lstBuff.Remove(destinationArray); //} //); m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null); } catch (Exception ex) { } }
public static DataTable GetExcelContent(String filePath, string sheetName, StructData data) { if (sheetName == "_xlnm#_FilterDatabase") { return(null); } DataSet dateSet = new DataSet(); String connectionString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=NO;IMEX=1;'", filePath); String commandString = string.Format("SELECT * FROM [{0}$]", sheetName); using (OleDbConnection connection = new OleDbConnection(connectionString)) { connection.Open(); using (OleDbCommand command = new OleDbCommand(commandString, connection)) { OleDbCommand objCmd = new OleDbCommand(commandString, connection); OleDbDataAdapter myData = new OleDbDataAdapter(commandString, connection); myData.Fill(dateSet, sheetName); DataTable table = dateSet.Tables[sheetName]; table.Rows.RemoveAt(0); if (table.Rows.Count <= 0) { return(table); } table.Columns.RemoveAt(0); for (int i = 0; i < table.Rows[0].ItemArray.Length; i++) { var cloumnName = table.Rows[0].ItemArray[i].ToString() == "真" ? true : false; data.number.Add(cloumnName); } table.Rows.RemoveAt(0); if (table.Rows.Count <= 0) { return(table); } for (int i = 0; i < table.Rows[0].ItemArray.Length; i++) { var cloumnName = table.Rows[0].ItemArray[i].ToString(); data.fileds.Add(cloumnName); } table.Rows.RemoveAt(0); return(table); } } }
private static void Parse( string[] lines, List <EnumData> enums, List <FunctionData> functions, List <CallbackData> callbacks, List <StructData> structs) { for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("#define ")) { string[] parts = lines[i].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 3) { var @enum = new EnumData() { Name = parts[1], Value = parts[2] }; enums.Add(@enum); ParseDocs(lines, i, @enum); } } else if (lines[i].StartsWith("GLFWAPI ")) { FunctionData function = ParseFunction(lines, i); functions.Add(function); } else if (lines[i].StartsWith("typedef ")) { if (lines[i].Contains("(* ")) { CallbackData callback = ParseCallback(lines, i); callbacks.Add(callback); } else if (lines[i].StartsWith("typedef struct ")) { StructData @struct = ParseStruct(lines, ref i); structs.Add(@struct); } } } }
private void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { character2 = character1; } if (Input.GetKeyDown(KeyCode.Alpha2)) { character2.lv = 1; print("<color=blue>Character 2 Lv : " + character2.lv + "</color>"); print("<color=blue>Character 1 Lv : " + character1.lv + "</color>"); } if (Input.GetKeyDown(KeyCode.Alpha3)) { characters[1] = characters[0]; } if (Input.GetKeyDown(KeyCode.Alpha4)) { characters[1].lv = 1; print("<color=red>Character 2 Lv : " + characters[1].lv + "</color>"); print("<color=red>Character 1 Lv : " + characters[0].lv + "</color>"); } if (Input.GetKeyDown(KeyCode.Alpha5)) { // 陣列會變為參考型別 charactersArray2 = charactersArray1; } if (Input.GetKeyDown(KeyCode.Alpha6)) { charactersArray2[1].lv = 1; print("<color=yellow>Character 2 Lv : " + charactersArray2[1].lv + "</color>"); print("<color=yellow>Character 1 Lv : " + charactersArray1[1].lv + "</color>"); } }
/// <summary> /// 强纯过来的Pdf的字节数组保存到本地文件中 /// </summary> /// <param name="state"></param> private static void SavePdfBytesToFile(object state) { FileStream fileStream = null; StructData sd = (StructData)state; try { fileStream = File.Create( ProductionProcessPdfService.PdfDirPath + sd.filename); fileStream.Write(sd.filestream, 0, sd.filestream.Length); fileStream.Flush(); fileStream.Close(); } catch { } finally { if (fileStream != null) { fileStream.Close(); } } }
protected override void Execute(CodeActivityContext context) { //======= Variables ======= var xmlWorkflowData = WorkflowData.Get(context); var xmlStructData = new XDocument(); var dtIssueList = new DataTable(); var dtStatList = new DataTable(); //======= Analyze XAML Data ======= // To be implemented //======= Set Output ======= StructData.Set(context, xmlStructData); IssueList.Set(context, dtIssueList); StatList.Set(context, dtStatList); }
public void SaveToFile() { StructData gameData = new StructData { _enemiesMovementSpeed2 = this._enemiesMovementSpeed, _movementSpeedHippo2 = this._movementSpeedHippo, _theNumberOfHitPointsToWin2 = this._theNumberOfHitPointsToWin, _snowballReloadSpeedHippo2 = this._snowballReloadSpeedHippo, _periodicityOfEnemyShots2 = this._periodicityOfEnemyShots, _pointsForHittingTheWeakEnemy2 = this._pointsForHittingTheWeakEnemy, _pointsForHittingTheMiddleEnemy2 = this._pointsForHittingTheMiddleEnemy, _pointsForHittingTheStrongEnemy2 = this._pointsForHittingTheStrongEnemy }; string json = JsonUtility.ToJson(gameData, true); try{ File.WriteAllText(savePath, json); } catch (Exception e) { Debug.Log("Exception: " + e); } }
private static StructData ParseStruct(string[] lines, ref int i) { string[] parts = lines[i].Split(' '); var @struct = new StructData(); @struct.Name = parts[2]; if (lines[i].EndsWith(";")) { @struct.IsOpaque = true; } else if (lines[i + 1].StartsWith("{")) { i++; while (!lines[i].StartsWith("}")) { string line = lines[i].Trim(); if (line.EndsWith(";")) { parts = line.Substring(0, line.Length - 1).Split(' '); int j = 0; var member = new ParamData(); member.Type = ParseType(parts, ref j); j++; member.Name = parts[j]; @struct.Members.Add(member); } i++; } } return(@struct); }
public void LoadFromFile() { if (!File.Exists(savePath)) { Debug.Log("File not found!"); return; } string json = File.ReadAllText(savePath); try{ StructData DataFromJson = JsonUtility.FromJson <StructData>(json); _enemiesMovementSpeed = DataFromJson._enemiesMovementSpeed2; _movementSpeedHippo = DataFromJson._movementSpeedHippo2; _theNumberOfHitPointsToWin = DataFromJson._theNumberOfHitPointsToWin2; _snowballReloadSpeedHippo = DataFromJson._snowballReloadSpeedHippo2; _periodicityOfEnemyShots = DataFromJson._periodicityOfEnemyShots2; _pointsForHittingTheWeakEnemy = DataFromJson._pointsForHittingTheWeakEnemy2; _pointsForHittingTheMiddleEnemy = DataFromJson._pointsForHittingTheMiddleEnemy2; _pointsForHittingTheStrongEnemy = DataFromJson._pointsForHittingTheStrongEnemy2; } catch (Exception e) { Debug.Log("Exception: " + e); } }
static void FuncAAA(StructData aaa) { StructData b = aaa; Console.WriteLine(b.str); }
public abstract void SendData(StructData data);
static void ExcelToJson(string xlsx) { List <string> tableNames = ExcelHelper.GetExcelSheetNames(xlsx); //var json = new JObject(); foreach (string tableName in tableNames) { if (tableName != "Shelve" && tableName != "OffShelve") { continue; } JsonData json = new JsonData(); JsonData table = new JsonData(); StructData data = new StructData(); DataTable dataTable = ExcelHelper.GetExcelContent(xlsx, tableName, data); if (dataTable.Rows.Count <= 0) { continue; } foreach (DataRow dataRow in dataTable.Rows) { JsonData row = new JsonData(); int idx = 0; foreach (DataColumn column in dataTable.Columns) { bool isValid = false; for (int i = 0; i < dataRow.ItemArray.Length; ++i) { if (dataRow.ItemArray[i].ToString().Length > 0) { isValid = true; break; } } if (!isValid) { continue; } JsonData jtoken; string s = dataRow.ItemArray[idx] == null ? "" : dataRow.ItemArray[idx].ToString(); if (data.number[idx]) { if (s.IndexOf('.') != -1) { jtoken = new JsonData(float.Parse(s)); } else { jtoken = new JsonData(s == "" ? 0 : int.Parse(s)); } } else { jtoken = new JsonData(s); } row[data.fileds[idx]] = jtoken; idx++; } table.Add(row); } json["config"] = table; //Console.WriteLine(json.ToString()); string jsonArray = json.ToJson(); byte[] jsonBytes = System.Text.Encoding.Default.GetBytes(jsonArray); FileStream fs = new FileStream(tableName + ".json", FileMode.Create); fs.Write(jsonBytes, 0, jsonBytes.Length); fs.Close(); Console.WriteLine(tableName + ".json"); } //Console.WriteLine(json.ToString(Formatting.None)); }
static void Test(StructData _Data) { _Data.a = 1000; }
public TheStructWorkerClass(StructData yourStruct) { this.TheStruct = yourStruct; }
public ArrayLink(StructData @struct, Entry entry) { this.@struct = @struct; this.entry = entry; }
public void PackStruct() { var date = MessagePackConvert.ToDateTime(1360370224238); var s = new StructData { Name = "Struct", Value = 112233445566778899}; var pack = _packer.MakePacket("test1", date, s); Utils.Unpack(pack).Is(@"[ ""test.test1"", 1360370224238, { ""Name"" : ""Struct"", ""Value"" : 112233445566778899 } ]"); }