protected override string GetPropertyDeclaration(PropertyDefinition property) { bool getVisible = property.GetMethod != null && property.GetMethod.IsPublic; bool setVisible = property.SetMethod != null && property.SetMethod.IsPublic; var method = property.SetMethod ?? property.GetMethod; // https://github.com/mono/api-doc-tools/issues/133 // var [property value type, camel-cased] = [typename, camel-cased].[property name, camel-cased]; // [typename, camel-cased].[property name, camel-cased] = [property value type, camel-cased]; // Static properties // var [property value type, camel-cased] = [typename].[property name, camel-cased]; // [typename].[property name, camel-cased] = [property value type, camel-cased]; var buf = new StringBuilder(); var propertyValueType = CamelCase(GetName(property.PropertyType)); var propertyName = DocUtils.GetPropertyName(property, NestedTypeSeparator); var propertyNameCamelCased = CamelCase(propertyName); var typeName = GetName(property.DeclaringType); if (!method.IsStatic) { typeName = CamelCase(typeName); } if (getVisible) { buf.Append("var "); buf.Append(propertyValueType); buf.Append(" = "); buf.Append(typeName); buf.Append("."); buf.Append(propertyNameCamelCased); buf.Append(";"); } if (setVisible) { if (getVisible) { buf.Append(GetLineEnding()); } buf.Append(typeName); buf.Append("."); buf.Append(propertyNameCamelCased); buf.Append(" = "); buf.Append(propertyValueType); buf.Append(";"); } return(buf.ToString()); }
protected override string GetPropertyDeclaration(PropertyDefinition property) { var propVisib = GetPropertyVisibility(property, out var getVisible, out var setVisible); var buf = new StringBuilder(); buf.Append(propVisib); // Pick an accessor to use for static/virtual/override/etc. checks. var method = property.SetMethod ?? property.GetMethod; string modifiers = String.Empty; if (method.IsStatic) { modifiers += " static"; } if (method.IsVirtual && !method.IsAbstract) { if (((method.Attributes & MethodAttributes.SpecialName) != 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(' ').Append("property "); var typeName = GetTypeNameWithOptions(property.PropertyType, AppendHatOnReturn); buf.Append(typeName).Append(' '); IEnumerable <MemberReference> defs = property.DeclaringType.GetDefaultMembers(); string propertyName = property.Name; foreach (MemberReference mi in defs) { if (mi == property) { propertyName = "default"; break; } } buf.Append(propertyName == "default" ? propertyName : DocUtils.GetPropertyName(property, NestedTypeSeparator)); bool hasParams = false; if (property.Parameters.Count != 0) { hasParams = true; buf.Append('['); buf.Append(GetTypeNameWithOptions(property.Parameters[0].ParameterType, AppendHatOnReturn)); for (int i = 1; i < property.Parameters.Count; ++i) { buf.Append(", "); buf.Append(GetTypeNameWithOptions(property.Parameters[i].ParameterType, AppendHatOnReturn)); } buf.Append(']'); } buf.Append(" { "); if (getVisible != null) { if (getVisible != propVisib) { buf.Append(' ').Append(getVisible); } buf.AppendFormat("{0} get", typeName); if (hasParams) { AppendParameters(buf, property.Parameters, '(', ')'); } else { buf.Append("()"); } buf.Append(";"); } if (setVisible != null) { if (setVisible != propVisib) { buf.Append(' ').Append(setVisible); } buf.Append(' ').AppendFormat("void set("); if (hasParams) {//no need for braces since they are added in other place AppendParameters(buf, property.Parameters, null, null); buf.Append(", "); } buf.AppendFormat("{0} value)", typeName); buf.Append(";"); } buf.Append(" };"); return(buf[0] != ' ' ? buf.ToString() : buf.ToString(1, buf.Length - 1)); }
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 "); } buf.Append(GetTypeName(property.PropertyType, new DynamicParserContext(property))).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)); }