本文整理汇总了C#中System.Text.StringBuilderWrapper.AppendPropertyAccessor方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilderWrapper.AppendPropertyAccessor方法的具体用法?C# StringBuilderWrapper.AppendPropertyAccessor怎么用?C# StringBuilderWrapper.AppendPropertyAccessor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.StringBuilderWrapper
的用法示例。
在下文中一共展示了StringBuilderWrapper.AppendPropertyAccessor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendType
//.........这里部分代码省略.........
hasIntValue = hasIntValue || value != null;
}
if (hasIntValue)
{
sb.AppendLine();
sb.AppendLine("private final int value;");
sb.AppendLine("{0}(final int intValue) {{ value = intValue; }}".Fmt(typeName));
sb.AppendLine("public int getValue() { return value; }");
}
}
sb = sb.UnIndent();
sb.AppendLine("}");
}
else
{
var defType = type.IsInterface()
? "interface"
: "class";
var extends = new List<string>();
//: BaseClass, Interfaces
if (type.Inherits != null)
extends.Add(Type(type.Inherits).InheritedType());
string responseTypeExpression = null;
var interfaces = new List<string>();
if (options.ImplementsFn != null)
{
var implStr = options.ImplementsFn();
if (!string.IsNullOrEmpty(implStr))
{
interfaces.Add(implStr);
if (implStr.StartsWith("IReturn<"))
{
var types = implStr.RightPart('<');
var returnType = types.Substring(0, types.Length - 1);
//Can't get .class from Generic Type definition
responseTypeExpression = returnType.Contains("<")
? "new TypeToken<{0}>(){{}}.getType()".Fmt(returnType)
: "{0}.class".Fmt(returnType);
}
}
if (!type.Implements.IsEmpty())
{
foreach (var interfaceRef in type.Implements)
{
interfaces.Add(Type(interfaceRef));
}
}
}
var extend = extends.Count > 0
? " extends " + extends[0]
: "";
if (interfaces.Count > 0)
extend += " implements " + string.Join(", ", interfaces.ToArray());
var addPropertyAccessors = Config.AddPropertyAccessors && !type.IsInterface();
var settersReturnType = addPropertyAccessors && Config.SettersReturnThis ? typeName : null;
sb.AppendLine("public static {0} {1}{2}".Fmt(defType, typeName, extend));
sb.AppendLine("{");
sb = sb.Indent();
var addVersionInfo = Config.AddImplicitVersion != null && options.IsRequest;
if (addVersionInfo)
{
sb.AppendLine("public Integer {0} = {1};".Fmt("Version".PropertyStyle(), Config.AddImplicitVersion));
if (addPropertyAccessors)
sb.AppendPropertyAccessor("Integer", "Version", settersReturnType);
}
AddProperties(sb, type,
includeResponseStatus: Config.AddResponseStatus && options.IsResponse
&& type.Properties.Safe().All(x => x.Name != typeof(ResponseStatus).Name),
addPropertyAccessors: addPropertyAccessors,
settersReturnType: settersReturnType);
if (responseTypeExpression != null)
{
sb.AppendLine("private static Object responseType = {0};".Fmt(responseTypeExpression));
sb.AppendLine("public Object getResponseType() { return responseType; }");
}
sb = sb.UnIndent();
sb.AppendLine("}");
}
sb = sb.UnIndent();
return lastNS;
}
示例2: AddProperties
public void AddProperties(StringBuilderWrapper sb, MetadataType type,
bool includeResponseStatus,
bool addPropertyAccessors,
string settersReturnType)
{
var wasAdded = false;
var sbInner = StringBuilderCacheAlt.Allocate();
var sbAccessors = new StringBuilderWrapper(sbInner);
if (addPropertyAccessors)
{
sbAccessors.AppendLine();
sbAccessors = sbAccessors.Indent().Indent();
}
var dataMemberIndex = 1;
if (type.Properties != null)
{
foreach (var prop in type.Properties)
{
if (wasAdded) sb.AppendLine();
var propType = Type(prop.Type, prop.GenericArgs);
var fieldName = prop.Name.SafeToken().PropertyStyle();
var accessorName = fieldName.ToPascalCase();
wasAdded = AppendComments(sb, prop.Description);
wasAdded = AppendDataMember(sb, prop.DataMember, dataMemberIndex++) || wasAdded;
wasAdded = AppendAttributes(sb, prop.Attributes) || wasAdded;
if (!fieldName.IsKeyWord())
{
sb.AppendLine("public {0} {1} = null;".Fmt(propType, fieldName));
}
else
{
var originalName = fieldName;
fieldName = Char.ToUpper(fieldName[0]) + fieldName.SafeSubstring(1);
sb.AppendLine("@SerializedName(\"{0}\") public {1} {2} = null;".Fmt(originalName, propType, fieldName));
}
if (addPropertyAccessors)
sbAccessors.AppendPropertyAccessor(propType, fieldName, accessorName, settersReturnType);
}
}
if (includeResponseStatus)
{
if (wasAdded) sb.AppendLine();
AppendDataMember(sb, null, dataMemberIndex++);
sb.AppendLine("public ResponseStatus {0} = null;".Fmt(typeof(ResponseStatus).Name.PropertyStyle()));
if (addPropertyAccessors)
sbAccessors.AppendPropertyAccessor("ResponseStatus", "ResponseStatus", settersReturnType);
}
if (sbAccessors.Length > 0)
sb.AppendLine(StringBuilderCacheAlt.ReturnAndFree(sbInner).TrimEnd()); //remove last \n
}