1

私はこのコードを持っています:

public class TrainingModuleProgressStateDataModelResults
{
    public IEnumerable<DataModels.Training.TrainingModuleProgressStateDataModel> TrainingModuleProgressStates { get; set; }
} 

public class TrainingModuleProgressStateDataModel
{
    public IEnumerable<UserTrainingPointsDataModel> UserTrainingPoints { get; set; }
}  

これを次のように分割する必要があります。

public class UserTrainingPointsDataModel
{
    public virtual int InteractionType { get; set; }
    public virtual int Points { get; set; }
    public virtual string Name { get; set; }
}

私のリポジトリでは、次のデータベースから戻ってきますRawPoints

China Incentive Program,50,6,1|India - Q2 Incentive ,50,6,4|China - Q2 Incentive,50,6,5|India Incentive Program,100,8,3|India - Q2 Incentive ,100,8,4

各セットは で区切られ、pipe character50 = the points,6インタラクション タイプで1あり、trainingmoduleid です (これはもう必要ありません)。name はまあ、name :)

string RawPoints = row["RawPoints"].ToString();
foreach (var RawPoint in RawPoints)
{
    UserTrainingPointsDataModel.Name = RawPoints.Name;???
}
4

1 に答える 1

1

以下のようにString.Splitを使用できます。

string rawInput = "China Incentive Program,50,6,1|India - Q2 Incentive ,50,6,4|China -     Q2 Incentive,50,6,5|India Incentive Program,100,8,3|India - Q2 Incentive ,100,8,4";
string[] rawPoints = rawInput.Split(new char[]{'|'});

List<UserTrainingPointsDataModel> points = new List<UserTrainingPointsDataModel>();

foreach(string rawPoint in rawPoints)
{
    string[] enrty = rawPoints.Split(new char[]{','});
    var point = new UserTrainingPointDataModel();
    point.Name = entry[0];
    point.Points = entry[1];
    point.InteractionType = entry[2];

    points.Add(point);  
}
于 2013-01-07T11:50:25.773 に答える