本文整理汇总了C#中CodeWriter.Indent方法的典型用法代码示例。如果您正苦于以下问题:C# CodeWriter.Indent方法的具体用法?C# CodeWriter.Indent怎么用?C# CodeWriter.Indent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeWriter
的用法示例。
在下文中一共展示了CodeWriter.Indent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateReader
static void GenerateReader(ProtoMessage m, CodeWriter cw)
{
#region Helper Deserialize Methods
string refstr = (m.OptionType == "struct") ? "ref " : "";
if (m.OptionType != "interface")
{
cw.Summary("Helper: create a new instance to deserializing into");
cw.Bracket(m.OptionAccess + " static " + m.CsType + " Deserialize(Stream stream)");
cw.WriteLine(m.CsType + " instance = new " + m.CsType + "();");
cw.WriteLine("Deserialize(stream, " + refstr + "instance);");
cw.WriteLine("return instance;");
cw.EndBracketSpace();
cw.Summary("Helper: create a new instance to deserializing into");
cw.Bracket(m.OptionAccess + " static " + m.CsType + " DeserializeLengthDelimited(Stream stream)");
cw.WriteLine(m.CsType + " instance = new " + m.CsType + "();");
cw.WriteLine("DeserializeLengthDelimited(stream, " + refstr + "instance);");
cw.WriteLine("return instance;");
cw.EndBracketSpace();
cw.Summary("Helper: create a new instance to deserializing into");
cw.Bracket(m.OptionAccess + " static " + m.CsType + " DeserializeLength(Stream stream, int length)");
cw.WriteLine(m.CsType + " instance = new " + m.CsType + "();");
cw.WriteLine("DeserializeLength(stream, length, " + refstr + "instance);");
cw.WriteLine("return instance;");
cw.EndBracketSpace();
cw.Summary("Helper: put the buffer into a MemoryStream and create a new instance to deserializing into");
cw.Bracket(m.OptionAccess + " static " + m.CsType + " Deserialize(byte[] buffer)");
cw.WriteLine(m.CsType + " instance = new " + m.CsType + "();");
cw.WriteLine("using (var ms = new MemoryStream(buffer))");
cw.WriteIndent("Deserialize(ms, " + refstr + "instance);");
cw.WriteLine("return instance;");
cw.EndBracketSpace();
}
cw.Summary("Helper: put the buffer into a MemoryStream before deserializing");
cw.Bracket(m.OptionAccess + " static " + m.FullCsType + " Deserialize(byte[] buffer, " + refstr + m.FullCsType + " instance)");
cw.WriteLine("using (var ms = new MemoryStream(buffer))");
cw.WriteIndent("Deserialize(ms, " + refstr + "instance);");
cw.WriteLine("return instance;");
cw.EndBracketSpace();
#endregion
string[] methods = new string[]
{
"Deserialize", //Default old one
"DeserializeLengthDelimited", //Start by reading length prefix and stay within that limit
"DeserializeLength", //Read at most length bytes given by argument
};
//Main Deserialize
foreach (string method in methods)
{
if (method == "Deserialize")
{
cw.Summary("Takes the remaining content of the stream and deserialze it into the instance.");
cw.Bracket(m.OptionAccess + " static " + m.FullCsType + " " + method + "(Stream stream, " + refstr + m.FullCsType + " instance)");
}
else if (method == "DeserializeLengthDelimited")
{
cw.Summary("Read the VarInt length prefix and the given number of bytes from the stream and deserialze it into the instance.");
cw.Bracket(m.OptionAccess + " static " + m.FullCsType + " " + method + "(Stream stream, " + refstr + m.FullCsType + " instance)");
}
else if (method == "DeserializeLength")
{
cw.Summary("Read the given number of bytes from the stream and deserialze it into the instance.");
cw.Bracket(m.OptionAccess + " static " + m.FullCsType + " " + method + "(Stream stream, int length, " + refstr + m.FullCsType + " instance)");
}
else
throw new NotImplementedException();
if (m.IsUsingBinaryWriter)
cw.WriteLine("BinaryReader br = new BinaryReader(stream);");
//Prepare List<> and default values
foreach (Field f in m.Fields.Values)
{
if (f.Rule == FieldRule.Repeated)
{
//Initialize lists of the custom DateTime or TimeSpan type.
string csType = f.ProtoType.FullCsType;
if (f.OptionCodeType != null)
csType = f.OptionCodeType;
cw.WriteLine("if (instance." + f.CsName + " == null)");
cw.WriteIndent("instance." + f.CsName + " = new List<" + csType + ">();");
}
else if (f.OptionDefault != null)
{
if (f.ProtoType is ProtoEnum)
cw.WriteLine("instance." + f.CsName + " = " + f.ProtoType.FullCsType + "." + f.OptionDefault + ";");
else
cw.WriteLine("instance." + f.CsName + " = " + f.OptionDefault + ";");
}
else if (f.Rule == FieldRule.Optional)
{
if (f.ProtoType is ProtoEnum)
{
ProtoEnum pe = f.ProtoType as ProtoEnum;
//.........这里部分代码省略.........