本文整理汇总了C#中FieldCollection.AddField方法的典型用法代码示例。如果您正苦于以下问题:C# FieldCollection.AddField方法的具体用法?C# FieldCollection.AddField怎么用?C# FieldCollection.AddField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FieldCollection
的用法示例。
在下文中一共展示了FieldCollection.AddField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
public void Write(
TzdbDatabase database,
WindowsZones cldrWindowsZones,
IDictionary<string, string> additionalWindowsNameToIdMappings,
Stream stream)
{
FieldCollection fields = new FieldCollection();
var zones = database.GenerateDateTimeZones().ToList();
var stringPool = CreateOptimizedStringPool(zones, database.ZoneLocations, database.Zone1970Locations, cldrWindowsZones);
// First assemble the fields (writing to the string pool as we go)
foreach (var zone in zones)
{
var zoneField = fields.AddField(TzdbStreamFieldId.TimeZone, stringPool);
WriteZone(zone, zoneField.Writer);
}
fields.AddField(TzdbStreamFieldId.TzdbVersion, null).Writer.WriteString(database.Version);
// Normalize the aliases
var timeZoneMap = new Dictionary<string, string>();
foreach (var key in database.Aliases.Keys)
{
var value = database.Aliases[key];
while (database.Aliases.ContainsKey(value))
{
value = database.Aliases[value];
}
timeZoneMap.Add(key, value);
}
fields.AddField(TzdbStreamFieldId.TzdbIdMap, stringPool).Writer.WriteDictionary(timeZoneMap);
// Windows mappings
cldrWindowsZones.Write(fields.AddField(TzdbStreamFieldId.CldrSupplementalWindowsZones, stringPool).Writer);
fields.AddField(TzdbStreamFieldId.WindowsAdditionalStandardNameToIdMapping, stringPool).Writer.WriteDictionary
(additionalWindowsNameToIdMappings.ToDictionary(pair => pair.Key, pair => cldrWindowsZones.PrimaryMapping[pair.Value]));
// Zone locations, if any.
var zoneLocations = database.ZoneLocations;
if (zoneLocations != null)
{
var field = fields.AddField(TzdbStreamFieldId.ZoneLocations, stringPool);
field.Writer.WriteCount(zoneLocations.Count);
foreach (var zoneLocation in zoneLocations)
{
zoneLocation.Write(field.Writer);
}
}
// Zone 1970 locations, if any.
var zone1970Locations = database.Zone1970Locations;
if (zone1970Locations != null)
{
var field = fields.AddField(TzdbStreamFieldId.Zone1970Locations, stringPool);
field.Writer.WriteCount(zone1970Locations.Count);
foreach (var zoneLocation in zone1970Locations)
{
zoneLocation.Write(field.Writer);
}
}
var stringPoolField = fields.AddField(TzdbStreamFieldId.StringPool, null);
stringPoolField.Writer.WriteCount(stringPool.Count);
foreach (string value in stringPool)
{
stringPoolField.Writer.WriteString(value);
}
// Now write all the fields out, in the right order.
new BinaryWriter(stream).Write(Version);
fields.WriteTo(stream);
}