本文整理汇总了C#中Name.UsageFor方法的典型用法代码示例。如果您正苦于以下问题:C# Name.UsageFor方法的具体用法?C# Name.UsageFor怎么用?C# Name.UsageFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Name
的用法示例。
在下文中一共展示了Name.UsageFor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFrequency
/// <summary>
/// Adds frequency data for a name.
/// </summary>
/// <param name="name">The name to add data to.</param>
/// <param name="sex">The sex for which this data is being added.</param>
/// <param name="year">The year in which the name was used.</param>
/// <param name="occs">The number of times the name was used.</param>
private void AddFrequency(Name name, Sex sex, Int32 year, Int64 occs)
{
// try to get the usage version of this name
NameUsage usage = name.UsageFor(this.Culture, sex);
// create it if it does not exist
if (usage == null)
{
usage = new NameUsage(this.Culture, sex);
usage.NameID = name.ID;
usage.Name = name;
name.Usage.Add(usage);
this.context.Usage.Add(usage);
this.Commit();
}
// try to get an existing frequency entry
DateTime periodStart = new DateTime(year, 1, 1);
DateTime periodEnd = new DateTime(year, 12, 31);
NameFrequency frequency = usage.Frequency.SingleOrDefault(x =>
x.PeriodStart.Equals(periodStart) && x.PeriodEnd.Equals(periodEnd));
// create it if it doesn't exist
if (frequency == null)
{
frequency = new NameFrequency(periodStart, periodEnd);
frequency.NameUsedID = usage.ID;
frequency.NameUsed = usage;
frequency.Type = FrequencyType.Birth;
frequency.Occurrences = occs;
usage.Frequency.Add(frequency);
this.context.Frequency.Add(frequency);
this.Commit();
}
}