我有这样的代码:实现扩展方法
namespace Zinc.Web.Extensions.DataModel.Training
{
public static class TrainingModuleProgressStateDataModelExtentions
{
public static string GetHintText(String aString)
{
//must still make up astring here
return aString;
}
}
}
namespace Zinc.DataModels.Training
{
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; }
public virtual string IncentiveTrainingModuleOptionName { get; set; }
}
在我的仓库
我添加到UserTrainingPoints:
string RawPoints = row["RawPoints"].ToString();
string[] rawPoints = RawPoints.Split(new char[] { '|' });
List<UserTrainingPointsDataModel> points = new List<UserTrainingPointsDataModel>();
foreach (var RawPoint in rawPoints)
{
string[] entry = RawPoint.Split(new char[] { ',' });
var point = new UserTrainingPointsDataModel();
point.Name = entry[0];
point.Points = Convert.ToInt32(entry[1]);
point.InteractionType = Convert.ToInt32(entry[2]);
point.IncentiveTrainingModuleOptionName = entry[3];
points.Add(point);
}
trainingModuleProgressState.UserTrainingPoints = points;
data.Add(trainingModuleProgressState);
在我看来,我需要调用其将在UserTrainingPoints值的扩展方法组成一个字符串,然后我将在工具提示中显示。
我的问题是我如何实现扩展方法,所以我可以在我的视图中调用它?
我的视图代码:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Zinc.Models.Training.TrainingModuleProgressStateDataModelResults>" %>
<%@ Import namespace="Zinc.Web.Extensions.DataModel.Training" %> //added this
<% if (module.HasAssessment)
{ %>
<div class="<%: moduleStateClass %>"> </div>
<div class="<%: moduleScoreClass %>"><%: module.ModuleScore %>%</div>
<% Zinc.Web.Extensions.DataModel.Training.TrainingModuleProgressStateDataModelExtentions.GetHintText(module.UserTrainingPoints); %> //still not correct here
你向我们展示了不包含任何扩展方法的代码。你想成为一种扩展方法的方法是什么?哪种类型? –
类名建议'TrainingModuleProgressStateDataModelExtentions.GetHintText'应该是一个扩展方法,但它只接受一个字符串作为其唯一参数。这看起来不正确。尝试让它不首先使用扩展方法,然后将其转换为扩展方法。 – hvd