public static string Print(this FieldDefinition field, FieldPrintOptions options) { StringBuilder sb = new StringBuilder(); if ((options & FieldPrintOptions.Visibility) == FieldPrintOptions.Visibility) { AddVisibility(sb, field.IsPublic, field.IsPrivate, field.IsFamily, field.IsAssembly, field.IsFamilyOrAssembly); } if ((options & FieldPrintOptions.Modifiers) == FieldPrintOptions.Modifiers) { if (field.IsStatic && !field.HasConstant) { sb.Append("static "); } if (field.IsInitOnly) { sb.Append("readonly "); } if (field.HasConstant) { sb.Append("const "); } } string typeName = ""; if ((options & FieldPrintOptions.SimpleType) == FieldPrintOptions.SimpleType) { GenericInstanceType genType = field.FieldType as GenericInstanceType; if (genType != null) { typeName = genType.Print(); } else { typeName = field.FieldType.FullName; typeName = TypeMapper.FullToShort(typeName); } } sb.Append(typeName); sb.AppendFormat(" {0}", field.Name); if (((options & FieldPrintOptions.Value) == FieldPrintOptions.Value) && field.HasConstant) { sb.AppendFormat(" - Value: {0}", field.Constant); } return(sb.ToString()); }
public static string Print(this MethodDefinition method, MethodPrintOption options) { StringBuilder sb = new StringBuilder(); bool bPrintAlias = ((MethodPrintOption.ShortNames & MethodPrintOption.ShortNames) == MethodPrintOption.ShortNames); if ((MethodPrintOption.Visiblity & options) == MethodPrintOption.Visiblity) { AddVisibility(sb, method.IsPublic, method.IsPrivate, method.IsFamily, method.IsAssembly, method.IsFamilyOrAssembly); } if ((MethodPrintOption.Modifier & options) == MethodPrintOption.Modifier) { if (method.IsVirtual && method.HasBody) { sb.AppendFormat("{0} ", "virtual"); } if (method.IsStatic) { sb.AppendFormat("{0} ", "static"); } } if ((MethodPrintOption.ReturnType & options) == MethodPrintOption.ReturnType) { string retType = null; if (bPrintAlias) { GenericInstanceType generic = method.ReturnType as GenericInstanceType; if (generic != null) { retType = generic.Print(); } } if (retType == null) { retType = TypeMapper.FullToShort(method.ReturnType.FullName); } sb.AppendFormat("{0} ", retType); } sb.Append(method.Name); if ((options & MethodPrintOption.Parameters) == MethodPrintOption.Parameters) { PrintParameters(method.Parameters, sb, options); } return(sb.ToString()); }
static void PrintParameters(Collection <ParameterDefinition> parameters, StringBuilder sb, MethodPrintOption options) { bool bPrintNames = ((options & MethodPrintOption.ParamNames) == MethodPrintOption.ParamNames); sb.Append("("); for (int i = 0; i < parameters.Count; i++) { ParameterDefinition parameter = parameters[i]; if (parameter.IsOut) { sb.Append("out "); } string paramType = null; GenericInstanceType generic = parameter.ParameterType as GenericInstanceType; if (generic != null) { paramType = generic.Print(); } if (paramType == null) { paramType = parameter.ParameterType.Name; } // Ref types seem not to be correctly parsed by mono cecil so we leave the & syntax // inside it for the time beeing. if (parameter.IsOut) { paramType = paramType.TrimEnd(new char[] { '&' }); } sb.Append(paramType); if (bPrintNames) { sb.AppendFormat(" {0}", parameter.Name); } // parameter.Name if (i != parameters.Count - 1) { sb.Append(","); } } sb.Append(")"); }