【发布时间】:2016-09-09 17:10:38
【问题描述】:
我有一个有很多属性的视图模型,我创建了一个自定义属性来将数据发送到 hubspot,因为 hubspot 需要一个特定的命名法,然后我需要创建一个具有一些迭代器之王的方法,即对于包含我的自定义属性的每个属性,他都放置了一个特定的输出,这里是代码:
public class CreateTrialUserHubspotViewModel {
[HubspotAttribute("firstname")]
[Display(Name = "First Name")]
[StringLength(50)]
[Required]
public string FirstName { get; set; }
[HubspotAttribute("lastname")]
[Display(Name = "Last Name")]
[StringLength(50)]
[Required]
public string LastName { get; set; }
[HubspotAttribute("jobtitle")]
[Display(Name = "Job title")]
[StringLength(50)]
[Required]
public string JobTitle { get; set; }
}
现在这是我的自定义属性
[AttributeUsage(AttributeTargets.All)]
public class HubspotAttribute : System.Attribute {
public readonly string hubspotValue;
public HubspotAttribute(string value)
{
this.hubspotValue = value;
}
}
然后我需要创建一个方法来获取视图模型对象并创建我的输出,我需要一些关于如何做到这一点的建议,将是这样的:
private static RowValidation ValidateRowWithManifest<T>(CreateTrialUserHubspotViewModel trialUser) {
RowValidation validation = new RowValidation();
FieldInfo[] fields = typeof(T).GetPropertiesOfSomeWay;
foreach (DataType field in fields) {
output+=whatINeed
}
return validation;
}
}
所需的输出将类似于:[firstname:"pepe", lastname="perez", jobtitle"none"]。只需调用该方法将返回我需要的所有数据。
【问题讨论】:
-
您的数据输出甚至没有意义。您有冒号等号,并且没有键/值对的表示器。你真正需要的是什么?
-
让我更好地解释一下,我有属性,有名称(当然),但我添加了一些自定义属性,以获得每个道具所需的确切名称,所以我需要一个方法期望一个 viewmodel 对象,然后他为每个 prop.customattr + ":" + viewModelObject.value 构建一个字符串。告诉我你现在是否理解得更好
标签: c# asp.net orchardcms hubspot