How do I parse my string array to my c# model? - c#

This is my c# code:
public void addBoxScore(string[] playerstats)
{
Games gamestats = new Games();
gamestats.GAME_ID = Int32.Parse(playerstats[0]);
gamestats.TEAM_ID = Int32.Parse(playerstats[1]);
gamestats.TEAM_ABBREVIATION = playerstats[2];
gamestats.TEAM_CITY = playerstats[3];
gamestats.PLAYER_ID = Int32.Parse(playerstats[4]);
gamestats.PLAYER_NAME = playerstats[5];
gamestats.START_POSITION = playerstats[6];
gamestats.COMMENT = playerstats[7];
gamestats.MIN = Int32.Parse(playerstats[8]);
gamestats.FGM = Int32.Parse(playerstats[9]);
gamestats.FGA = Int32.Parse(playerstats[10]);
gamestats.FG_PCT = Int32.Parse(playerstats[11]);
gamestats.FGTHREEM = Int32.Parse(playerstats[12]);
gamestats.FGTHREEA = Int32.Parse(playerstats[13]);
gamestats.FGTHREE_PCT = Int32.Parse(playerstats[14]);
gamestats.FTM = Int32.Parse(playerstats[15]);
gamestats.FTA = Int32.Parse(playerstats[16]);
gamestats.FT_PCT = Int32.Parse(playerstats[17]);
gamestats.OREB = Int32.Parse(playerstats[18]);
gamestats.DREB = Int32.Parse(playerstats[19]);
gamestats.REB = Int32.Parse(playerstats[20]);
gamestats.AST = Int32.Parse(playerstats[21]);
gamestats.STL = Int32.Parse(playerstats[22]);
gamestats.BLK = Int32.Parse(playerstats[23]);
gamestats.TO = Int32.Parse(playerstats[24]);
gamestats.PF = Int32.Parse(playerstats[25]);
gamestats.PTS = Int32.Parse(playerstats[26]);
gamestats.PLUS_MINUS = Int32.Parse(playerstats[27]);
}
and this is my javascript that gets the data from the api and sends it to the controller.
var date = "05/05/2014";
$.ajax({
dataType: "jsonp",
type: "post",
crossDomain: true,
url: 'http://stats.nba.com/stats/scoreboard/?LeagueID=00&gameDate=' + date + '&DayOffset=0',
success: function (val) {
var result = val.resultSets[0].rowSet;
$.each(result, function (key, value) {
var gameID = this[2];
$.ajax({
dataType: "jsonp",
async: false,
type: "post",
crossDomain: true,
gameID: { gameID: gameID },
url: "http://stats.nba.com/stats/boxscore?GameID=" + gameID + "&RangeType=0&StartPeriod=0&EndPeriod=0&StartRange=0&EndRange=0",
success: function (gameinfo) {
var w = gameinfo.resultSets[0].rowSet[0];
if (w[4] == "Final") {
var pstats = gameinfo.resultSets[4].rowSet;
$.each(pstats, function (key, value) {
var playerstats = this;
$.ajax({
async: false,
type: "post",
url: "/Stats/addBoxScore",
data: { playerstats: JSON.stringify(playerstats) },
done: function (data) {
console.log(data);
},
error: function (jqXHR, err) {
console.log(err);
}
});
});
};
}
And this is what the data that the controller recieves looks like:
"[\"0041300201\",1610612764,\"WAS\",\"Washington\",2772,\"Trevor Ariza\",\"F\",\"\",\"37:20\",7,10,0.7,6,6,1,2,4,0.5,1,5,6,2,1,0,0,3,22,18]"
This is my model:
public class Games
{
[Key, Column(Order = 0)]
public int GAME_ID { get; set; }
public int TEAM_ID { get; set; }
public string TEAM_ABBREVIATION { get; set; }
public string TEAM_CITY { get; set; }
[Key, Column(Order = 1)]
public int PLAYER_ID { get; set; }
public string PLAYER_NAME { get; set; }
public string START_POSITION { get; set; }
public string COMMENT { get; set; }
public int MIN { get; set; }
public int FGM { get; set; }
public int FGA { get; set; }
public int FG_PCT { get; set; }
public int FGTHREEM { get; set; }
public int FGTHREEA { get; set; }
public int FGTHREE_PCT { get; set; }
public int FTM { get; set; }
public int FTA { get; set; }
public int FT_PCT { get; set; }
public int OREB { get; set; }
public int DREB { get; set; }
public int REB { get; set; }
public int AST { get; set; }
public int STL { get; set; }
public int BLK { get; set; }
public int TO { get; set; }
public int PF { get; set; }
public int PTS { get; set; }
public int PLUS_MINUS { get; set; }
public virtual Player player { get; set; }
}
Why does it put \ in every string in the array? And how do i parse it to my model?

I think this should help.
using System.Web.Helpers;
public void addBoxScore(string playerstats)
{
Games gamestats = Json.Decode<Games>(playerstats);
}
Edits
Well, I'm not sure that fully understand the structure of your model, but... Try the following:
public void addBoxScore(string playerstats)
{
var gamestats = System.Web.Helpers.Json.Decode<IEnumerable<Games>>(playerstats);
}
More Edits
Now I can spot the problem. Json.Decode() will not help you to create your Games object because data you send to controller is just stringnified array of strings and property names, which are required for converting are not provided. Maximum what you can do - deserialize this string to proper C# string array manually, and then do what you have already done - assign each property one by one. You can refactor it to look more pretty, create some extension method for string or even use reflection to loop through Games properties for assignment ... For example:
public static class Extensions
{
public static Games ToGames(this string data)
{
var playerstats = data
.Replace("[", string.Empty)
.Replace("]", string.Empty)
.Replace(#"\", string.Empty)
.Replace("\"", string.Empty)
.Split(',')
.Select(s => s.Trim())
.ToArray();
var gamestats = new Games
{
GAME_ID = Int32.Parse(playerstats[0]),
TEAM_ID = Int32.Parse(playerstats[1]),
TEAM_ABBREVIATION = playerstats[2],
TEAM_CITY = playerstats[3],
PLAYER_ID = Int32.Parse(playerstats[4]),
PLAYER_NAME = playerstats[5],
START_POSITION = playerstats[6],
COMMENT = playerstats[7],
MIN = Int32.Parse(playerstats[8]),
FGM = Int32.Parse(playerstats[9]),
FGA = Int32.Parse(playerstats[10]),
FG_PCT = Int32.Parse(playerstats[11]),
FGTHREEM = Int32.Parse(playerstats[12]),
FGTHREEA = Int32.Parse(playerstats[13]),
FGTHREE_PCT = Int32.Parse(playerstats[14]),
FTM = Int32.Parse(playerstats[15]),
FTA = Int32.Parse(playerstats[16]),
FT_PCT = Int32.Parse(playerstats[17]),
OREB = Int32.Parse(playerstats[18]),
DREB = Int32.Parse(playerstats[19]),
REB = Int32.Parse(playerstats[20]),
AST = Int32.Parse(playerstats[21]),
STL = Int32.Parse(playerstats[22]),
BLK = Int32.Parse(playerstats[23]),
TO = Int32.Parse(playerstats[24]),
PF = Int32.Parse(playerstats[25]),
PTS = Int32.Parse(playerstats[26]),
PLUS_MINUS = Int32.Parse(playerstats[27])
};
return gamestats;
}
}
And then in your controller:
public void addBoxScore(string playerstats)
{
Games result = playerstats.ToGames();
}
Also I have a question - What is MIN = Int32.Parse(playerstats[8])? Because it has a value of 37:20 (in example string you provided) and I'm not sure I understand what is this, because it will give the error during conversion to int.

Related

How to get each value from table in ASP.NET MVC?

I get each value but it doesn't display on DSChiTiet. How can I fix it? It only gets value TenKH, NgayLap, TongTien.
DSChiTiet doesn't get value from table and displays null. enter image description here
Thank you very much for your help <3.
My model PhieuBanHangModel
public class PhieuBanHangViewModel
{
public int MaPBH { get; set; }
public string TenKH { get; set; }
public DateTime NgayLap { get; set; }
public decimal TongTien { get; set; }
public IEnumerable<CT_PhieuBanHangViewModel> DSChiTiet { get; set; }
}
My model CT_PhieuBanHangModel
public class CT_PhieuBanHangViewModel
{
public int MaPBH { get; set; }
public int MaSP { get; set; }
public int SoLuong { get; set; }
public decimal DonGia { get; set; }
public decimal ThanhTien { get; set; }
}
Controller Create Json
[HttpPost]
public JsonResult Create(PhieuBanHangViewModel phieuBanHang)
{
return Json(data: "", JsonRequestBehavior.AllowGet);
}
Function in View
function ThanhToan() {
var phieuBanHang = {};
var dsct_PhieuBanHang = new Array();
phieuBanHang.TenKH = $("#txtTenKH").val();
phieuBanHang.NgayLap = $("#txtNgayGiaoDich").val();
phieuBanHang.TongTien = $("#txtTongTien").val();
$("table tr:not(:first)").each(function () {
var ct_PhieuBanHang = {};
ct_PhieuBanHang.MaSP = parseFloat($(this).find("td:eq(0))").text());
ct_PhieuBanHang.SoLuong = parseFloat($(this).find("td:eq(4))").text());
ct_PhieuBanHang.DonGia = parseFloat($(this).find("td:eq(6))").text());
ct_PhieuBanHang.ThanhTien = parseFloat($(this).find("td:eq(7))").text());
dsct_PhieuBanHang.push(ct_PhieuBanHang);
});
phieuBanHang.DSChiTiet = dsct_PhieuBanHang;
$.ajax({
async: true,
type: 'POST',
dataType: 'JSON',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(phieuBanHang),
url: '/Manager/CT_PhieuBanHang/Create',
success: function (data) {
},
error: function () {
alert('Lỗi');
}
});
}
You may need to inherit ApiControllerand add the [FromBody] attribute to the binding model:
public class MyController : ApiController
{
/* something else... */
// /Manager/CT_PhieuBanHang/Create
[HttpPost]
public JsonResult Create([FromBody] PhieuBanHangViewModel phieuBanHang)
{
return Json(data: "", JsonRequestBehavior.AllowGet);
}
/* something else... */
}
For your jQuery code, make sure thet:$("table tr:not(:first)") do returns an array contains at least 1 item. (You can verify that by doing a console.log(phieuBanHang) to print out your data).

How to select object and its properties base on its properties which is list with linq?

I have an object which has a property which is list. Based on that list I want to filter property of it along with other properties of an object.
I have following object
{
Adult: 1,
Child: 0,
Infant: 0,
Origin: 'ABC',
Destination: 'XYZ',
DomesticFlightInfos: [{
FlightID: flightId1,
FareID: fareId1,
IsInbound: true
},
{
FlightID: flightId2,
FareID: fareId2,
IsInbound: false
}
]
};
I want following two objects
{
Adult: 1,
Child: 0,
Infant: 0,
Origin: 'ABC',
Destination: 'XYZ',
DomesticFlightInfos: [{
FlightID: flightId1,
FareID: fareId1,
IsInbound: true
}]
};
Adult: 1,
Child: 0,
Infant: 0,
Origin: 'ABC',
Destination: 'XYZ',
DomesticFlightInfos: [{
FlightID: flightId2,
FareID: fareId2,
IsInbound: false
}]
I was trying to do reservation.DomesticFlightInfos.Where(x => !x.IsInbound); which was wrong and got casting issue. What could be the best solution for it?
C# Object
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
new DomesticFlightReservation()
{
Adult = 1,
Child = 0,
Infant = 0,
Origin = "ABC",
Destination = "XYZ",
DomesticFlightInfos = new List<DomesticFlightInfo>(){
new DomesticFlightInfo{
FlightID= "flightId1",
FareID= "fareId1",
IsInbound= true
},
new DomesticFlightInfo {
FlightID= "flightId2",
FareID= "fareId2",
IsInbound= false
}
}
};
}
}
public class DomesticFlightReservation
{
public int Adult { get; set; } = 0;
public int Child { get; set; } = 0;
public int Infant { get; set; } = 0;
public string Origin { get; set; }
public string Destination { get; set; }
public List<DomesticFlightInfo> DomesticFlightInfos { get; set; }
}
public class DomesticFlightInfo
{
public string FlightID { get; set; }
public string FareID { get; set; }
// True for inbound, false for outbound
public bool IsInbound { get; set; }
}
Since you haven't provided C# object, assuming your C# objects to be defined as
public class DomesticFlightInfo
{
public string FlightID { get; set; }
public string FareID { get; set; }
public bool IsInbound { get; set; }
}
public class RootObject
{
public int Adult { get; set; }
public int Child { get; set; }
public int Infant { get; set; }
public string Origin { get; set; }
public string Destination { get; set; }
public List<DomesticFlightInfo> DomesticFlightInfos { get; set; }
}
If your intention is to separate the Inbounds and Outbound flights to separate groups, you could
var reservation = JsonConvert.DeserializeObject<RootObject>(str);
var flattenedReservation = new[]{reservation}.SelectMany(x=>x.DomesticFlightInfos
.GroupBy(v=>v.IsInbound)
.Select(c =>
{
x.DomesticFlightInfos = c.ToList();
return x;
}));
var jsonCollection = flattenedReservation.Select(x=> JsonConvert.SerializeObject(x,settings));
If your intention is to separate out each flight info into separate jsons, you could
var flattenedReservation = new[]{reservation}.SelectMany(x=>x.DomesticFlightInfos
.Select(c =>
{
x.DomesticFlightInfos = new List<DomesticFlightInfo>{c};
return x;
}));
var jsonCollection = flattenedReservation.Select(x=> JsonConvert.SerializeObject(x));
Output
If you have a list as a collection, you can use SelectMany
So, if you have a list
List<RootObject> rootObjects
then you can do this like flatten the list to get individual items:
rootObjects.SelectMany(x=> x.DomesticFlightInfos).Where(y => !y.IsInbound);

How to Send json object with fromdata to mvc controller

I am sending formdata data object to mvc controller. I received the array in controller but the object is always missing. Searched a lot about it did not find a clue.
I have tried to send whole object or appending each value to formdata but its always null. does formdata accepts? nested object.
My jQuery code:
function addstudent() {
var form= $("#studentform").valid();
if (form)
{
personfood.details.firstname = $("#firstname").val();
personfood.details.lastname = $("#lastname").val();
personfood.details.imageuploaded = $("#imageupload")[0].files[0];
personfood.details.rememberme = $("#rememberme").is(":checked");
personfood.details.newsletter = $("#newsletter").is(":checked");
personfood.details.gender = $("input[name='gender']").val();
var personfoods = new FormData();
$.each(personfood.details, function (key, value) {
personfoods.append(key, value);
});
$.each(personfood.foodname, function (key, value) {
personfoods.append("foodname["+[key]+"]", value);
});
for (var pair of personfoods.entries()) {
console.log(pair[0] + ', ' + pair[1]);
}
$.ajax({
url: "/Main/addperson",
type: "POST",
processData: false,
cache: false,
contentType: false,
dataType: "json",
data: personfoods,
success: onsucessinsert,
error:onerrorinsert
})
}
My ViewModel
public class personfoods
{
public details details { get; set; }
public List<string> foodname { get; set; }
}
details model:
public class details
{
public int id { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string imagename { get; set; }
public string imageshorturl { get; set; }
public string imagefullurl { get; set; }
public bool rememberme {get;set;}
public bool newsletter { get; set; }
public string gender { get; set;}
public HttpPostedFileBase imageuploaded { get; set; }
}
i solve it using $.each and appending key value pairs to my formdata.
$.each(personfood.details, function (key, value) {
personfoods.append("details[" + key + "]",value);
});
ContentType should be ''application/json; charset=utf-8" and you can not post files like you are doing. I think data:JSON.stringify(personfoods); should work for remaining properties.

Saving data to a sqlite local database too slow. Any ideas how to make it faster? [duplicate]

This question already has answers here:
SQLite .NET performance, how to speed up things?
(2 answers)
Closed 7 years ago.
I am having a hard time trying to save the data faster, to a local DB.
Even though this is a one time saving, when the app runs for the first time, it takes like 90 seconds, in a Lumia 920, to save "only" the "map tables".
What I do:
1) I call an API, where I receive all the grids, with its Xs, Ys, Map Id, etc.
2) I deserialize the info based on a class I have defined.
3) For each item, in that info, I save the "misc" info (since I will use it)
4) I save, in a GRIDS table, each grid inside the previous item.
This code snipet is what I use to deserialize the info, and call the function to save in the DB
public class Maps
{
public string id { get; set; }
public string name { get; set; }
public string height { get; set; }
public string width { get; set; }
public string tile { get; set; }
public string shopping_id { get; set; }
public string url { get; set; }
public string updated_at { get; set; }
public string created_at { get; set; }
public GridFirst gridFirst { get; set; }
public GridLast gridLast { get; set; }
public List<Grid> grid { get; set; }
public class GridFirst
{
public string id { get; set; }
public string x { get; set; }
public string y { get; set; }
public string maps_id { get; set; }
public string value { get; set; }
}
public class GridLast
{
public string id { get; set; }
public string x { get; set; }
public string y { get; set; }
public string maps_id { get; set; }
public string value { get; set; }
}
public class Grid
{
public string id { get; set; }
public string x { get; set; }
public string y { get; set; }
public string maps_id { get; set; }
public string value { get; set; }
}
public void deserializeAndConvert(string aaa)
{
JObject myGeneral = JObject.Parse(aaa);
IList<JToken> results = myGeneral["resp"].Children().ToList();
// serialize JSON results into .NET objects
IList<Maps> searchResults = new List<Maps>();
foreach (JToken result in results)
{
Maps searchResult = JsonConvert.DeserializeObject<Maps>(result.ToString());
searchResults.Add(searchResult);
}
var respuesta = from data in searchResults
select new
{
id = data.id,
name = data.name,
height = data.height,
width = data.width,
tile = data.tile,
url = data.url,
lastX = data.gridLast.x,
lastY = data.gridLast.y,
grid = data.grid
};
foreach (var a in respuesta)
{
Database_Controller.getReadyToSaveData("mapinfo", 8, a.id, a.name, a.height, a.width, a.tile, a.url, a.lastX, a.lastY, "", "", "", "", "", "", "");
foreach (var data in a.grid)
{
Database_Controller.getReadyToSaveData("mapgrid", 5, data.id, data.x, data.y, data.maps_id, data.value, "", "", "", "", "", "", "", "", "", "");
}
}
}
}
And these are the functions that save the data, in the DB
public static void getReadyToSaveData(string dbName, int numberOfParams, string param1, string param2, string param3, string param4, string param5, string param6, string param7, string param8, string param9, string param10, string param11, string param12, string param13, string param14, string param15)
{
List<string> myParams = new List<string>();
myParams.Add(param1);
myParams.Add(param2);
myParams.Add(param3);
myParams.Add(param4);
myParams.Add(param5);
myParams.Add(param6);
myParams.Add(param7);
myParams.Add(param8);
myParams.Add(param9);
myParams.Add(param10);
myParams.Add(param11);
myParams.Add(param12);
myParams.Add(param13);
myParams.Add(param14);
myParams.Add(param15);
List<string> myParamsToDB = new List<string>();
for (var i = 0; i < numberOfParams; i++)
{
myParamsToDB.Add(myParams[i]);
}
insertData(dbName, myParamsToDB);
}
public static void insertData(string dbName, List<string> paramsToGo)
{
try
{
using (var connection = new SQLiteConnection("Unicenter.sqlite"))
{
if (dbName == "mapgrid")
{
using (var statement = connection.Prepare(#"INSERT INTO mapgrid (ID,X,Y,MAPS_ID,VALUE)
VALUES(?, ?,?,?,?);"))
{
statement.Bind(1, paramsToGo[0]);
statement.Bind(2, paramsToGo[1]);
statement.Bind(3, paramsToGo[2]);
statement.Bind(4, paramsToGo[3]);
statement.Bind(5, paramsToGo[4]);
// Inserts data.
statement.Step();
statement.Reset();
statement.ClearBindings();
}
}
if (dbName == "mapinfo")
{
using (var statement = connection.Prepare(#"INSERT INTO mapinfo (ID,NAME,HEIGHT,WIDTH,TILE,URL,LASTX,LASTY)
VALUES(?, ?,?,?,?,?,?,?);"))
{
statement.Bind(1, paramsToGo[0]);
statement.Bind(2, paramsToGo[1]);
statement.Bind(3, paramsToGo[2]);
statement.Bind(4, paramsToGo[3]);
statement.Bind(5, paramsToGo[4]);
statement.Bind(6, paramsToGo[5]);
statement.Bind(7, paramsToGo[6]);
statement.Bind(8, paramsToGo[7]);
// Inserts data.
statement.Step();
statement.Reset();
statement.ClearBindings();
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine("Exception\n" + ex.ToString());
}
}
***Edit: As a kind reminder, in case some people does not see the tags (and mark this question as duplicated), this is FOR WINDOWS PHONE 8.1, so, the functions, references and classes ARE different from plain c#
Any idea on how to make it faster? ... What am I doing wrong?
you can use parallel.for loop which is more faster if you have large data or you can easily check each loop how much time it takes to execute in VS-2015

protobuf-net Sub-message not read correctly

I'm currently testing protobuf-net (latest version), but intermittently I'm getting "Sub-message not read correctly" exception while deserializing. So far there's no apparent pattern to reproduce this error, and the data is always the same.
I googled this error and so far people reported this error only when dealing with big data (>20MB), which I'm not doing.
Can anyone point out whether this is a bug (and if it is, any possible solution to fix/circumvent this?), or am I missing some steps? Below is the code I'm using:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using ProtoBuf;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
const string message = "Cycle {0}: {1:N2} ms - avg: {2:N2} ms - min: {3:N2} - max: {4:N2}";
const int loop = 1000;
var counter = new Stopwatch();
var average = 0d;
var min = double.MaxValue;
var max = double.MinValue;
for (int i = 0;; i++)
{
var classThree = Create();
counter.Reset();
counter.Start();
Parallel.For(0, loop, j =>
{
using (var ms = new MemoryStream())
{
Serializer.Serialize(ms, classThree);
using (var ms2 = new MemoryStream(ms.ToArray()))
{
var des = Serializer.Deserialize<ClassThree>(ms2);
var aaa = des;
}
}
});
counter.Stop();
var elapsed = counter.Elapsed.TotalMilliseconds;
average += elapsed;
min = Math.Min(min, elapsed);
max = Math.Max(max, elapsed);
var currentAverage = average / (i + 1);
Console.Clear();
Console.WriteLine(message, i, elapsed, currentAverage, min, max);
Thread.Sleep(0);
}
}
private static ClassThree Create()
{
var classOne = new ClassSix()
{
// properties
p_i1 = -123,
p_i2 = 456,
p_l1 = -456,
p_l2 = 123,
p_s = "str",
p_f = 12.34f,
p_d = 56.78d,
p_bl = true,
p_dt = DateTime.Now.AddMonths(-1),
p_m = 90.12m,
p_b1 = 12,
p_b2 = -34,
p_c = 'c',
p_s1 = -21,
p_s2 = 43,
p_ts = new TimeSpan(12, 34, 56),
p_id = Guid.NewGuid(),
p_uri = new Uri("http://www.google.com"),
p_ba = new[] { (byte)1, (byte)3, (byte)2 },
p_t = typeof(ClassTwo),
p_sa = new[] { "aaa", "bbb", "ccc" },
p_ia = new[] { 7, 4, 9 },
p_e1 = EnumOne.Three,
p_e2 = EnumTwo.One | EnumTwo.Two,
p_list = new List<ClassFive>(new[]
{
new ClassFive()
{
i = 1,
s = "1"
},
new ClassFive()
{
i = 2,
s = "2"
}
}),
// fields
f_i1 = -123,
f_i2 = 456,
f_l1 = -456,
f_l2 = 123,
f_s = "str",
f_f = 12.34f,
f_d = 56.78d,
f_bl = true,
f_dt = DateTime.Now.AddMonths(-1),
f_m = 90.12m,
f_b1 = 12,
f_b2 = -34,
f_c = 'c',
f_s1 = -21,
f_s2 = 43,
f_ts = new TimeSpan(12, 34, 56),
f_id = Guid.NewGuid(),
f_uri = new Uri("http://www.google.com"),
f_ba = new[] { (byte)1, (byte)3, (byte)2 },
f_t = typeof(ClassTwo),
f_sa = new[] { "aaa", "bbb", "ccc" },
f_ia = new[] { 7, 4, 9 },
f_e1 = EnumOne.Three,
f_e2 = EnumTwo.One | EnumTwo.Two,
f_list = new List<ClassFive>(new[]
{
new ClassFive()
{
i = 1,
s = "1"
},
new ClassFive()
{
i = 2,
s = "2"
}
})
};
var classThree = new ClassThree()
{
ss = "333",
one = classOne,
two = classOne
};
return classThree;
}
}
public enum EnumOne
{
One = 1,
Two = 2,
Three = 3
}
[Flags]
public enum EnumTwo
{
One = 1,
Two = 2,
Three = 4
}
[ProtoContract, ProtoInclude(51, typeof(ClassSix))]
public class ClassOne
{
// properties
[ProtoMember(1)]
public int p_i1 { set; get; }
[ProtoMember(2)]
public uint p_i2 { set; get; }
[ProtoMember(3)]
public long p_l1 { set; get; }
[ProtoMember(4)]
public ulong p_l2 { set; get; }
[ProtoMember(5)]
public string p_s { set; get; }
[ProtoMember(6)]
public float p_f { set; get; }
[ProtoMember(7)]
public double p_d { set; get; }
[ProtoMember(8)]
public bool p_bl { set; get; }
[ProtoMember(9)]
public DateTime p_dt { set; get; }
[ProtoMember(10)]
public decimal p_m { set; get; }
[ProtoMember(11)]
public byte p_b1 { set; get; }
[ProtoMember(12)]
public sbyte p_b2 { set; get; }
[ProtoMember(13)]
public char p_c { set; get; }
[ProtoMember(14)]
public short p_s1 { set; get; }
[ProtoMember(15)]
public ushort p_s2 { set; get; }
[ProtoMember(16)]
public TimeSpan p_ts { set; get; }
[ProtoMember(17)]
public Guid p_id { set; get; }
[ProtoMember(18)]
public Uri p_uri { set; get; }
[ProtoMember(19)]
public byte[] p_ba { set; get; }
[ProtoMember(20)]
public Type p_t { set; get; }
[ProtoMember(21)]
public string[] p_sa { set; get; }
[ProtoMember(22)]
public int[] p_ia { set; get; }
[ProtoMember(23)]
public EnumOne p_e1 { set; get; }
[ProtoMember(24)]
public EnumTwo p_e2 { set; get; }
[ProtoMember(25)]
public List<ClassFive> p_list { set; get; }
// fields
[ProtoMember(26)]
public int f_i1 = 0;
[ProtoMember(27)]
public uint f_i2 = 0;
[ProtoMember(28)]
public long f_l1 = 0L;
[ProtoMember(29)]
public ulong f_l2 = 0UL;
[ProtoMember(30)]
public string f_s = string.Empty;
[ProtoMember(31)]
public float f_f = 0f;
[ProtoMember(32)]
public double f_d = 0d;
[ProtoMember(33)]
public bool f_bl = false;
[ProtoMember(34)]
public DateTime f_dt = DateTime.MinValue;
[ProtoMember(35)]
public decimal f_m = 0m;
[ProtoMember(36)]
public byte f_b1 = 0;
[ProtoMember(37)]
public sbyte f_b2 = 0;
[ProtoMember(38)]
public char f_c = (char)0;
[ProtoMember(39)]
public short f_s1 = 0;
[ProtoMember(40)]
public ushort f_s2 = 0;
[ProtoMember(41)]
public TimeSpan f_ts = TimeSpan.Zero;
[ProtoMember(42)]
public Guid f_id = Guid.Empty;
[ProtoMember(43)]
public Uri f_uri = null;
[ProtoMember(44)]
public byte[] f_ba = null;
[ProtoMember(45)]
public Type f_t = null;
[ProtoMember(46)]
public string[] f_sa = null;
[ProtoMember(47)]
public int[] f_ia = null;
[ProtoMember(48)]
public EnumOne f_e1 = 0;
[ProtoMember(49)]
public EnumTwo f_e2 = 0;
[ProtoMember(50)]
public List<ClassFive> f_list = null;
}
[ProtoContract]
public class ClassSix : ClassOne
{
}
[ProtoContract]
public class ClassTwo
{
}
[ProtoContract]
public interface IClass
{
[ProtoMember(1)]
string ss
{
set;
get;
}
[ProtoMember(2)]
ClassOne one
{
set;
get;
}
}
[ProtoContract]
public class ClassThree : IClass
{
[ProtoMember(1)]
public string ss { set; get; }
[ProtoMember(2)]
public ClassOne one { set; get; }
[ProtoMember(3)]
public ClassSix two { set; get; }
}
[ProtoContract]
public class ClassFour
{
[ProtoMember(1)]
public string ss { set; get; }
[ProtoMember(2)]
public ClassOne one { set; get; }
}
[ProtoContract]
public class ClassFive
{
[ProtoMember(1)]
public int i { set; get; }
[ProtoMember(2)]
public string s { set; get; }
}
}
Updated to rev. 669 and so far haven't encounter the error again. So I'm reporting this as fixed for now.

Categories

Resources