Ejemplo n.º 1
0
        protected override string GetEventDeclaration(EventDefinition e)
        {
            StringBuilder buf         = new StringBuilder();
            bool          isPublicEII = IsPublicEII(e);

            if (AppendVisibility(buf, e.AddMethod).Length == 0 && !isPublicEII)
            {
                return(null);
            }
            if (e.DeclaringType.IsInterface) // There is no access modifiers in interfaces
            {
                buf.Clear();
            }
            AppendModifiers(buf, e.AddMethod);
            if (e.AddMethod.CustomAttributes.All(
                    i => i.AttributeType.FullName != Consts.CompilerGeneratedAttribute) &&
                !e.DeclaringType.IsInterface)   // There is no 'Custom' modifier in interfaces
            {
                if (buf.Length > 0)
                {
                    buf.Append(' ');
                }
                buf.Append("Custom");
            }

            if (buf.Length > 0)
            {
                buf.Append(' ');
            }
            buf.Append("Event ");
            if (isPublicEII)
            {
                buf.Append(e.Name.Split('.').Last());
            }
            else
            {
                buf.Append(e.Name);
            }
            buf.Append(" As ").Append(GetTypeName(e.EventType, AttributeParserContext.Create(e.AddMethod.Parameters[0]))).Append(' ');
            if (isPublicEII)
            {
                var dotIndex = e.Name.LastIndexOf('.');
                dotIndex = dotIndex > -1 ? dotIndex : e.Name.Length;
                buf.Append($"Implements {e.Name.Substring(0, dotIndex)}");
            }

            return(buf.ToString());
        }
Ejemplo n.º 2
0
        private void AppendParameter(StringBuilder buf, ParameterDefinition parameter)
        {
            bool isFSharpFunction = IsFSharpFunction(parameter.ParameterType);

            if (isFSharpFunction)
            {
                buf.Append("(");
            }
            var typeName = GetTypeName(parameter.ParameterType, AttributeParserContext.Create(parameter));

            buf.Append(typeName);
            if (isFSharpFunction)
            {
                buf.Append(")");
            }
        }
Ejemplo n.º 3
0
        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.
            }
            var visibility = GetFieldVisibility(field);

            if (visibility == null)
            {
                return(null);
            }
            var buf = new StringBuilder();

            if (declType.IsEnum)
            {
                buf.Append(field.Name);
                if (field.IsLiteral)
                {
                    buf.Append($" = {field.Constant}");
                }
                return(buf.ToString());
            }
            if (field.IsStatic && !field.IsLiteral)
            {
                buf.Append(" static");
            }

            buf.Append("val mutable");
            if (!string.IsNullOrEmpty(visibility))
            {
                buf.Append(" ");
            }
            buf.Append(visibility);
            buf.Append(" ");
            buf.Append(field.Name);
            buf.Append(" : ");
            buf.Append(GetTypeName(field.FieldType, AttributeParserContext.Create(field)));

            return(buf.ToString());
        }
Ejemplo n.º 4
0
        protected override string GetEventDeclaration(EventDefinition e)
        {
            StringBuilder buf           = new StringBuilder();
            StringBuilder visibilityBuf = new StringBuilder();

            if (AppendVisibility(visibilityBuf, e.AddMethod) == null)
            {
                return(null);
            }

            buf.Append("member this.");
            if (visibilityBuf.Length > 0)
            {
                buf.Append(visibilityBuf).Append(' ');
            }
            buf.Append(e.Name).Append(" : ");
            buf.Append(GetTypeName(e.EventType, AttributeParserContext.Create(e.AddMethod.Parameters[0]))).Append(' ');

            return(buf.ToString());
        }
Ejemplo n.º 5
0
        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 && !IsModule(field.DeclaringType))
            {
                buf.Append(" Shared");
            }
            if (field.IsInitOnly)
            {
                buf.Append(" ReadOnly");
            }
            if (field.IsLiteral)
            {
                buf.Append(" Const");
            }

            buf.Append(' ').Append(field.Name);
            buf.Append(" As ").Append(GetTypeName(field.FieldType, AttributeParserContext.Create(field))).Append(' ');
            DocUtils.AppendFieldValue(buf, field);

            return(buf.ToString());
        }
