本文整理匯總了C#中CodeWriter.EndBracketSpace方法的典型用法代碼示例。如果您正苦於以下問題:C# CodeWriter.EndBracketSpace方法的具體用法?C# CodeWriter.EndBracketSpace怎麽用?C# CodeWriter.EndBracketSpace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CodeWriter
的用法示例。
在下文中一共展示了CodeWriter.EndBracketSpace方法的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;
//.........這裏部分代碼省略.........