private void WriteAsTypeMethods(CodeWriter writer, Schema schema)
{
foreach (Property property in schema.Properties)
{
if (!property.IsValue)
{
continue;
}
if (PropertyValueIsLeaf(property))
{
IEnumerable <OverloadInfo> overloads = GetOverloadsForProperty(property);
OverloadInfo firstOverload = overloads.First();
if (firstOverload.Parameters.Length != 1)
{
continue;
}
string firstOverloadFirstParameterType = firstOverload.Parameters[0].Type;
OverloadInfo sampleOverload = FindSampledDataOverload(overloads);
string interfaceName = "ICesiumValuePropertyWriter";
if (sampleOverload != null)
{
interfaceName = "ICesiumInterpolatableValuePropertyWriter";
}
WriteSummaryText(writer, string.Format("Returns a wrapper for this instance that implements <see cref=\"{0}{{T}}\" /> to write a value in <c>{1}</c> format. Because the returned instance is a wrapper for this instance, you may call <see cref=\"ICesiumElementWriter.Close\" /> on either this instance or the wrapper, but you must not call it on both.", interfaceName, property.NameWithPascalCase));
WriteReturnsText(writer, "The wrapper.");
writer.WriteLine("public {0}<{1}> As{2}()", interfaceName, firstOverloadFirstParameterType, property.NameWithPascalCase);
using (writer.OpenScope())
{
writer.WriteLine("return m_as{0}.Value;", property.NameWithPascalCase);
}
writer.WriteLine();
string adaptorName = "CesiumWriterAdaptor";
if (sampleOverload != null)
{
adaptorName = "CesiumInterpolatableWriterAdaptor";
}
writer.WriteLine("private {0}<{1}> Create{2}Adaptor()", interfaceName, firstOverloadFirstParameterType, property.NameWithPascalCase);
using (writer.OpenScope())
{
string extraParameter = "";
if (sampleOverload != null)
{
extraParameter = string.Format(", (me, dates, values, startIndex, length) => me.Write{0}(dates, values, startIndex, length)", property.NameWithPascalCase);
}
writer.WriteLine("return new {0}<{1}CesiumWriter, {2}>(this, (me, value) => me.Write{3}(value){4});", adaptorName, schema.NameWithPascalCase, firstOverloadFirstParameterType, property.NameWithPascalCase, extraParameter);
}
writer.WriteLine();
}
}
}