protected override string GetEventDeclaration(EventDefinition e) { StringBuilder buf = new StringBuilder(); if (AppendVisibility(buf, e.AddMethod).Length == 0 && !IsPublicEII(e)) { return(null); } if (e.DeclaringType.IsInterface) { buf.Clear(); } AppendModifiers(buf, e.AddMethod); var context = AttributeParserContext.Create(e.AddMethod.Parameters[0]); var isNullableType = context.IsNullable(); buf.Append(buf.Length == 0 ? "event " : " event "); buf.Append(GetTypeName(e.EventType, context)); buf.Append(GetTypeNullableSymbol(e.EventType, isNullableType)); buf.Append(' '); buf.Append(e.Name).Append(';'); return(buf.ToString()); }
protected override string GetPropertyDeclaration(PropertyDefinition property) { MethodDefinition gm = null, sm = null; string get_visible = null; if ((gm = property.GetMethod) != null && (DocUtils.IsExplicitlyImplemented(gm) || (!gm.IsPrivate && !gm.IsAssembly && !gm.IsFamilyAndAssembly))) { get_visible = AppendVisibility(new StringBuilder(), gm).ToString(); } string set_visible = null; if ((sm = property.SetMethod) != null && (DocUtils.IsExplicitlyImplemented(sm) || (!sm.IsPrivate && !sm.IsAssembly && !sm.IsFamilyAndAssembly))) { set_visible = AppendVisibility(new StringBuilder(), sm).ToString(); } if ((set_visible == null) && (get_visible == null)) { return(null); } StringBuilder buf = new StringBuilder() .Append(".property "); if (!(gm ?? sm).IsStatic) { buf.Append("instance "); } _AppendTypeName(buf, property.PropertyType, AttributeParserContext.Create(property)); buf.Append(' ').Append(property.Name); if (!property.HasParameters || property.Parameters.Count == 0) { return(buf.ToString()); } buf.Append('('); bool first = true; foreach (ParameterDefinition p in property.Parameters) { if (!first) { buf.Append(", "); } first = false; _AppendTypeName(buf, p.ParameterType, AttributeParserContext.Create(p)); } buf.Append(')'); return(buf.ToString()); }
protected override string GetFieldDeclaration(FieldDefinition field) { TypeDefinition declType = (TypeDefinition)field.DeclaringType; if (declType.IsEnum && field.Name == "value__") { return(null); // This member of enums aren't documented. } StringBuilder buf = new StringBuilder(); AppendFieldVisibility(buf, field); if (buf.Length == 0) { return(null); } if (declType.IsEnum) { return(field.Name); } if (field.IsStatic && !field.IsLiteral) { buf.Append(" static"); } if (field.IsInitOnly) { buf.Append(" readonly"); } if (field.IsLiteral) { buf.Append(" const"); } buf.Append(' '); var context = AttributeParserContext.Create(field); var isNullableType = context.IsNullable(); buf.Append(GetTypeName(field.FieldType, context)); buf.Append(GetTypeNullableSymbol(field.FieldType, isNullableType)); buf.Append(' '); buf.Append(field.Name); DocUtils.AppendFieldValue(buf, field); buf.Append(';'); return(buf.ToString()); }
private StringBuilder AppendParameter(StringBuilder buf, ParameterDefinition parameter) { if (parameter.ParameterType is ByReferenceType) { if (parameter.IsOut) { buf.Append("out "); } else { buf.Append("ref "); } } if (parameter.HasCustomAttributes) { var isParams = parameter.CustomAttributes.Any(ca => ca.AttributeType.Name == "ParamArrayAttribute"); if (isParams) { buf.AppendFormat("params "); } } var context = AttributeParserContext.Create(parameter); var isNullableType = context.IsNullable(); buf.Append(GetTypeName(parameter.ParameterType, context)); buf.Append(GetTypeNullableSymbol(parameter.ParameterType, isNullableType)); buf.Append(" "); buf.Append(parameter.Name); if (parameter.HasDefault && parameter.IsOptional && parameter.HasConstant) { var ReturnVal = new AttributeFormatter().MakeAttributesValueString(parameter.Constant, parameter.ParameterType); buf.AppendFormat(" = {0}", ReturnVal == "null" ? "default" : ReturnVal); } return(buf); }
protected override string GetFieldDeclaration(FieldDefinition field) { TypeDefinition declType = (TypeDefinition)field.DeclaringType; if (declType.IsEnum && field.Name == "value__") { return(null); // This member of enums aren't documented. } StringBuilder buf = new StringBuilder(); AppendFieldVisibility(buf, field); if (buf.Length == 0) { return(null); } buf.Insert(0, ".field "); if (field.IsStatic) { buf.Append("static "); } if (field.IsInitOnly) { buf.Append("initonly "); } if (field.IsLiteral) { buf.Append("literal "); } _AppendTypeName(buf, field.FieldType, AttributeParserContext.Create(field)); buf.Append(' ').Append(field.Name); AppendFieldValue(buf, field); return(buf.ToString()); }
protected override string GetPropertyDeclaration(PropertyDefinition property) { MethodDefinition method; string get_visible = null; if ((method = property.GetMethod) != null && (DocUtils.IsExplicitlyImplemented(method) || (!method.IsPrivate && !method.IsAssembly && !method.IsFamilyAndAssembly))) { get_visible = AppendVisibility(new StringBuilder(), method).ToString(); } string set_visible = null; if ((method = property.SetMethod) != null && (DocUtils.IsExplicitlyImplemented(method) || (!method.IsPrivate && !method.IsAssembly && !method.IsFamilyAndAssembly))) { set_visible = AppendVisibility(new StringBuilder(), method).ToString(); } if ((set_visible == null) && (get_visible == null)) { return(null); } string visibility; StringBuilder buf = new StringBuilder(); if (get_visible != null && (set_visible == null || (set_visible != null && get_visible == set_visible))) { buf.Append(visibility = get_visible); } else if (set_visible != null && get_visible == null) { buf.Append(visibility = set_visible); } else { buf.Append(visibility = "public"); } // Pick an accessor to use for static/virtual/override/etc. checks. method = property.SetMethod; if (method == null) { method = property.GetMethod; } string modifiers = String.Empty; if (method.IsStatic) { modifiers += " static"; } if (method.IsVirtual && !method.IsAbstract) { if ((method.Attributes & MethodAttributes.NewSlot) != 0) { modifiers += " virtual"; } else { modifiers += " override"; } } TypeDefinition declDef = (TypeDefinition)method.DeclaringType; if (method.IsAbstract && !declDef.IsInterface) { modifiers += " abstract"; } if (method.IsFinal) { modifiers += " sealed"; } if (modifiers == " virtual sealed") { modifiers = ""; } buf.Append(modifiers).Append(' '); if (property.PropertyType.IsByReference) { buf.Append("ref "); } var context = AttributeParserContext.Create(property); var isNullableType = context.IsNullable(); var propertyReturnTypeName = GetTypeName(property.PropertyType, context); buf.Append(propertyReturnTypeName); buf.Append(GetTypeNullableSymbol(property.PropertyType, isNullableType)); buf.Append(' '); IEnumerable <MemberReference> defs = property.DeclaringType.GetDefaultMembers(); string name = property.Name; foreach (MemberReference mi in defs) { if (mi == property) { name = "this"; break; } } buf.Append(name == "this" ? name : DocUtils.GetPropertyName(property, NestedTypeSeparator)); if (property.Parameters.Count != 0) { AppendParameters(buf, method, property.Parameters, '[', ']'); } buf.Append(" {"); if (get_visible != null) { if (get_visible != visibility) { buf.Append(' ').Append(get_visible); } buf.Append(" get;"); } if (set_visible != null) { if (set_visible != visibility) { buf.Append(' ').Append(set_visible); } buf.Append(" set;"); } buf.Append(" }"); return(buf[0] != ' ' ? buf.ToString() : buf.ToString(1, buf.Length - 1)); }
protected override string GetTypeDeclaration(TypeDefinition type) { string visibility = GetTypeVisibility(type.Attributes); if (visibility == null) { return(null); } StringBuilder buf = new StringBuilder(); buf.Append(visibility); buf.Append(" "); MemberFormatter full = new CSharpFullMemberFormatter(this.TypeMap); if (DocUtils.IsDelegate(type)) { buf.Append("delegate "); MethodDefinition invoke = type.GetMethod("Invoke"); var context = AttributeParserContext.Create(invoke.MethodReturnType); var isNullableType = context.IsNullable(); buf.Append(full.GetName(invoke.ReturnType, context)); buf.Append(GetTypeNullableSymbol(invoke.ReturnType, isNullableType)); buf.Append(" "); buf.Append(GetName(type)); AppendParameters(buf, invoke, invoke.Parameters); AppendGenericTypeConstraints(buf, type); buf.Append(";"); return(buf.ToString()); } if (type.IsAbstract && !type.IsInterface) { buf.Append("abstract "); } if (type.IsSealed && !DocUtils.IsDelegate(type) && !type.IsValueType) { buf.Append("sealed "); } buf.Replace("abstract sealed", "static"); buf.Append(GetTypeKind(type)); buf.Append(" "); buf.Append(GetCSharpType(type.FullName) == null ? GetName(type) : type.Name); if (!type.IsEnum) { TypeReference basetype = type.BaseType; if (basetype != null && basetype.FullName == "System.Object" || type.IsValueType) // FIXME { basetype = null; } List <string> interface_names = DocUtils.GetUserImplementedInterfaces(type) .Select(iface => full.GetName(iface)) .OrderBy(s => s) .ToList(); if (basetype != null || interface_names.Count > 0) { buf.Append(" : "); } if (basetype != null) { buf.Append(full.GetName(basetype)); if (interface_names.Count > 0) { buf.Append(", "); } } for (int i = 0; i < interface_names.Count; i++) { if (i != 0) { buf.Append(", "); } buf.Append(interface_names[i]); } AppendGenericTypeConstraints(buf, type); } return(buf.ToString()); }
protected override string GetMethodDeclaration(MethodDefinition method) { if (method.IsPrivate && !DocUtils.IsExplicitlyImplemented(method)) { return(null); } var buf = new StringBuilder(); buf.Append(".method "); AppendVisibility(buf, method); if (method.IsStatic) { buf.Append("static "); } if (method.IsHideBySig) { buf.Append("hidebysig "); } if (method.IsPInvokeImpl && method.PInvokeInfo != null) { var info = method.PInvokeInfo; buf.Append("pinvokeimpl (\"") .Append(info.Module.Name) .Append("\" as \"") .Append(info.EntryPoint) .Append("\""); if (info.IsCharSetAuto) { buf.Append(" auto"); } if (info.IsCharSetUnicode) { buf.Append(" unicode"); } if (info.IsCharSetAnsi) { buf.Append(" ansi"); } if (info.IsCallConvCdecl) { buf.Append(" cdecl"); } if (info.IsCallConvStdCall) { buf.Append(" stdcall"); } if (info.IsCallConvWinapi) { buf.Append(" winapi"); } if (info.IsCallConvThiscall) { buf.Append(" thiscall"); } if (info.SupportsLastError) { buf.Append(" lasterr"); } buf.Append(")"); } if (method.IsSpecialName) { buf.Append("specialname "); } if (method.IsRuntimeSpecialName) { buf.Append("rtspecialname "); } if (method.IsNewSlot) { buf.Append("newslot "); } if (method.IsVirtual) { buf.Append("virtual "); } if (!method.IsStatic) { buf.Append("instance "); } _AppendTypeName(buf, method.ReturnType, AttributeParserContext.Create(method.MethodReturnType)); buf.Append(' ') .Append(method.Name); if (method.IsGenericMethod()) { var state = MemberFormatterState; MemberFormatterState = MemberFormatterState.WithinGenericTypeParameters; IList <GenericParameter> args = method.GenericParameters; if (args.Count > 0) { buf.Append("<"); _AppendTypeName(buf, args[0], null); for (int i = 1; i < args.Count; ++i) { _AppendTypeName(buf.Append(", "), args[i], null); } buf.Append(">"); } MemberFormatterState = state; } buf.Append('('); bool first = true; for (int i = 0; i < method.Parameters.Count; ++i) { var param = method.Parameters[i]; if (!first) { buf.Append(", "); } first = false; if (param.IsOut) { buf.Append("[out] "); } else if (param.IsIn) { buf.Append("[in]"); } _AppendTypeName(buf, param.ParameterType, AttributeParserContext.Create(param)); if (param.ParameterType.IsByReference) { buf.Append("&"); } buf.Append(' '); buf.Append(param.Name); } buf.Append(')'); if (method.IsIL) { buf.Append(" cil"); } if (method.IsRuntime) { buf.Append(" runtime"); } if (method.IsManaged) { buf.Append(" managed"); } return(buf.ToString()); }