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 character然后50 = the points,6是交互类型,1是 trainingmoduleid(我不再需要将其拉出)并且名称很好,名称 :)

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 回答