public virtual string MakeAttributesValueString(object v, TypeReference valueType) { var formatters = new[] { new AttributeValueFormatter(), new ApplePlatformEnumFormatter(), new StandardFlagsEnumFormatter(), new DefaultAttributeValueFormatter(), }; ResolvedTypeInfo type = new ResolvedTypeInfo(valueType); if (valueType is ArrayType && v is CustomAttributeArgument[]) { ArrayType atype = valueType as ArrayType; CustomAttributeArgument[] args = v as CustomAttributeArgument[]; var returnvalue = $"new {atype.FullName}{(atype.FullName.EndsWith("[]") ? "" : "[]")} {{ { string.Join(", ", args.Select(a => MakeAttributesValueString(a.Value, a.Type)).ToArray()) } }}"; return(returnvalue); } foreach (var formatter in formatters) { string formattedValue; if (formatter.TryFormatValue(v, type, out formattedValue)) { return(formattedValue); } } // this should never occur because the DefaultAttributeValueFormatter will always // successfully format the value ... but this is needed to satisfy the compiler :) throw new InvalidDataException(string.Format("Unable to format attribute value ({0})", v.ToString())); }
public override bool TryFormatValue(object v, ResolvedTypeInfo type, out string returnvalue) { returnvalue = "(" + MDocUpdater.GetDocTypeFullName(type.Reference) + ") " + MDocUpdater.FilterSpecialChars(v.ToString()); return(true); }