Ejemplo n.º 6
0
        protected void AppendRecordParameter(StringBuilder buf, PropertyDefinition property)
        {
            bool hasParameterName = !string.IsNullOrEmpty(property.Name);

            if (property.SetMethod != null && property.SetMethod.IsPublic)
            {
                buf.Append("mutable ");
            }
            if (hasParameterName)
            {
                buf.Append(property.Name.TrimEnd('@'));
            }

            if (property.PropertyType.FullName != "System.Object")
            {
                var typeName = GetTypeName(property.PropertyType, AttributeParserContext.Create(property));
                if (hasParameterName)
                {
                    buf.Append(" : ");
                }
                buf.Append(typeName);
            }
        }
Ejemplo n.º 7
0
        protected override string GetPropertyDeclaration(PropertyDefinition property)
        {
            string getVisible = null;

            if (DocUtils.IsAvailablePropertyMethod(property.GetMethod))
            {
                getVisible = AppendVisibility(new StringBuilder(), property.GetMethod).ToString();
            }
            string setVisible = null;

            if (DocUtils.IsAvailablePropertyMethod(property.SetMethod))
            {
                setVisible = AppendVisibility(new StringBuilder(), property.SetMethod).ToString();
            }

            if (setVisible == null && getVisible == null)
            {
                return(null);
            }

            StringBuilder buf = new StringBuilder();
            IEnumerable <MemberReference> defs = property.DeclaringType.GetDefaultMembers();
            bool indexer = false;

            foreach (MemberReference mi in defs)
            {
                if (mi == property)
                {
                    indexer = true;
                    break;
                }
            }
            if (indexer)
            {
                buf.Append("Default ");
            }
            if (getVisible != null && (setVisible == null || (setVisible != null && getVisible == setVisible)))
            {
                buf.Append(getVisible);
            }
            else if (setVisible != null && getVisible == null)
            {
                buf.Append(setVisible);
            }
            else
            {
                buf.Append("Public");
            }

            // Pick an accessor to use for static/virtual/override/etc. checks.
            var method = property.SetMethod;

            if (method == null)
            {
                method = property.GetMethod;
            }

            string modifiers = String.Empty;

            if (method.IsStatic && !IsModule(method.DeclaringType))
            {
                modifiers += " Shared";
            }
            if (method.IsVirtual && !method.IsAbstract)
            {
                if ((method.Attributes & MethodAttributes.NewSlot) != 0)
                {
                    modifiers += " Overridable";
                }
                else
                {
                    modifiers += " Overrides";
                }
            }
            TypeDefinition declDef = (TypeDefinition)method.DeclaringType;

            if (method.IsAbstract && !declDef.IsInterface)
            {
                modifiers += " MustOverride";
            }
            if (method.IsFinal)
            {
                modifiers += " NotOverridable";
            }
            if (modifiers == " MustOverride NotOverridable")
            {
                modifiers = "";
            }
            if (modifiers == " Overridable NotOverridable")
            {
                modifiers = "";
            }
            buf.Append(modifiers).Append(' ');

            if (getVisible != null && setVisible == null)
            {
                buf.Append("ReadOnly ");
            }

            buf.Append("Property ");
            buf.Append(property.Name.Split('.').Last());

            if (property.Parameters.Count != 0)
            {
                AppendParameters(buf, method, property.Parameters, '(', ')');
            }
            buf.Append(" As ");
            buf.Append(GetTypeName(property.PropertyType, AttributeParserContext.Create(property)));
            if (DocUtils.IsExplicitlyImplemented(property.GetMethod))
            {
                TypeReference   iface;
                MethodReference ifaceMethod;
                DocUtils.GetInfoForExplicitlyImplementedMethod(method, out iface, out ifaceMethod);
                buf.Append(" Implements ")
                .Append(new VBMemberFormatter(this.TypeMap).GetName(iface))
                .Append('.')
                .Append(DocUtils.GetPropertyName(property, NestedTypeSeparator).Split('.').Last());
            }
            return(buf.ToString());
        }
Ejemplo n.º 8
0
        protected override string GetMethodDeclaration(MethodDefinition method)
        {
            if (method.HasCustomAttributes && method.CustomAttributes.Cast <CustomAttribute>().Any(
                    ca => ca.GetDeclaringType() == "System.Diagnostics.Contracts.ContractInvariantMethodAttribute"))
            {
                return(null);
            }


            // Special signature for destructors.
            if (method.Name == "Finalize" && method.Parameters.Count == 0)
            {
                return(GetFinalizerName(method));
            }

            StringBuilder buf = new StringBuilder();

            if (DocUtils.IsExtensionMethod(method))
            {
                buf.Append("<Extension()>" + GetLineEnding());
            }

            AppendVisibility(buf, method);
            if (buf.Length == 0 &&
                !(DocUtils.IsExplicitlyImplemented(method) && !method.IsSpecialName))
            {
                return(null);
            }

            AppendModifiers(buf, method);
            if (buf.Length != 0)
            {
                buf.Append(" ");
            }
            bool isFunction = method.MethodReturnType.ReturnType.FullName != "System.Void";

            if (!DocUtils.IsOperator(method))
            {
                if (isFunction)
                {
                    buf.Append("Function ");
                }
                else
                {
                    buf.Append("Sub ");
                }
            }
            AppendMethodName(buf, method);

            AppendGenericMethod(buf, method).Append(" ");
            AppendParameters(buf, method, method.Parameters);
            AppendGenericMethodConstraints(buf, method);
            if (isFunction)
            {
                buf.Append(" As ").Append(GetTypeName(method.ReturnType, AttributeParserContext.Create(method.MethodReturnType)));
            }

            if (DocUtils.IsExplicitlyImplemented(method))
            {
                TypeReference   iface;
                MethodReference ifaceMethod;
                DocUtils.GetInfoForExplicitlyImplementedMethod(method, out iface, out ifaceMethod);
                buf.Append(" Implements ")
                .Append(new VBMemberFormatter(this.TypeMap).GetName(iface))
                .Append('.')
                .Append(ifaceMethod.Name);
            }

            return(buf.ToString());
        }
Ejemplo n.º 9
0
        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 VBMemberFormatter(this.TypeMap);

            if (DocUtils.IsDelegate(type))
            {
                buf.Append("Delegate ");
                MethodDefinition invoke     = type.GetMethod("Invoke");
                bool             isFunction = invoke.ReturnType.FullName != "System.Void";
                if (isFunction)
                {
                    buf.Append("Function ");
                }
                else
                {
                    buf.Append("Sub ");
                }
                buf.Append(GetName(type));
                AppendParameters(buf, invoke, invoke.Parameters);
                if (isFunction)
                {
                    buf.Append(" As ");
                    buf.Append(full.GetName(invoke.ReturnType, AttributeParserContext.Create(invoke.MethodReturnType))).Append(" ");
                }

                return(buf.ToString());
            }

            if (type.IsAbstract && !type.IsInterface && !IsModule(type))
            {
                buf.Append("MustInherit ");
            }
            if (type.IsSealed && !DocUtils.IsDelegate(type) && !type.IsValueType && !IsModule(type))
            {
                buf.Append("NotInheritable ");
            }
            buf.Replace(" MustInherit NotInheritable", "");

            buf.Append(GetTypeKind(type));
            buf.Append(" ");
            buf.Append(GetVBType(type.FullName) == null
                    ? GetName(type)
                    : type.Name);

            if (!type.IsEnum)
            {
                TypeReference basetype = type.BaseType;
                if (basetype != null && basetype.FullName == "System.Object" || type.IsValueType)
                {
                    basetype = null;
                }

                if (basetype != null)
                {
                    buf.Append(GetLineEnding()).Append("Inherits ");
                    buf.Append(full.GetName(basetype));
                }

                List <string> interfaceNames = DocUtils.GetUserImplementedInterfaces(type)
                                               .Select(iface => full.GetName(iface))
                                               .OrderBy(s => s)
                                               .ToList();
                if (interfaceNames.Count > 0)
                {
                    buf.Append(GetLineEnding()).Append("Implements ");
                    buf.Append(string.Join(", ", interfaceNames));
                }
            }

            return(buf.ToString());
        }