예제 #1
0
        private void WriteExtensionMethodSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string            name       = (string)reflection.Evaluate(apiNameExpression);
            XPathNavigator    returnType = reflection.SelectSingleNode(apiReturnTypeExpression);
            XPathNodeIterator parameters = reflection.Select(apiParametersExpression);

            // extract the first parameter as the extension type
            parameters.MoveNext();
            XPathNavigator extendedType     = parameters.Current.SelectSingleNode(parameterTypeExpression);
            string         extendedTypeName = (string)parameters.Current.Evaluate(parameterNameExpression);

            // write the declarations
            ParameterDeclaration(extendedTypeName, extendedType, writer);
            WriteParameterDeclarations(parameters.Clone(), writer);
            if (returnType != null)
            {
                ParameterDeclaration("returnValue", returnType, writer);
            }
            writer.WriteLine();

            // write the method invocation
            if (returnType != null)
            {
                writer.WriteParameter("returnValue");
                writer.WriteString(" = ");
            }
            writer.WriteParameter(extendedTypeName);
            writer.WriteString(".");
            writer.WriteIdentifier(name);
            writer.WriteString("(");
            WriteParameters(parameters.Clone(), writer);
            writer.WriteString(")");
        }
예제 #2
0
        private void WriteParameters(XPathNodeIterator parameters, SyntaxWriter writer)
        {
            while (parameters.MoveNext())
            {
                XPathNavigator parameter = parameters.Current;
                string         name      = (string)parameter.Evaluate(parameterNameExpression);
                writer.WriteParameter(name);

                if (parameters.CurrentPosition < parameters.Count)
                {
                    writer.WriteString(", ");

                    if (writer.Position > MaxPosition)
                    {
                        if (includeLineContinuation)
                        {
                            writer.WriteString("_");
                        }

                        writer.WriteLine();
                        writer.WriteString("\t");
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Write out event syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteEventSyntax(XPathNavigator reflection,
                                              SyntaxWriter writer)
        {
            if (!this.IsUnsupported(reflection, writer))
            {
                if (reflection.Select(
                        SyntaxGeneratorTemplate.apiParametersExpression).Count > 0)
                {
                    writer.WriteMessage("UnsupportedIndex_" + this.Language);
                }
                else
                {
                    string identifier = ReadMemberName(reflection);

                    writer.WriteKeyword("function");
                    writer.WriteString(" add_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString("(");
                    writer.WriteParameter("value");
                    writer.WriteString(");");
                    writer.WriteLine();
                    writer.WriteKeyword("function");
                    writer.WriteString(" remove_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString("(");
                    writer.WriteParameter("value");
                    writer.WriteString(");");
                }
            }
        }
        /// <summary>
        /// Write out enumeration syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteEnumerationSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            string identifier = ReadFullTypeName(reflection);

            writer.WriteIdentifier(identifier);
            writer.WriteString(" = ");
            writer.WriteKeyword("function");
            writer.WriteString("();");
            writer.WriteLine();
            writer.WriteIdentifier(identifier);
            writer.WriteString(".createEnum('");
            writer.WriteIdentifier(identifier);
            writer.WriteString("', ");
            writer.WriteString(HasAttribute(reflection, "System.FlagsAttribute") ? "true" : "false");
            writer.WriteString(");");
        }
예제 #5
0
        private static void WriteAttribute(string reference, SyntaxWriter writer, bool newline)
        {
            writer.WriteString("/** @attribute ");
            writer.WriteReferenceLink(reference);
            writer.WriteString(" */ ");

            if (newline)
            {
                writer.WriteLine();
            }
        }
예제 #6
0
        // Parameters

        private void WriteMethodParameters(XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNodeIterator parameters = reflection.Select(apiParametersExpression);

            writer.WriteString("(");
            if (parameters.Count > 0)
            {
                writer.WriteLine();
                WriteParameters(parameters, writer);
            }
            writer.WriteString(")");
        }
예제 #7
0
        // A grandiose Property Element Usage block
        // syntax looks like:
        //   <object>
        //     <object.PropertyName>
        //       <linkToType .../>
        //     </object.PropertyName>
        //   </object>
        private void PropertyElementUsageGrande(XPathNavigator propertyReflection, SyntaxWriter writer)
        {
            string         xamlBlockId  = Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlPropertyElementUsageHeading);
            string         propertyName = (string)propertyReflection.Evaluate(apiNameExpression);
            XPathNavigator returnType   = propertyReflection.SelectSingleNode(apiReturnTypeExpression);

            // start the syntax block
            writer.WriteStartSubBlock(xamlBlockId);

            //   <object>
            writer.WriteString("<");
            writer.WriteParameter("object");
            writer.WriteString(">");
            writer.WriteLine();
            //     <object.PropertyName>
            writer.WriteString("  <");
            writer.WriteParameter("object");
            writer.WriteString(".");
            writer.WriteIdentifier(propertyName);
            writer.WriteString(">");
            writer.WriteLine();
            //       <linkToType .../>
            writer.WriteString("    <");
            WriteTypeReference(returnType, writer);
            writer.WriteString(" .../>");
            writer.WriteLine();
            //     </object.PropertyName>
            writer.WriteString("  </");
            writer.WriteParameter("object");
            writer.WriteString(".");
            writer.WriteIdentifier(propertyName);
            writer.WriteString(">");
            writer.WriteLine();
            //   </object>
            writer.WriteString("</");
            writer.WriteParameter("object");
            writer.WriteString(">");

            writer.WriteEndSubBlock();
        }
예제 #8
0
        /// <inheritdoc />
        public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            // !EFW - Added unsafe check
            if (IsUnsupportedUnsafe(reflection, writer))
            {
                return;
            }

            bool           isStatic      = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool           isFamily      = (bool)reflection.Evaluate(apiIsFamilyMemberExpression);
            XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);
            XPathNavigator handler       = reflection.SelectSingleNode(apiHandlerOfEventExpression);

            if (!(isStatic | isFamily))
            {
                ParameterDeclaration("instance", declaringType, writer);
            }

            ParameterDeclaration("handler", handler, writer);

            // adder
            writer.WriteLine();
            writer.WriteKeyword("AddHandler");
            writer.WriteString(" ");
            WriteMemberName(reflection, writer);
            writer.WriteString(", ");
            writer.WriteParameter("handler");
            writer.WriteLine();
        }
예제 #9
0
        /// <inheritdoc />
        public override void WriteNormalMethodSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            bool isExtension = (bool)reflection.Evaluate(apiIsExtensionMethod);

            if (isExtension)
            {
                WriteExtensionMethodSyntax(reflection, writer);
            }
            else
            {
                //string name = (string)reflection.Evaluate(apiNameExpression);
                XPathNavigator returnType    = reflection.SelectSingleNode(apiReturnTypeExpression);
                XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);
                //bool isExplicit = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);
                bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
                bool isFamily = (bool)reflection.Evaluate(apiIsFamilyMemberExpression);

                if (!(isStatic || isFamily))
                {
                    ParameterDeclaration("instance", declaringType, writer);
                }
                WriteParameterDeclarations(reflection, writer);
                if (returnType != null)
                {
                    ParameterDeclaration("returnValue", returnType, writer);
                }
                writer.WriteLine();

                if (returnType != null)
                {
                    writer.WriteParameter("returnValue");
                    writer.WriteString(" = ");
                }

                WriteMemberName(reflection, writer);
                WriteMethodParameters(reflection, writer);
            }
        }
예제 #10
0
        /// <inheritdoc />
        public override void WriteConstructorSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (IsUnsupportedUnsafe(reflection, writer))
            {
                return;
            }

            XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);

            // if static, no usage

            WriteParameterDeclarations(reflection, writer);
            writer.WriteLine();
            writer.WriteKeyword("Dim");
            writer.WriteString(" ");
            writer.WriteParameter("instance");
            writer.WriteString(" ");
            writer.WriteKeyword("As New");
            writer.WriteString(" ");

            string typeName = (string)declaringType.Evaluate(apiNameExpression);

            if (reservedWords.Contains(typeName))
            {
                writer.WriteString("[");
                WriteTypeReference(declaringType, writer);
                writer.WriteString("]");
            }
            else
            {
                WriteTypeReference(declaringType, writer);
            }

            WriteMethodParameters(reflection, writer);
        }
예제 #11
0
        /// <summary>
        /// Write out interface syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteInterfaceSyntax(XPathNavigator reflection,
                                                  SyntaxWriter writer)
        {
            if (!this.IsUnsupported(reflection, writer))
            {
                string identifier = ReadFullTypeName(reflection);

                writer.WriteIdentifier(identifier);
                writer.WriteString(" = ");
                writer.WriteKeyword("function");
                writer.WriteString("();");
                writer.WriteLine();
                writer.WriteIdentifier(identifier);
                writer.WriteString(".createInterface('");
                writer.WriteIdentifier(identifier);
                writer.WriteString("');");
            }
        }
예제 #12
0
        /// <summary>
        /// Write out enumeration syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteEnumerationSyntax(XPathNavigator reflection,
                                                    SyntaxWriter writer)
        {
            string identifier = ReadFullTypeName(reflection);

            writer.WriteIdentifier(identifier);
            writer.WriteString(" = ");
            writer.WriteKeyword("function");
            writer.WriteString("();");
            writer.WriteLine();
            writer.WriteIdentifier(identifier);
            writer.WriteString(".createEnum('");
            writer.WriteIdentifier(identifier);
            writer.WriteString("', ");
            writer.WriteString(HasAttribute(reflection,
                                            "System.FlagsAttribute") ? "true" : "false");
            writer.WriteString(");");
        }
예제 #13
0
        private void WriteMethodThrows(XPathNodeIterator exceptions, XPathNavigator reflection, SyntaxWriter writer)
        {
            writer.WriteString(" ");
            writer.WriteKeyword("throws");
            writer.WriteString(" ");

            while (exceptions.MoveNext())
            {
                XPathNavigator exception = exceptions.Current;

                WriteTypeReference(exception, writer);

                if (exceptions.CurrentPosition < exceptions.Count)
                {
                    writer.WriteString(",");
                }
                writer.WriteLine();
            }
        }
예제 #14
0
        /// <inheritdoc />
        public override void WriteDelegateSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (IsUnsupportedUnsafe(reflection, writer))
            {
                return;
            }
            if (IsUnsupportedGeneric(reflection, writer))
            {
                return;
            }

            string name           = (string)reflection.Evaluate(apiNameExpression);
            bool   isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);

            writer.WriteString("/** @delegate */");
            writer.WriteLine();

            if (isSerializable)
            {
                WriteAttribute("T:System.SerializableAttribute", writer);
            }

            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            writer.WriteKeyword("delegate");
            writer.WriteString(" ");
            WriteReturnValue(reflection, writer);
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteMethodParameters(reflection, writer);
        }
예제 #15
0
        /// <inheritdoc />
        public override void WriteCastSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            XPathNavigator parameter = reflection.SelectSingleNode(apiParametersExpression);

            if (parameter == null)
            {
                return;
            }

            XPathNavigator inputType  = parameter.SelectSingleNode(typeExpression);
            XPathNavigator outputType = reflection.SelectSingleNode(apiReturnTypeExpression);

            if ((inputType == null) || (outputType == null))
            {
                return;
            }

            ParameterDeclaration("input", inputType, writer);
            ParameterDeclaration("output", outputType, writer);

            writer.WriteLine();
            writer.WriteParameter("output");
            writer.WriteString(" = ");
            writer.WriteKeyword("CType");
            writer.WriteString("(");
            writer.WriteParameter("input");
            writer.WriteString(", ");

            WriteTypeReference(outputType, writer);

            writer.WriteString(")");
        }
        /// <summary>
        /// Write out event syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (!this.IsUnsupported(reflection, writer))
            {
                if (reflection.Select(apiParametersExpression).Count > 0)
                {
                    writer.WriteMessage("UnsupportedIndex_" + this.Language);
                }
                else
                {
                    string identifier = ReadMemberName(reflection);

                    writer.WriteKeyword("function");
                    writer.WriteString(" add_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString("(");
                    writer.WriteParameter("value");
                    writer.WriteString(");");
                    writer.WriteLine();
                    writer.WriteKeyword("function");
                    writer.WriteString(" remove_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString("(");
                    writer.WriteParameter("value");
                    writer.WriteString(");");
                }
            }
        }
예제 #17
0
        private void ParameterDeclaration(string name, XPathNavigator type, SyntaxWriter writer)
        {
            writer.WriteKeyword("Dim");
            writer.WriteString(" ");
            writer.WriteParameter(name);
            writer.WriteString(" ");
            writer.WriteKeyword("As");
            writer.WriteString(" ");

            string typeName = (string)type.Evaluate(apiNameExpression);

            if (reservedWords.Contains(typeName))
            {
                writer.WriteString("[");
                WriteTypeReference(type, writer);
                writer.WriteString("]");
            }
            else
            {
                WriteTypeReference(type, writer);
            }

            writer.WriteLine();
        }
        /// <summary>
        /// This is used to write a string followed by an optional line break if needed (the writer position is
        /// past the maximum position afterwards).
        /// </summary>
        /// <param name="writer">The syntax writer to use</param>
        /// <param name="text">An optional text string to write before the new line</param>
        /// <param name="indent">An optional indent to write after the line break</param>
        /// <returns>True if a new line was written, false if not</returns>
        private bool WriteWithLineBreakIfNeededVB(SyntaxWriter writer, string text, string indent)
        {
            if(!String.IsNullOrEmpty(text))
                writer.WriteString(text);

            if(writer.Position > MaxPosition)
            {
                if(includeLineContinuation)
                    writer.WriteString(" _");

                writer.WriteLine();

                if(!String.IsNullOrEmpty(indent))
                    writer.WriteString(indent);

                return true;
            }

            return false;
        }
        private void WriteImplementedInterfaces(XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNodeIterator implements = reflection.Select(apiImplementedInterfacesExpression);

            if(implements.Count != 0)
            {
                if(includeLineContinuation)
                    writer.WriteString(" _");

                writer.WriteLine();
                writer.WriteString("\t");

                string subgroup = (string)reflection.Evaluate(apiSubgroupExpression);

                if(subgroup == "interface")
                    writer.WriteKeyword("Inherits");
                else
                    writer.WriteKeyword("Implements");

                writer.WriteString(" ");

                while(implements.MoveNext())
                {
                    XPathNavigator implement = implements.Current;

                    if(implements.CurrentPosition > 1)
                        this.WriteWithLineBreakIfNeededVB(writer, ", ", "\t");

                    WriteTypeReference(implement, writer);
                }
            }
        }
예제 #20
0
        // A grandiose Property Element Usage block
        // syntax looks like: 
        //   <object>
        //     <object.PropertyName>
        //       <linkToType .../>
        //     </object.PropertyName>
        //   </object>
        private void PropertyElementUsageGrande(XPathNavigator propertyReflection, SyntaxWriter writer)
        {
            string xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlPropertyElementUsageHeading);
            string propertyName = (string)propertyReflection.Evaluate(apiNameExpression);
            XPathNavigator returnType = propertyReflection.SelectSingleNode(apiReturnTypeExpression);

            // start the syntax block
            writer.WriteStartSubBlock(xamlBlockId);

            //   <object>
            writer.WriteString("<");
            writer.WriteParameter("object");
            writer.WriteString(">");
            writer.WriteLine();
            //     <object.PropertyName>
            writer.WriteString("  <");
            writer.WriteParameter("object");
            writer.WriteString(".");
            writer.WriteIdentifier(propertyName);
            writer.WriteString(">");
            writer.WriteLine();
            //       <linkToType .../>
            writer.WriteString("    <");
            WriteTypeReference(returnType, writer);
            writer.WriteString(" .../>");
            writer.WriteLine();
            //     </object.PropertyName>
            writer.WriteString("  </");
            writer.WriteParameter("object");
            writer.WriteString(".");
            writer.WriteIdentifier(propertyName);
            writer.WriteString(">");
            writer.WriteLine();
            //   </object>
            writer.WriteString("</");
            writer.WriteParameter("object");
            writer.WriteString(">");

            writer.WriteEndSubBlock();
        }
예제 #21
0
        private void WriteParameters(XPathNodeIterator parameters, SyntaxWriter writer)
        {
            while(parameters.MoveNext())
            {
                XPathNavigator parameter = parameters.Current;

                // !EFW - Added support for optional parameter values
                XPathNavigator argument = (XPathNavigator)parameter.SelectSingleNode(parameterArgumentExpression);
                bool isOptional = (bool)parameter.Evaluate(parameterIsOptionalExpression);

                string name = (string)parameter.Evaluate(parameterNameExpression);
                XPathNavigator type = parameter.SelectSingleNode(parameterTypeExpression);
                bool isIn = (bool)parameter.Evaluate(parameterIsInExpression);
                bool isOut = (bool)parameter.Evaluate(parameterIsOutExpression);
                bool isRef = (bool)parameter.Evaluate(parameterIsRefExpression);

                writer.WriteString("\t");

                // !EFW - Optional indicated by OptionalAttribute?
                if(isOptional && argument == null)
                    WriteAttribute("T:System.Runtime.InteropServices.OptionalAttribute", writer, false);

                if(isIn)
                    WriteAttribute("T:System.Runtime.InteropServices.InAttribute", writer, false);

                if(isOut)
                    WriteAttribute("T:System.Runtime.InteropServices.OutAttribute", writer, false);

                // !EFW - Write out parameter attributes
                WriteAttributes(parameter, writer, true);

                if(isRef)
                    writer.WriteString("/** @ref */");

                WriteTypeReference(type, writer);
                writer.WriteString(" ");
                writer.WriteParameter(name);

                // !EFW - Write optional value if present
                if(argument != null)
                {
                    writer.WriteString(" = ");
                    this.WriteValue(argument, writer);
                }

                if(parameters.CurrentPosition < parameters.Count)
                    writer.WriteString(",");

                writer.WriteLine();
            }
        }
예제 #22
0
        private static void WriteAttribute(string reference, SyntaxWriter writer, bool newline)
        {
            writer.WriteString("/** @attribute ");
            writer.WriteReferenceLink(reference);
            writer.WriteString(" */ ");

            if(newline)
                writer.WriteLine();
        }
예제 #23
0
        /// <inheritdoc />
        public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            // !EFW - Added unsafe check
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool isFamily = (bool)reflection.Evaluate(apiIsFamilyMemberExpression);
            XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);
            XPathNavigator handler = reflection.SelectSingleNode(apiHandlerOfEventExpression);

            if(!(isStatic | isFamily))
                ParameterDeclaration("instance", declaringType, writer);
            ParameterDeclaration("handler", handler, writer);

            // adder
            writer.WriteLine();
            writer.WriteKeyword("AddHandler");
            writer.WriteString(" ");
            WriteMemberName(reflection, writer);
            writer.WriteString(", ");
            writer.WriteParameter("handler");
            writer.WriteLine();
        }
        /// <inheritdoc />
        public override void WriteNormalMethodSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            // !EFW - Added unsafe check
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            if(IsUnsupportedVarargs(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool isVirtual = (bool)reflection.Evaluate(apiIsVirtualExpression) && !(bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
            int iterations = isVirtual ? 2 : 1;

            for(int i = 0; i < iterations; i++)
            {

                WriteAttributes(reflection, writer);

                WriteVisibility(reflection, writer);

                if(isStatic)
                {
                    writer.WriteKeyword("static");
                    writer.WriteString(" ");
                }

                if(isVirtual)
                    if(i == 0)
                    {
                        writer.WriteKeyword("abstract");
                        writer.WriteString(" ");
                    }
                    else
                    {
                        writer.WriteKeyword("override");
                        writer.WriteString(" ");
                    }
                else
                {
                    WriteMemberKeyword(reflection, writer);
                }

                writer.WriteIdentifier(name);
                writer.WriteString(" : ");
                WriteParameters(reflection, writer);
                writer.WriteKeyword("->");
                writer.WriteString(" ");
                WriteReturnValue(reflection, writer);
                writer.WriteString(" ");
                WriteGenericTemplateConstraints(reflection, writer);

                if(i == 0)
                    writer.WriteLine();
            }
        }
예제 #25
0
        // !EFW - Added parameterAttributes to suppress line feeds for method parameter attributes
        private void WriteAttributes(XPathNavigator reflection, SyntaxWriter writer, bool parameterAttributes = false)
        {
            // Handle interop attributes first as they are output in metadata
            if (!parameterAttributes)
            {
                WriteInteropAttributes(reflection, writer);
            }

            // Add the standard attributes
            XPathNodeIterator attributes = (XPathNodeIterator)reflection.Evaluate(apiAttributesExpression);

            foreach (XPathNavigator attribute in attributes)
            {
                XPathNavigator type = attribute.SelectSingleNode(attributeTypeExpression);

                // !EFW - Ignore FixedBufferAttribute, ParamArrayAttribute, IsByRefLikeAttribute, IsReadOnlyAttribute too
                if (type.GetAttribute("api", String.Empty) == "T:System.Runtime.CompilerServices.FixedBufferAttribute" ||
                    type.GetAttribute("api", String.Empty) == "T:System.Runtime.CompilerServices.IsByRefLikeAttribute" ||
                    type.GetAttribute("api", String.Empty) == "T:System.Runtime.CompilerServices.IsReadOnlyAttribute" ||
                    type.GetAttribute("api", String.Empty) == "T:System.ParamArrayAttribute")
                {
                    continue;
                }

                writer.WriteString("/** @attribute ");
                WriteTypeReference(type, writer);

                XPathNodeIterator arguments   = attribute.Select(attributeArgumentsExpression);
                XPathNodeIterator assignments = attribute.Select(attributeAssignmentsExpression);

                if ((arguments.Count > 0) || (assignments.Count > 0))
                {
                    writer.WriteString("(");

                    while (arguments.MoveNext())
                    {
                        XPathNavigator argument = arguments.Current;

                        if (arguments.CurrentPosition > 1)
                        {
                            WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                        }

                        WriteValue(argument, writer);
                    }

                    if (arguments.Count > 0 && assignments.Count > 0)
                    {
                        writer.WriteString(", ");
                    }

                    while (assignments.MoveNext())
                    {
                        XPathNavigator assignment = assignments.Current;

                        if (assignments.CurrentPosition > 1)
                        {
                            WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                        }

                        writer.WriteString((string)assignment.Evaluate(assignmentNameExpression));
                        writer.WriteString(" = ");
                        WriteValue(assignment, writer);
                    }

                    writer.WriteString(")");
                }

                writer.WriteString(" */");

                if (!parameterAttributes)
                {
                    writer.WriteLine();
                }
            }

            if (parameterAttributes && attributes.Count != 0)
            {
                writer.WriteString(" ");
            }
        }
예제 #26
0
        /// <inheritdoc />
        public override void WriteCastSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNavigator parameter = reflection.SelectSingleNode(apiParametersExpression);
            if(parameter == null)
                return;
            XPathNavigator inputType = parameter.SelectSingleNode(typeExpression);
            XPathNavigator outputType = reflection.SelectSingleNode(apiReturnTypeExpression);
            if((inputType == null) || (outputType == null))
                return;

            ParameterDeclaration("input", inputType, writer);
            ParameterDeclaration("output", outputType, writer);
            writer.WriteLine();
            writer.WriteParameter("output");
            writer.WriteString(" = ");
            writer.WriteKeyword("CType");
            writer.WriteString("(");
            writer.WriteParameter("input");
            writer.WriteString(", ");
            WriteTypeReference(outputType, writer);
            writer.WriteString(")");
        }
예제 #27
0
        /// <inheritdoc />
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (IsUnsupportedUnsafe(reflection, writer))
            {
                return;
            }

            if (IsUnsupportedExplicit(reflection, writer))
            {
                return;
            }

            string name       = (string)reflection.Evaluate(apiNameExpression);
            bool   isGettable = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool   isSettable = (bool)reflection.Evaluate(apiIsWritePropertyExpression);

            if (isGettable)
            {
                writer.WriteString("/** @property */");
                writer.WriteLine();

                // !EFW - Added support for getter/setter attributes
                XPathNavigator getter = reflection.SelectSingleNode(apiGetterExpression);

                if (getter != null && getter.HasChildren)
                {
                    this.WriteAttributes(getter, writer);
                }

                // write getter method
                WriteAttributes(reflection, writer);
                WriteProcedureModifiers(reflection, writer);
                WriteReturnValue(reflection, writer);
                writer.WriteString(" ");
                writer.WriteIdentifier("get_" + name);
                WriteMethodParameters(reflection, writer);
                writer.WriteLine();
            }

            if (isSettable)
            {
                writer.WriteString("/** @property */");
                writer.WriteLine();

                // !EFW - Added support for getter/setter attributes
                XPathNavigator setter = reflection.SelectSingleNode(apiSetterExpression);

                if (setter != null && setter.HasChildren)
                {
                    this.WriteAttributes(setter, writer);
                }

                // write setter method
                WriteAttributes(reflection, writer);
                WriteProcedureModifiers(reflection, writer);
                writer.WriteKeyword("void");
                writer.WriteString(" ");
                writer.WriteIdentifier("set_" + name);

                // parameters
                writer.WriteString("(");
                WriteReturnValue(reflection, writer);
                writer.WriteString(" ");
                writer.WriteParameter("value");
                writer.WriteString(")");

                // end parameters
                writer.WriteLine();
            }
        }
예제 #28
0
        private void WriteParameters(XPathNodeIterator parameters, SyntaxWriter writer)
        {
            while (parameters.MoveNext())
            {
                XPathNavigator parameter = parameters.Current;

                // !EFW - Added support for optional parameter values
                XPathNavigator argument   = parameter.SelectSingleNode(parameterArgumentExpression);
                bool           isOptional = (bool)parameter.Evaluate(parameterIsOptionalExpression);

                string         name  = (string)parameter.Evaluate(parameterNameExpression);
                XPathNavigator type  = parameter.SelectSingleNode(parameterTypeExpression);
                bool           isIn  = (bool)parameter.Evaluate(parameterIsInExpression);
                bool           isOut = (bool)parameter.Evaluate(parameterIsOutExpression);
                bool           isRef = (bool)parameter.Evaluate(parameterIsRefExpression);

                writer.WriteString("\t");

                // !EFW - Optional indicated by OptionalAttribute?
                if (isOptional && argument == null)
                {
                    WriteAttribute("T:System.Runtime.InteropServices.OptionalAttribute", writer, false);
                }

                if (isIn)
                {
                    WriteAttribute("T:System.Runtime.InteropServices.InAttribute", writer, false);
                }

                if (isOut)
                {
                    WriteAttribute("T:System.Runtime.InteropServices.OutAttribute", writer, false);
                }

                // !EFW - Write out parameter attributes
                WriteAttributes(parameter, writer, true);

                if (isRef)
                {
                    writer.WriteString("/** @ref */");
                }

                WriteTypeReference(type, writer);
                writer.WriteString(" ");
                writer.WriteParameter(name);

                // !EFW - Write optional value if present
                if (argument != null)
                {
                    writer.WriteString(" = ");
                    this.WriteValue(argument, writer);
                }

                if (parameters.CurrentPosition < parameters.Count)
                {
                    writer.WriteString(",");
                }

                writer.WriteLine();
            }
        }
예제 #29
0
        /// <inheritdoc />
        public override void WriteFieldSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (IsUnsupportedUnsafe(reflection, writer))
            {
                return;
            }

            string         name          = (string)reflection.Evaluate(apiNameExpression);
            bool           isStatic      = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool           isLiteral     = (bool)reflection.Evaluate(apiIsLiteralFieldExpression);
            bool           isInitOnly    = (bool)reflection.Evaluate(apiIsInitOnlyFieldExpression);
            bool           isFamily      = (bool)reflection.Evaluate(apiIsFamilyMemberExpression);
            XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);
            XPathNavigator fieldType     = reflection.SelectSingleNode(apiReturnTypeExpression);

            if (!(isStatic || isFamily))
            {
                ParameterDeclaration("instance", declaringType, writer);
            }
            ParameterDeclaration("value", fieldType, writer);

            // get value
            writer.WriteLine();
            writer.WriteParameter("value");
            writer.WriteString(" = ");
            if (isStatic)
            {
                WriteTypeReference(declaringType, writer);
            }
            else
            {
                if (isFamily)
                {
                    writer.WriteKeyword("Me");
                }
                else
                {
                    writer.WriteParameter("instance");
                }
            }
            writer.WriteString(".");
            writer.WriteIdentifier(name);
            writer.WriteLine();

            // set value
            if (isLiteral || isInitOnly)
            {
                return;
            }
            writer.WriteLine();
            if (isStatic)
            {
                WriteTypeReference(declaringType, writer);
            }
            else
            {
                if (isFamily)
                {
                    writer.WriteKeyword("Me");
                }
                else
                {
                    writer.WriteParameter("instance");
                }
            }
            writer.WriteString(".");
            writer.WriteIdentifier(name);
            writer.WriteString(" = ");
            writer.WriteParameter("value");
        }
예제 #30
0
        private void WriteParameters(XPathNodeIterator parameters, SyntaxWriter writer)
        {
            while(parameters.MoveNext())
            {
                XPathNavigator parameter = parameters.Current;
                string name = (string)parameter.Evaluate(parameterNameExpression);
                writer.WriteParameter(name);

                if(parameters.CurrentPosition < parameters.Count)
                {
                    writer.WriteString(", ");

                    if(writer.Position > MaxPosition)
                    {
                        if(includeLineContinuation)
                            writer.WriteString("_");

                        writer.WriteLine();
                        writer.WriteString("\t");
                    }
                }
            }
        }
        /// <inheritdoc />
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            bool hasGetter = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool hasSetter = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
            bool isDefault = (bool)reflection.Evaluate(apiIsDefaultMemberExpression);
            bool isExplicit = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);
            XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);

            WriteAttributes(reflection, writer);
            WriteProcedureModifiers(reflection, writer);

            if(hasGetter && !hasSetter)
            {
                writer.WriteKeyword("ReadOnly");
                writer.WriteString(" ");
            }
            else if(hasSetter && !hasGetter)
            {
                writer.WriteKeyword("WriteOnly");
                writer.WriteString(" ");
            }

            if(isDefault)
            {
                writer.WriteKeyword("Default");
                writer.WriteString(" ");
            }

            writer.WriteKeyword("Property");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteParameters(reflection, writer);
            writer.WriteString(" ");
            writer.WriteKeyword("As");
            writer.WriteString(" ");
            WriteTypeReference(type, writer);

            if(isExplicit)
            {
                if(writer.Position > MaxPosition)
                {
                    writer.WriteLine();
                    writer.WriteString("\t");
                }
                else
                {
                    writer.WriteString(" ");
                }

                writer.WriteKeyword("Implements");
                writer.WriteString(" ");
                XPathNodeIterator implementations = reflection.Select(apiImplementedMembersExpression);

                while(implementations.MoveNext())
                {
                    XPathNavigator implementation = implementations.Current;
                    XPathNavigator contract = implementation.SelectSingleNode(memberDeclaringTypeExpression);
                    //string id = implementation.GetAttribute("api", String.Empty);
                    if(implementations.CurrentPosition > 1)
                        writer.WriteString(", ");
                    WriteTypeReference(contract, writer);
                    writer.WriteString(".");
                    WriteMemberReference(implementation, writer);
                    //writer.WriteReferenceLink(id);	
                }
            }

            if(hasGetter)
            {
                writer.WriteLine();

                // !EFW - Added support for getter/setter attributes
                XPathNavigator getter = reflection.SelectSingleNode(apiGetterExpression);

                if(getter != null && getter.HasChildren)
                {
                    writer.WriteString("\t");
                    this.WriteAttributes(getter, writer, "\t");
                }

                writer.WriteString("\t");

                string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);

                if(!String.IsNullOrEmpty(getVisibility))
                {
                    WriteVisibility(getVisibility, writer);
                    writer.WriteString(" ");
                }

                writer.WriteKeyword("Get");
            }

            if(hasSetter)
            {
                writer.WriteLine();

                // !EFW - Added support for getter/setter attributes
                XPathNavigator setter = reflection.SelectSingleNode(apiSetterExpression);

                if(setter != null && setter.HasChildren)
                {
                    writer.WriteString("\t");
                    this.WriteAttributes(setter, writer, "\t");
                }

                writer.WriteString("\t");

                string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);

                if(!String.IsNullOrEmpty(setVisibility))
                {
                    WriteVisibility(setVisibility, writer);
                    writer.WriteString(" ");
                }

                writer.WriteKeyword("Set");
            }
        }
예제 #32
0
        // EFW - Added support for interop attributes stored in metadata
        private void WriteInteropAttributes(XPathNavigator reflection, SyntaxWriter writer)
        {
            if ((bool)reflection.Evaluate(apiComImportTypeExpression))
            {
                WriteAttribute("T:System.Runtime.InteropServices.ComImportAttribute", writer, true);
            }

            string layout = (string)reflection.Evaluate(apiStructLayoutTypeExpression);

            if (!String.IsNullOrEmpty(layout))
            {
                double size   = (double)reflection.Evaluate(apiStructLayoutSizeTypeExpression),
                       pack   = (double)reflection.Evaluate(apiStructLayoutPackTypeExpression);
                string format = (string)reflection.Evaluate(apiStructLayoutFormatTypeExpression);

                writer.WriteString("/** @attribute ");
                WriteNormalTypeReference("T:System.Runtime.InteropServices.StructLayoutAttribute", writer);
                writer.WriteString("(");

                switch (layout)
                {
                case "explicit":
                    writer.WriteString("LayoutKind.Explicit");
                    break;

                case "sequential":
                    writer.WriteString("LayoutKind.Sequential");
                    break;

                default:
                    writer.WriteString("LayoutKind.Auto");
                    break;
                }

                if (!Double.IsNaN(size) && size != 0)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("Size = ");
                    writer.WriteString(((int)size).ToString(CultureInfo.InvariantCulture));
                }

                if (!Double.IsNaN(pack) && pack != 0)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("Pack = ");
                    writer.WriteString(((int)pack).ToString(CultureInfo.InvariantCulture));
                }

                switch (format)
                {
                case "ansi":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CharSet = CharSet.Ansi");
                    break;

                case "auto":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CharSet = CharSet.Auto");
                    break;

                case "unicode":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CharSet = CharSet.Unicode");
                    break;
                }

                writer.WriteString(")");
                writer.WriteString(" */");
                writer.WriteLine();
            }

            double fieldOffset = (double)reflection.Evaluate(apiFieldOffsetFieldExpression);

            if (!Double.IsNaN(fieldOffset))
            {
                writer.WriteString("/** @attribute ");
                WriteNormalTypeReference("T:System.Runtime.InteropServices.FieldOffsetAttribute", writer);
                writer.WriteString("(");
                writer.WriteString(((int)fieldOffset).ToString(CultureInfo.InvariantCulture));
                writer.WriteString(")");
                writer.WriteString(" */");
                writer.WriteLine();
            }

            bool   preserveSig = (bool)reflection.Evaluate(apiPreserveSigProcedureExpression);
            string module      = (string)reflection.Evaluate(apiModuleProcedureExpression);

            if (!String.IsNullOrEmpty(module))
            {
                string entryPoint     = (string)reflection.Evaluate(apiEntryPointProcedureExpression),
                       callingConv    = (string)reflection.Evaluate(apiCallingConvProcedureExpression),
                       charset        = (string)reflection.Evaluate(apiCharSetProcedureExpression),
                       bestFitMapping = (string)reflection.Evaluate(apiBestFitMappingProcedureExpression);

                bool exactSpelling         = (bool)reflection.Evaluate(apiExactSpellingProcedureExpression),
                     throwOnUnmappableChar = (bool)reflection.Evaluate(apiUnmappableCharProcedureExpression),
                     setLastError          = (bool)reflection.Evaluate(apiSetLastErrorProcedureExpression);

                writer.WriteString("/** @attribute ");
                WriteNormalTypeReference("T:System.Runtime.InteropServices.DllImportAttribute", writer);
                writer.WriteString("(\"");
                writer.WriteString(module);
                writer.WriteString("\"");

                if (!String.IsNullOrEmpty(entryPoint))
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("EntryPoint = \"");
                    writer.WriteString(entryPoint);
                    writer.WriteString("\"");
                }

                switch (callingConv)
                {
                case "cdecl":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CallingConvention = CallingConvention.Cdecl");
                    break;

                case "fastcall":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CallingConvention = CallingConvention.FastCall");
                    break;

                case "stdcall":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CallingConvention = CallingConvention.StdCall");
                    break;

                case "thiscall":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CallingConvention = CallingConvention.ThisCall");
                    break;
                }

                switch (charset)
                {
                case "ansi":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CharSet = CharSet.Ansi");
                    break;

                case "auto":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CharSet = CharSet.Auto");
                    break;

                case "unicode":
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("CharSet = CharSet.Unicode");
                    break;
                }

                if (!String.IsNullOrEmpty(bestFitMapping) && !Convert.ToBoolean(bestFitMapping, CultureInfo.InvariantCulture))
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("BestFitMapping = false");
                }

                if (exactSpelling)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("ExactSpelling = true");
                }

                if (throwOnUnmappableChar)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("ThrowOnUnmappableChar = true");
                }

                if (!preserveSig)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("PreserveSig = false");
                }

                if (setLastError)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    writer.WriteString("SetLastError = true");
                }

                writer.WriteString(")");
                writer.WriteString(" */");
                writer.WriteLine();
            }
            else
            if (preserveSig)
            {
                WriteAttribute("T:System.Runtime.InteropServices.PreserveSigAttribute", writer, true);
            }
        }
        private void WriteAttribute(string reference, bool newLine, SyntaxWriter writer)
        {
            writer.WriteString("<");
            writer.WriteReferenceLink(reference);
            writer.WriteString(">");

            if(newLine)
            {
                if(includeLineContinuation)
                    writer.WriteString(" _");

                writer.WriteLine();
            }
        }
예제 #34
0
        /// <inheritdoc />
        public override void WriteOperatorSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string name = (string)reflection.Evaluate(apiNameExpression);
            XPathNavigator returnType = reflection.SelectSingleNode(apiReturnTypeExpression);

            // Determine operator identifier and type
            string identifier = null;
            int type = 0;

            if(!(bool)reflection.Evaluate(apiIsUdtReturnExpression))
            {
                switch(name)
                {
                    // unary math operators
                    case "UnaryPlus":
                        identifier = "+";
                        type = -1;
                        break;
                    case "UnaryNegation":
                        identifier = "-";
                        type = -1;
                        break;
                    case "Increment":
                        identifier = "++";
                        type = +1;
                        break;
                    case "Decrement":
                        identifier = "--";
                        type = +1;
                        break;
                    // unary logical operators
                    case "LogicalNot":
                        identifier = "Not";
                        type = -1;
                        break;
                    case "True":
                        identifier = "IsTrue";
                        type = -1;
                        break;
                    case "False":
                        identifier = "IsFalse";
                        type = -1;
                        break;
                    // binary comparison operators
                    case "Equality":
                        identifier = "=";
                        type = 2;
                        break;
                    case "Inequality":
                        identifier = "<>";
                        type = 2;
                        break;
                    case "LessThan":
                        identifier = "<";
                        type = 2;
                        break;
                    case "GreaterThan":
                        identifier = ">";
                        type = 2;
                        break;
                    case "LessThanOrEqual":
                        identifier = "<=";
                        type = 2;
                        break;
                    case "GreaterThanOrEqual":
                        identifier = ">=";
                        type = 2;
                        break;
                    // binary math operators
                    case "Addition":
                        identifier = "+";
                        type = 2;
                        break;
                    case "Subtraction":
                        identifier = "-";
                        type = 2;
                        break;
                    case "Multiply":
                        identifier = "*";
                        type = 2;
                        break;
                    case "Division":
                        identifier = "/";
                        type = 2;
                        break;
                    case "Exponent":
                        identifier = "^";
                        type = 2;
                        break;
                    case "Modulus":
                        identifier = "Mod";
                        type = 2;
                        break;
                    case "IntegerDivision":
                        identifier = @"\";
                        type = 2;
                        break;
                    // binary logical operators
                    case "BitwiseAnd":
                        identifier = "And";
                        type = 2;
                        break;
                    case "BitwiseOr":
                        identifier = "Or";
                        type = 2;
                        break;
                    case "ExclusiveOr":
                        identifier = "Xor";
                        type = 2;
                        break;
                    // bit-array operators
                    case "OnesComplement":
                        identifier = "~";
                        type = -1;
                        break;
                    case "LeftShift":
                        identifier = "<<";
                        type = 2;
                        break;
                    case "RightShift":
                        identifier = ">>";
                        type = 2;
                        break;
                    // concatenation
                    case "Concatenate":
                        identifier = "&";
                        type = 2;
                        break;
                    case "Assign":
                        identifier = "=";
                        type = 2;
                        break;


                    // didn't recognize an operator
                    default:
                        identifier = null;
                        type = 0;
                        break;
                }
            }

            if(identifier == null)
                writer.WriteMessage("UnsupportedOperator_" + Language);
            else
            {
                XPathNodeIterator parameters = reflection.Select(apiParametersExpression);

                if(parameters.Count != Math.Abs(type))
                {
                    writer.WriteMessage("UnsupportedOperator_" + Language);
                    return;
                }   //throw new InvalidOperationException("An operator has the wrong number of parameters.");

                WriteParameterDeclarations(reflection, writer);
                ParameterDeclaration("returnValue", returnType, writer);
                writer.WriteLine();
                writer.WriteParameter("returnValue");
                writer.WriteString(" = ");
                switch(type)
                {
                    case -1:
                        writer.WriteIdentifier(identifier);
                        parameters.MoveNext();
                        writer.WriteParameter((string)parameters.Current.Evaluate(parameterNameExpression));
                        break;
                    case +1:
                        parameters.MoveNext();
                        writer.WriteParameter((string)parameters.Current.Evaluate(parameterNameExpression));
                        writer.WriteIdentifier(identifier);
                        break;
                    case 2:
                        writer.WriteString("(");

                        // parameter 1
                        parameters.MoveNext();
                        writer.WriteParameter((string)parameters.Current.Evaluate(parameterNameExpression));

                        writer.WriteString(" ");
                        writer.WriteIdentifier(identifier);
                        writer.WriteString(" ");

                        // parameter 2
                        parameters.MoveNext();
                        writer.WriteParameter((string)parameters.Current.Evaluate(parameterNameExpression));

                        writer.WriteString(")");
                        break;
                }
            }

        }
        /// <inheritdoc />
        public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            // !EFW - Added unsafe check
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            XPathNavigator handler = reflection.SelectSingleNode(apiHandlerOfEventExpression);
            XPathNavigator args = reflection.SelectSingleNode(apiEventArgsExpression);
            bool isVirtual = (bool)reflection.Evaluate(apiIsVirtualExpression) && !(bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
            int iterations = isVirtual ? 2 : 1;

            for(int i = 0; i < iterations; i++)
            {
                WriteAttributes(reflection, writer);
                WriteVisibility(reflection, writer);
                if(isVirtual)
                    if(i == 0)
                    {
                        writer.WriteKeyword("abstract");
                        writer.WriteString(" ");
                    }
                    else
                    {
                        writer.WriteKeyword("override");
                        writer.WriteString(" ");
                    }
                else
                {
                    WriteMemberKeyword(reflection, writer);
                }
                writer.WriteIdentifier(name);
                writer.WriteString(" : ");
                writer.WriteReferenceLink("T:Microsoft.FSharp.Control.IEvent`2");

                writer.WriteString("<");
                WriteTypeReference(handler, writer);
                writer.WriteString(",");
                writer.WriteLine();
                writer.WriteString("    ");
                if(args == null)
                {
                    writer.WriteReferenceLink("T:System.EventArgs");
                }
                else
                {
                    WriteTypeReference(args, writer);
                }
                writer.WriteString(">");
                if(i == 0)
                    writer.WriteLine();
            }
        }
예제 #36
0
        /// <summary>
        /// Write out property syntax
        /// </summary>
        /// <param name="reflection">An XPath navigator containing the member information</param>
        /// <param name="writer">The syntax writer to which the information is written</param>
        /// <param name="prefix">The web control prefix to use</param>
        private static void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer, string prefix)
        {
            bool set = (bool)reflection.Evaluate(propertyIsSettable);

            if (!set)
            {
                return;
            }

            string name          = (string)reflection.Evaluate(nameExpression);
            string declaringType = (string)reflection.Evaluate(declaringTypeExpression);
            string propertyType  = (string)reflection.Evaluate(propertyTypeExpression);

            bool isInnerProperty = (bool)reflection.Evaluate(propertyIsInnerProperty);

            writer.WriteStartBlock(LanguageName, StyleIdName);

            if (isInnerProperty)
            {
                // inner property logic
                writer.WriteString("<");
                writer.WriteString(prefix);
                writer.WriteString(":");
                writer.WriteReferenceLink(declaringType);
                writer.WriteString(">");

                writer.WriteLine();
                writer.WriteString("\t");

                writer.WriteString("<");
                writer.WriteString(name);
                writer.WriteString(">");

                if (String.IsNullOrEmpty(propertyType))
                {
                    writer.WriteParameter("value");
                }
                else
                if (propertyType == "T:System.Boolean")
                {
                    writer.WriteString("True|False");
                }
                else
                {
                    writer.WriteReferenceLink(propertyType);
                }

                writer.WriteString("</");
                writer.WriteString(name);
                writer.WriteString(">");

                writer.WriteLine();

                writer.WriteString("</");
                writer.WriteString(prefix);
                writer.WriteString(":");
                writer.WriteReferenceLink(declaringType);
                writer.WriteString(">");
            }
            else
            {
                // normal property logic
                writer.WriteString("<");
                writer.WriteString(prefix);
                writer.WriteString(":");
                writer.WriteReferenceLink(declaringType);
                writer.WriteString(" ");
                writer.WriteString(name);
                writer.WriteString("=\"");

                if (String.IsNullOrEmpty(propertyType))
                {
                    writer.WriteParameter("value");
                }
                else
                if (propertyType == "T:System.Boolean")
                {
                    writer.WriteString("True|False");
                }
                else
                {
                    writer.WriteReferenceLink(propertyType);
                }

                writer.WriteString("\" />");
            }

            writer.WriteEndBlock();
        }
예제 #37
0
        /// <inheritdoc />
        public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            XPathNavigator handler = reflection.SelectSingleNode(apiHandlerOfEventExpression);

            writer.WriteString("/** @event */");
            writer.WriteLine();
            // add_ method declaration
            WriteAttributes(reflection, writer);
            WriteProcedureModifiers(reflection, writer);
            WriteReturnValue(reflection, writer);
            writer.WriteString(" ");
            writer.WriteIdentifier("add_" + name);
            writer.WriteString(" (");
            WriteTypeReference(handler, writer);
            writer.WriteString(" ");
            writer.WriteParameter("value");
            writer.WriteString(")");
            writer.WriteLine();

            writer.WriteString("/** @event */");
            writer.WriteLine();
            // remove_ method declaration
            WriteAttributes(reflection, writer);
            WriteProcedureModifiers(reflection, writer);
            WriteReturnValue(reflection, writer);
            writer.WriteString(" ");
            writer.WriteIdentifier("remove_" + name);
            writer.WriteString(" (");
            WriteTypeReference(handler, writer);
            writer.WriteString(" ");
            writer.WriteParameter("value");
            writer.WriteString(")");
            writer.WriteLine();

        }
        // Attributes

        // !EFW - Added newLine parameter
        private static void WriteAttribute(string reference, bool newLine, SyntaxWriter writer)
        {
            writer.WriteString("[<");
            writer.WriteReferenceLink(reference);
            writer.WriteString(">]");

            if(newLine)
                writer.WriteLine();
        }
예제 #39
0
        // Parameters

        private void WriteMethodParameters(XPathNavigator reflection, SyntaxWriter writer)
        {

            XPathNodeIterator parameters = reflection.Select(apiParametersExpression);

            writer.WriteString("(");
            if(parameters.Count > 0)
            {
                writer.WriteLine();
                WriteParameters(parameters, writer);
            }
            writer.WriteString(")");

        }
        // EFW - Added support for interop attributes stored in metadata
        private void WriteInteropAttributes(XPathNavigator reflection, SyntaxWriter writer, string indent = null)
        {
            if((bool)reflection.Evaluate(apiComImportTypeExpression))
                WriteAttribute("T:System.Runtime.InteropServices.ComImportAttribute", true, writer);

            string layout = (string)reflection.Evaluate(apiStructLayoutTypeExpression);

            if(!String.IsNullOrEmpty(layout))
            {
                double size = (double)reflection.Evaluate(apiStructLayoutSizeTypeExpression),
                    pack = (double)reflection.Evaluate(apiStructLayoutPackTypeExpression);
                string format = (string)reflection.Evaluate(apiStructLayoutFormatTypeExpression);

                writer.WriteString("[<");
                WriteNormalTypeReference("T:System.Runtime.InteropServices.StructLayoutAttribute", writer);
                writer.WriteString("(");

                switch(layout)
                {
                    case "explicit":
                        writer.WriteString("LayoutKind.Explicit");
                        break;

                    case "sequential":
                        writer.WriteString("LayoutKind.Sequential");
                        break;

                    default:
                        writer.WriteString("LayoutKind.Auto");
                        break;
                }

                if(!Double.IsNaN(size) && size != 0)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                    writer.WriteString("Size = ");
                    writer.WriteString(((int)size).ToString(CultureInfo.InvariantCulture));
                }

                if(!Double.IsNaN(pack) && pack != 0)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                    writer.WriteString("Pack = ");
                    writer.WriteString(((int)pack).ToString(CultureInfo.InvariantCulture));
                }

                switch(format)
                {
                    case "ansi":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CharSet = CharSet.Ansi");
                        break;

                    case "auto":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CharSet = CharSet.Auto");
                        break;

                    case "unicode":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CharSet = CharSet.Unicode");
                        break;
                }

                writer.WriteString(")");
                writer.WriteString(">]");
                writer.WriteLine();
            }

            double fieldOffset = (double)reflection.Evaluate(apiFieldOffsetFieldExpression);

            if(!Double.IsNaN(fieldOffset))
            {
                writer.WriteString("[<");
                WriteNormalTypeReference("T:System.Runtime.InteropServices.FieldOffsetAttribute", writer);
                writer.WriteString("(");
                writer.WriteString(((int)fieldOffset).ToString(CultureInfo.InvariantCulture));
                writer.WriteString(")");
                writer.WriteString(">]");
                writer.WriteLine();
            }

            bool preserveSig = (bool)reflection.Evaluate(apiPreserveSigProcedureExpression);
            string module = (string)reflection.Evaluate(apiModuleProcedureExpression);

            if(!String.IsNullOrEmpty(module))
            {
                string entryPoint = (string)reflection.Evaluate(apiEntryPointProcedureExpression),
                    callingConv = (string)reflection.Evaluate(apiCallingConvProcedureExpression),
                    charset = (string)reflection.Evaluate(apiCharSetProcedureExpression),
                    bestFitMapping = (string)reflection.Evaluate(apiBestFitMappingProcedureExpression);

                bool exactSpelling = (bool)reflection.Evaluate(apiExactSpellingProcedureExpression),
                    throwOnUnmappableChar = (bool)reflection.Evaluate(apiUnmappableCharProcedureExpression),
                    setLastError = (bool)reflection.Evaluate(apiSetLastErrorProcedureExpression);

                writer.WriteString("[<");
                WriteNormalTypeReference("T:System.Runtime.InteropServices.DllImportAttribute", writer);
                writer.WriteString("(\"");
                writer.WriteString(module);
                writer.WriteString("\"");

                if(!String.IsNullOrEmpty(entryPoint))
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                    writer.WriteString("EntryPoint = \"");
                    writer.WriteString(entryPoint);
                    writer.WriteString("\"");
                }

                switch(callingConv)
                {
                    case "cdecl":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CallingConvention = CallingConvention.Cdecl");
                        break;

                    case "fastcall":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CallingConvention = CallingConvention.FastCall");
                        break;

                    case "stdcall":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CallingConvention = CallingConvention.StdCall");
                        break;

                    case "thiscall":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CallingConvention = CallingConvention.ThisCall");
                        break;
                }

                switch(charset)
                {
                    case "ansi":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CharSet = CharSet.Ansi");
                        break;

                    case "auto":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CharSet = CharSet.Auto");
                        break;

                    case "unicode":
                        WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                        writer.WriteString("CharSet = CharSet.Unicode");
                        break;
                }

                if(!String.IsNullOrEmpty(bestFitMapping) && !Convert.ToBoolean(bestFitMapping, CultureInfo.InvariantCulture))
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                    writer.WriteString("BestFitMapping = false");
                }

                if(exactSpelling)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                    writer.WriteString("ExactSpelling = true");
                }

                if(throwOnUnmappableChar)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                    writer.WriteString("ThrowOnUnmappableChar = true");
                }

                if(!preserveSig)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                    writer.WriteString("PreserveSig = false");
                }

                if(setLastError)
                {
                    WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");
                    writer.WriteString("SetLastError = true");
                }

                writer.WriteString(")");
                writer.WriteString(">]");
                writer.WriteLine();
            }
            else
                if(preserveSig)
                    WriteAttribute("T:System.Runtime.InteropServices.PreserveSigAttribute", true, writer);
        }
예제 #41
0
        private void ObjectElementUsageForClassStruct(XPathNavigator reflection, SyntaxWriter writer)
        {
            string typeName = (string)reflection.Evaluate(apiNameExpression);
            bool isGeneric = (bool)reflection.Evaluate(apiIsGenericExpression);
            string xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlObjectElementUsageHeading);

            string contentPropertyId = (string)reflection.Evaluate(contentPropertyIdExpression);

            if(String.IsNullOrEmpty(contentPropertyId))
                contentPropertyId = (string)reflection.Evaluate(ancestorContentPropertyIdExpression);

            // start the syntax block
            writer.WriteStartSubBlock(xamlBlockId);

            writer.WriteString("<");

            if(isGeneric)
            {
                writer.WriteIdentifier(typeName);

                // for generic types show the type arguments
                XPathNodeIterator templates = (XPathNodeIterator)reflection.Evaluate(apiTemplatesExpression);

                if(templates.Count > 0)
                {
                    writer.WriteString(" x:TypeArguments=\"");

                    while(templates.MoveNext())
                    {
                        XPathNavigator template = templates.Current;
                        string name = template.GetAttribute("name", String.Empty);
                        writer.WriteString(name);

                        if(templates.CurrentPosition < templates.Count)
                            writer.WriteString(",");
                    }

                    writer.WriteString("\"");
                }
            }
            else
            {
                // for non-generic types just show the name
                writer.WriteIdentifier(typeName);
            }

            if(String.IsNullOrEmpty(contentPropertyId))
                writer.WriteString(" .../>");
            else
            {
                // close the start tag
                writer.WriteString(">");

                // the inner xml of the Object Element syntax for a type with a content property
                // is a link to the content property
                writer.WriteLine();
                writer.WriteString("  ");
                writer.WriteReferenceLink(contentPropertyId);
                writer.WriteLine();

                // write the end tag
                writer.WriteString("</");
                writer.WriteIdentifier(typeName);
                writer.WriteString(">");
            }

            // end the sub block
            writer.WriteEndSubBlock();
        }
예제 #42
0
        /// <inheritdoc />
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (IsUnsupportedUnsafe(reflection, writer))
            {
                return;
            }
            if (IsUnsupportedExplicit(reflection, writer))
            {
                return;
            }

            if (reflection.Select(apiParametersExpression).Count > 0)
            {
                writer.WriteMessage("UnsupportedIndex_" + Language);
                return;
            }

            string         name       = (string)reflection.Evaluate(apiNameExpression);
            bool           isGettable = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool           isSettable = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
            XPathNavigator type       = reflection.SelectSingleNode(apiReturnTypeExpression);

            if (isGettable)
            {
                string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);

                if (!String.IsNullOrEmpty(getVisibility))
                {
                    WriteVisibility(getVisibility, writer);
                    writer.WriteString(" ");
                }

                WriteProcedureModifiers(reflection, writer);
                writer.WriteKeyword("function get");
                writer.WriteString(" ");
                writer.WriteIdentifier(name);

                // Some F# properties don't generate return type info for some reason.  It's probably unsupported
                // but just ignore them for now and write out what we do have.
                if (type != null)
                {
                    writer.WriteString(" () : ");
                    WriteTypeReference(type, writer);
                }
                else
                {
                    writer.WriteString(" ()");
                }

                writer.WriteLine();
            }

            if (isSettable)
            {
                string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);

                if (!String.IsNullOrEmpty(setVisibility))
                {
                    WriteVisibility(setVisibility, writer);
                    writer.WriteString(" ");
                }

                WriteProcedureModifiers(reflection, writer);
                writer.WriteKeyword("function set");
                writer.WriteString(" ");
                writer.WriteIdentifier(name);
                writer.WriteString(" (");
                writer.WriteParameter("value");

                // Some F# properties don't generate return type info for some reason.  It's probably unsupported
                // but just ignore them for now and write out what we do have.
                if (type != null)
                {
                    writer.WriteString(" : ");
                    WriteTypeReference(type, writer);
                }

                writer.WriteString(")");
            }
        }
        // Interfaces
        private void WriteBaseClass(XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNavigator baseClass = reflection.SelectSingleNode(apiBaseClassExpression);

            if((baseClass != null) && !((bool)baseClass.Evaluate(typeIsObjectExpression)))
            {
                if(includeLineContinuation)
                    writer.WriteString(" _");

                writer.WriteLine();
                writer.WriteString("\t");
                writer.WriteKeyword("Inherits");
                writer.WriteString(" ");
                WriteTypeReference(baseClass, writer);
            }
        }
        /// <summary>
        /// Write out class syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteClassSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (this.IsUnsupported(reflection, writer))
            {
                return;
            }

            if (HasAttribute(reflection, "System.RecordAttribute"))
            {
                WriteRecordSyntax(reflection, writer);
                return;
            }

            string identifier = ReadFullTypeName(reflection);

            writer.WriteIdentifier(identifier);
            writer.WriteString(" = ");
            writer.WriteKeyword("function");
            writer.WriteString("();");
            writer.WriteLine();
            writer.WriteLine();
            writer.WriteIdentifier("Type");
            writer.WriteString(".createClass(");
            writer.WriteLine();
            writer.WriteString("\t'");
            writer.WriteString(identifier);
            writer.WriteString("'");

            bool           hasBaseClass = false;
            XPathNavigator reference    = reflection.SelectSingleNode(apiBaseClassExpression);

            if (!(reference == null || (bool)reference.Evaluate(typeIsObjectExpression)))
            {
                WriteIndentedNewLine(writer);
                this.WriteTypeReference(reference, writer);
                hasBaseClass = true;
            }

            XPathNodeIterator iterator = reflection.Select(apiImplementedInterfacesExpression);

            if (iterator.Count != 0)
            {
                if (!hasBaseClass)
                {
                    WriteIndentedNewLine(writer);
                    writer.WriteString("null");
                }

                WriteIndentedNewLine(writer);

                while (iterator.MoveNext())
                {
                    XPathNavigator current = iterator.Current;
                    this.WriteTypeReference(current, writer);

                    if (iterator.CurrentPosition < iterator.Count)
                    {
                        WriteIndentedNewLine(writer);
                    }
                }
            }

            writer.WriteString(");");
        }
        // Parameters

        private void WriteParameters(XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNodeIterator parameters = reflection.Select(apiParametersExpression);

            if(parameters.Count == 0)
                return;

            writer.WriteString(" ( ");

            if(includeLineContinuation)
                writer.WriteString("_");

            writer.WriteLine();

            while(parameters.MoveNext())
            {
                XPathNavigator parameter = parameters.Current;

                // !EFW - Added support for optional parameter values
                XPathNavigator argument = (XPathNavigator)parameter.SelectSingleNode(parameterArgumentExpression);
                bool isOptional = (bool)parameter.Evaluate(parameterIsOptionalExpression);

                XPathNavigator type = parameter.SelectSingleNode(parameterTypeExpression);
                string name = (string)parameter.Evaluate(parameterNameExpression);
                bool isOut = (bool)parameter.Evaluate(parameterIsOutExpression);
                bool isParamArray = (bool)parameter.Evaluate(parameterIsParamArrayExpression);
                bool isByRef = (bool)parameter.Evaluate(parameterIsRefExpression);

                writer.WriteString("\t");

                // !EFW - Optional indicated by OptionalAttribute?
                if(isOptional && argument == null)
                {
                    WriteAttribute("T:System.Runtime.InteropServices.OptionalAttribute", false, writer);
                    writer.WriteString(" ");
                }

                if(isOut)
                {
                    WriteAttribute("T:System.Runtime.InteropServices.OutAttribute", false, writer);
                    writer.WriteString(" ");
                }

                // !EFW - Write out parameter attributes
                WriteAttributes(parameter, writer, null, true);

                // !EFW - Write optional value if present
                if(argument != null)
                    writer.WriteString("Optional ");

                if(isParamArray)
                {
                    writer.WriteKeyword("ParamArray");
                    writer.WriteString(" ");
                }

                if(isByRef)
                {
                    writer.WriteKeyword("ByRef");
                    writer.WriteString(" ");
                }

                writer.WriteParameter(name);
                writer.WriteString(" ");
                writer.WriteKeyword("As");
                writer.WriteString(" ");
                WriteTypeReference(type, writer);

                // !EFW - Write optional value if present
                if(argument != null)
                {
                    writer.WriteString(" = ");
                    this.WriteValue(argument, writer);
                }

                if(parameters.CurrentPosition < parameters.Count)
                    writer.WriteString(",");

                if(includeLineContinuation)
                    writer.WriteString(" _");

                writer.WriteLine();
            }

            writer.WriteString(")");
        }
예제 #46
0
        /// <inheritdoc />
        public override void WriteOperatorSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            string         name       = (string)reflection.Evaluate(apiNameExpression);
            XPathNavigator returnType = reflection.SelectSingleNode(apiReturnTypeExpression);

            // Determine operator identifier and type
            string identifier = null;
            int    type       = 0;

            if (!(bool)reflection.Evaluate(apiIsUdtReturnExpression))
            {
                switch (name)
                {
                // unary math operators
                case "UnaryPlus":
                    identifier = "+";
                    type       = -1;
                    break;

                case "UnaryNegation":
                    identifier = "-";
                    type       = -1;
                    break;

                case "Increment":
                    identifier = "++";
                    type       = +1;
                    break;

                case "Decrement":
                    identifier = "--";
                    type       = +1;
                    break;

                // unary logical operators
                case "LogicalNot":
                    identifier = "Not";
                    type       = -1;
                    break;

                case "True":
                    identifier = "IsTrue";
                    type       = -1;
                    break;

                case "False":
                    identifier = "IsFalse";
                    type       = -1;
                    break;

                // binary comparison operators
                case "Equality":
                    identifier = "=";
                    type       = 2;
                    break;

                case "Inequality":
                    identifier = "<>";
                    type       = 2;
                    break;

                case "LessThan":
                    identifier = "<";
                    type       = 2;
                    break;

                case "GreaterThan":
                    identifier = ">";
                    type       = 2;
                    break;

                case "LessThanOrEqual":
                    identifier = "<=";
                    type       = 2;
                    break;

                case "GreaterThanOrEqual":
                    identifier = ">=";
                    type       = 2;
                    break;

                // binary math operators
                case "Addition":
                    identifier = "+";
                    type       = 2;
                    break;

                case "Subtraction":
                    identifier = "-";
                    type       = 2;
                    break;

                case "Multiply":
                    identifier = "*";
                    type       = 2;
                    break;

                case "Division":
                    identifier = "/";
                    type       = 2;
                    break;

                case "Exponent":
                    identifier = "^";
                    type       = 2;
                    break;

                case "Modulus":
                    identifier = "Mod";
                    type       = 2;
                    break;

                case "IntegerDivision":
                    identifier = @"\";
                    type       = 2;
                    break;

                // binary logical operators
                case "BitwiseAnd":
                    identifier = "And";
                    type       = 2;
                    break;

                case "BitwiseOr":
                    identifier = "Or";
                    type       = 2;
                    break;

                case "ExclusiveOr":
                    identifier = "Xor";
                    type       = 2;
                    break;

                // bit-array operators
                case "OnesComplement":
                    identifier = "~";
                    type       = -1;
                    break;

                case "LeftShift":
                    identifier = "<<";
                    type       = 2;
                    break;

                case "RightShift":
                    identifier = ">>";
                    type       = 2;
                    break;

                // concatenation
                case "Concatenate":
                    identifier = "&";
                    type       = 2;
                    break;

                case "Assign":
                    identifier = "=";
                    type       = 2;
                    break;

                // didn't recognize an operator
                default:
                    identifier = null;
                    type       = 0;
                    break;
                }
            }

            if (identifier == null)
            {
                writer.WriteMessage("UnsupportedOperator_" + Language);
            }
            else
            {
                XPathNodeIterator parameters = reflection.Select(apiParametersExpression);

                if (parameters.Count != Math.Abs(type))
                {
                    writer.WriteMessage("UnsupportedOperator_" + Language);
                    return;
                }   //throw new InvalidOperationException("An operator has the wrong number of parameters.");

                WriteParameterDeclarations(reflection, writer);
                ParameterDeclaration("returnValue", returnType, writer);

                writer.WriteLine();
                writer.WriteParameter("returnValue");
                writer.WriteString(" = ");

                switch (type)
                {
                case -1:
                    writer.WriteIdentifier(identifier);
                    parameters.MoveNext();
                    writer.WriteParameter((string)parameters.Current.Evaluate(parameterNameExpression));
                    break;

                case +1:
                    parameters.MoveNext();
                    writer.WriteParameter((string)parameters.Current.Evaluate(parameterNameExpression));
                    writer.WriteIdentifier(identifier);
                    break;

                case 2:
                    writer.WriteString("(");

                    // parameter 1
                    parameters.MoveNext();
                    writer.WriteParameter((string)parameters.Current.Evaluate(parameterNameExpression));

                    writer.WriteString(" ");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString(" ");

                    // parameter 2
                    parameters.MoveNext();
                    writer.WriteParameter((string)parameters.Current.Evaluate(parameterNameExpression));

                    writer.WriteString(")");
                    break;
                }
            }
        }
        /// <inheritdoc />
        public override void WriteNormalMethodSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            // !EFW - Added unsafe check
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            if(IsUnsupportedVarargs(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);
            bool isExplicit = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);

            WriteAttributes(reflection, writer);
            WriteProcedureModifiers(reflection, writer);

            if(type == null)
                writer.WriteKeyword("Sub");
            else
                writer.WriteKeyword("Function");

            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteGenericTemplates(reflection, writer);
            WriteParameters(reflection, writer);

            if(type != null)
            {
                writer.WriteString(" ");
                writer.WriteKeyword("As");
                writer.WriteString(" ");
                WriteTypeReference(type, writer);
            }

            if(isExplicit)
            {
                if(writer.Position > MaxPosition)
                {
                    writer.WriteLine();
                    writer.WriteString("\t");
                }
                else
                    writer.WriteString(" ");

                writer.WriteKeyword("Implements");
                writer.WriteString(" ");
                XPathNodeIterator implementations = reflection.Select(apiImplementedMembersExpression);

                while(implementations.MoveNext())
                {
                    XPathNavigator implementation = implementations.Current;
                    XPathNavigator contract = implementation.SelectSingleNode(attributeTypeExpression);
                    // string id = implementation.GetAttribute("api", String.Empty);
                    if(implementations.CurrentPosition > 1)
                        writer.WriteString(", ");
                    WriteTypeReference(contract, writer);
                    writer.WriteString(".");
                    WriteMemberReference(implementation, writer);
                }
            }
        }
예제 #48
0
        /// <inheritdoc />
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (IsUnsupportedUnsafe(reflection, writer))
            {
                return;
            }

            bool           isStatic      = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool           isFamily      = (bool)reflection.Evaluate(apiIsFamilyMemberExpression);
            XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);
            XPathNavigator propertyType  = reflection.SelectSingleNode(apiReturnTypeExpression);
            bool           getter        = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool           setter        = (bool)reflection.Evaluate(apiIsWritePropertyExpression);

            if (!(isStatic || isFamily))
            {
                ParameterDeclaration("instance", declaringType, writer);
            }

            WriteParameterDeclarations(reflection, writer);

            // Some F# properties don't generate return type info for some reason.  It's probably unsupported
            // but just ignore them for now and write out what we do have.
            if (propertyType != null)
            {
                ParameterDeclaration("value", propertyType, writer);
            }

            // get value
            if (getter)
            {
                string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);

                if (String.IsNullOrEmpty(getVisibility) || (getVisibility != "assembly" &&
                                                            getVisibility != "private" && getVisibility != "family and assembly"))
                {
                    writer.WriteLine();
                    writer.WriteParameter("value");
                    writer.WriteString(" = ");
                    WriteMemberName(reflection, writer);
                    WritePropertyParameters(reflection, writer);
                    writer.WriteLine();
                }
            }

            // set value
            if (setter)
            {
                string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);

                if (String.IsNullOrEmpty(setVisibility) || (setVisibility != "assembly" &&
                                                            setVisibility != "private" && setVisibility != "family and assembly"))
                {
                    writer.WriteLine();
                    WriteMemberName(reflection, writer);
                    WritePropertyParameters(reflection, writer);
                    writer.WriteString(" = ");
                    writer.WriteParameter("value");
                }
            }
        }
        private void WriteExplicitImplementations(XPathNavigator reflection, SyntaxWriter writer)
        {
            bool isExplicit = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);

            if(isExplicit)
            {
                if(writer.Position > MaxPosition)
                {
                    writer.WriteLine();
                    writer.WriteString("\t");
                }
                else
                    writer.WriteString(" ");

                writer.WriteKeyword("Implements");
                writer.WriteString(" ");
                XPathNodeIterator implementations = reflection.Select(apiImplementedMembersExpression);

                while(implementations.MoveNext())
                {
                    XPathNavigator implementation = implementations.Current;
                    XPathNavigator contract = implementation.SelectSingleNode(memberDeclaringTypeExpression);

                    //string id = implementation.GetAttribute("api", String.Empty);
                    if(implementations.CurrentPosition > 1)
                        writer.WriteString(", ");

                    WriteTypeReference(contract, writer);
                    writer.WriteString(".");
                    WriteMemberReference(implementation, writer);
                    //writer.WriteReferenceLink(id);	
                }
            }
        }
        /// <summary>
        /// Write out property syntax if supported
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (this.IsUnsupported(reflection, writer))
            {
                return;
            }

            if (HasAttribute(reflection, "System.IntrinsicPropertyAttribute"))
            {
                this.WriteFieldSyntax(reflection, writer);
                return;
            }

            string identifier  = ReadMemberName(reflection);
            bool   isStatic    = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool   isReadProp  = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool   isWriteProp = (bool)reflection.Evaluate(apiIsWritePropertyExpression);

            if (isReadProp)
            {
                if (isStatic)
                {
                    writer.WriteIdentifier(ReadFullContainingTypeName(reflection));
                    writer.WriteString(".");
                    writer.WriteString("get_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString(" = ");
                    writer.WriteKeyword("function");
                }
                else
                {
                    writer.WriteKeyword("function");
                    writer.WriteString(" ");
                    writer.WriteString("get_");
                    writer.WriteIdentifier(identifier);
                }

                WriteParameterList(reflection, writer);
                writer.WriteString(";");
                writer.WriteLine();
            }

            if (isWriteProp)
            {
                if (isStatic)
                {
                    writer.WriteIdentifier(ReadFullContainingTypeName(reflection));
                    writer.WriteString(".");
                    writer.WriteString("set_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString(" = ");
                    writer.WriteKeyword("function");
                }
                else
                {
                    writer.WriteKeyword("function");
                    writer.WriteString(" ");
                    writer.WriteString("set_");
                    writer.WriteIdentifier(identifier);
                }

                writer.WriteString("(");
                writer.WriteParameter("value");
                writer.WriteString(");");
            }
        }
        private void WriteParameters(XPathNodeIterator parameters, SyntaxWriter writer)
        {
            List<KeyValuePair<string, XPathNavigator>> optionalParams = new List<KeyValuePair<string, XPathNavigator>>();
            writer.WriteLine();

            while(parameters.MoveNext())
            {
                XPathNavigator parameter = parameters.Current;

                // !EFW - Added support for optional parameter values
                XPathNavigator argument = (XPathNavigator)parameter.SelectSingleNode(parameterArgumentExpression);
                bool isOptional = (bool)parameter.Evaluate(parameterIsOptionalExpression);

                string name = (string)parameter.Evaluate(parameterNameExpression);
                bool isOut = (bool)parameter.Evaluate(parameterIsOutExpression);
                bool isRef = (bool)parameter.Evaluate(parameterIsRefExpression);
                XPathNavigator type = parameter.SelectSingleNode(parameterTypeExpression);
                writer.WriteString("        ");

                // !EFW - Write out parameter attributes
                WriteAttributes(parameter, writer, null, true);

                // !EFW - Optional indicated by OptionalAttribute?
                if(isOptional)
                    if(argument == null)
                    {
                        WriteAttribute("T:System.Runtime.InteropServices.OptionalAttribute", false, writer);
                        writer.WriteString(" ");
                    }
                    else
                    {
                        writer.WriteString("?");
                        optionalParams.Add(new KeyValuePair<string, XPathNavigator>(name, argument));
                    }

                writer.WriteParameter(name);
                writer.WriteString(" : ");
                WriteTypeReference(type, writer);

                if(isOut || isRef)
                {
                    writer.WriteString(" ");
                    writer.WriteKeyword("byref");
                }

                if(parameters.CurrentPosition != parameters.Count)
                {
                    writer.WriteString(" * ");
                    writer.WriteLine();
                }
                else
                    writer.WriteString(" ");
            }

            // !EFW - Write out the optional value assignments.  F# uses a function to assign defaults so we'll
            // just list them in a "comment" block.  There's probably a better way to do this but I know nothing
            // about F#.
            if(optionalParams.Count != 0)
            {
                writer.WriteLine();
                writer.WriteString("(* Defaults:");
                writer.WriteLine();

                foreach(var kv in optionalParams)
                {
                    writer.WriteString("        ");
                    writer.WriteKeyword("let ");
                    writer.WriteIdentifier("_");
                    writer.WriteIdentifier(kv.Key);
                    writer.WriteString(" = defaultArg ");
                    writer.WriteIdentifier(kv.Key);
                    writer.WriteString(" ");
                    this.WriteValue(kv.Value, writer);
                    writer.WriteLine();
                }

                writer.WriteString("*)");
                writer.WriteLine();
            }
        }
예제 #52
0
        /// <inheritdoc />
        public override void WriteDelegateSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if(IsUnsupportedUnsafe(reflection, writer))
                return;
            if(IsUnsupportedGeneric(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);

            writer.WriteString("/** @delegate */");
            writer.WriteLine();

            if(isSerializable)
                WriteAttribute("T:System.SerializableAttribute", writer);
            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            writer.WriteKeyword("delegate");
            writer.WriteString(" ");
            WriteReturnValue(reflection, writer);
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteMethodParameters(reflection, writer);

        }
        /// <inheritdoc />
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            // !EFW - Added unsafe check
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            bool isGettable = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool isSettable = (bool)reflection.Evaluate(apiIsWritePropertyExpression);

            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool isVirtual = (bool)reflection.Evaluate(apiIsVirtualExpression) && !(bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
            int iterations = isVirtual ? 2 : 1;

            for(int i = 0; i < iterations; i++)
            {
                WriteAttributes(reflection, writer);
                WriteVisibility(reflection, writer);

                if(isStatic)
                {
                    writer.WriteKeyword("static");
                    writer.WriteString(" ");
                }

                if(isVirtual)
                    if(i == 0)
                    {
                        writer.WriteKeyword("abstract");
                        writer.WriteString(" ");
                    }
                    else
                    {
                        writer.WriteKeyword("override");
                        writer.WriteString(" ");
                    }
                else
                {
                    WriteMemberKeyword(reflection, writer);
                }

                writer.WriteIdentifier(name);
                writer.WriteString(" : ");
                WriteReturnValue(reflection, writer);

                writer.WriteString(" ");
                writer.WriteKeyword("with");
                writer.WriteString(" ");

                if(isGettable)
                {
                    // !EFW - Added support for getter/setter attributes
                    XPathNavigator getter = reflection.SelectSingleNode(apiGetterExpression);

                    if(getter != null && getter.HasChildren)
                    {
                        writer.WriteLine();
                        writer.WriteString("\t");
                        this.WriteAttributes(getter, writer, "\t");
                        writer.WriteString("\t");
                    }

                    string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);

                    if(!String.IsNullOrEmpty(getVisibility))
                    {
                        WriteVisibility(getVisibility, writer);
                    }

                    writer.WriteKeyword("get");
                }

                if(isSettable)
                {
                    if(isGettable)
                        writer.WriteString(", ");

                    // !EFW - Added support for getter/setter attributes
                    XPathNavigator setter = reflection.SelectSingleNode(apiSetterExpression);

                    if(setter != null && setter.HasChildren)
                    {
                        writer.WriteLine();
                        writer.WriteString("\t");
                        this.WriteAttributes(setter, writer, "\t");
                        writer.WriteString("\t");
                    }

                    string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);

                    if(!String.IsNullOrEmpty(setVisibility))
                    {
                        WriteVisibility(setVisibility, writer);
                    }

                    writer.WriteKeyword("set");
                }

                if(i == 0)
                    writer.WriteLine();
            }
        }
예제 #54
0
        /// <inheritdoc />
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            if(IsUnsupportedExplicit(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            bool isGettable = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool isSettable = (bool)reflection.Evaluate(apiIsWritePropertyExpression);

            if(isGettable)
            {
                writer.WriteString("/** @property */");
                writer.WriteLine();

                // !EFW - Added support for getter/setter attributes
                XPathNavigator getter = reflection.SelectSingleNode(apiGetterExpression);

                if(getter != null && getter.HasChildren)
                    this.WriteAttributes(getter, writer);

                // write getter method
                WriteAttributes(reflection, writer);
                WriteProcedureModifiers(reflection, writer);
                WriteReturnValue(reflection, writer);
                writer.WriteString(" ");
                writer.WriteIdentifier("get_" + name);
                WriteMethodParameters(reflection, writer);
                writer.WriteLine();
            }

            if(isSettable)
            {
                writer.WriteString("/** @property */");
                writer.WriteLine();

                // !EFW - Added support for getter/setter attributes
                XPathNavigator setter = reflection.SelectSingleNode(apiSetterExpression);

                if(setter != null && setter.HasChildren)
                    this.WriteAttributes(setter, writer);

                // write setter method
                WriteAttributes(reflection, writer);
                WriteProcedureModifiers(reflection, writer);
                writer.WriteKeyword("void");
                writer.WriteString(" ");
                writer.WriteIdentifier("set_" + name);

                // parameters
                writer.WriteString("(");
                WriteReturnValue(reflection, writer);
                writer.WriteString(" ");
                writer.WriteParameter("value");
                writer.WriteString(")");

                // end parameters
                writer.WriteLine();
            }
        }
        private void WriteDotNetObject(XPathNavigator reflection, SyntaxWriter writer, string kind)
        {
            string name = reflection.Evaluate(apiNameExpression).ToString();
            bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);
            XPathNodeIterator implements = reflection.Select(apiImplementedInterfacesExpression);
            XPathNavigator baseClass = reflection.SelectSingleNode(apiBaseClassExpression);
            bool hasBaseClass = (baseClass != null) && !((bool)baseClass.Evaluate(typeIsObjectExpression));

            // CLR considers interfaces abstract.
            bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractTypeExpression) && kind != "interface";
            bool isSealed = (bool)reflection.Evaluate(apiIsSealedTypeExpression);

            if(isAbstract)
                WriteAttribute("T:Microsoft.FSharp.Core.AbstractClassAttribute", true, writer);
            if(isSealed)
                WriteAttribute("T:Microsoft.FSharp.Core.SealedAttribute", true, writer);

            if(isSerializable)
                WriteAttribute("T:System.SerializableAttribute", true, writer);
            WriteAttributes(reflection, writer);

            writer.WriteKeyword("type");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteGenericTemplates(reflection, writer);
            writer.WriteString(" =  ");

            if(hasBaseClass || implements.Count != 0)
            {
                writer.WriteLine();
                writer.WriteString("    ");
            }
            writer.WriteKeyword(kind);

            if(hasBaseClass || implements.Count != 0)
            {
                writer.WriteLine();
            }

            if(hasBaseClass)
            {
                writer.WriteString("        ");
                writer.WriteKeyword("inherit");
                writer.WriteString(" ");
                WriteTypeReference(baseClass, writer);
                writer.WriteLine();
            }


            while(implements.MoveNext())
            {
                XPathNavigator implement = implements.Current;
                writer.WriteString("        ");
                writer.WriteKeyword("interface");
                writer.WriteString(" ");
                WriteTypeReference(implement, writer);
                writer.WriteLine();
            }

            if(hasBaseClass || implements.Count != 0)
            {
                writer.WriteString("    ");
            }
            else
            {
                writer.WriteString(" ");
            }

            writer.WriteKeyword("end");

        }
예제 #56
0
        /// <inheritdoc />
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool isFamily = (bool)reflection.Evaluate(apiIsFamilyMemberExpression);
            XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);
            XPathNavigator propertyType = reflection.SelectSingleNode(apiReturnTypeExpression);
            bool getter = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool setter = (bool)reflection.Evaluate(apiIsWritePropertyExpression);

            if(!(isStatic || isFamily))
                ParameterDeclaration("instance", declaringType, writer);
            WriteParameterDeclarations(reflection, writer);
            ParameterDeclaration("value", propertyType, writer);

            // get value
            if(getter)
            {
                string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);
                if(string.IsNullOrEmpty(getVisibility) || (getVisibility != "assembly" &&
                    getVisibility != "private" && getVisibility != "family and assembly"))
                {
                    writer.WriteLine();
                    writer.WriteParameter("value");
                    writer.WriteString(" = ");
                    WriteMemberName(reflection, writer);
                    WritePropertyParameters(reflection, writer);
                    writer.WriteLine();
                }
            }

            // set value
            if(setter)
            {
                string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);
                if(string.IsNullOrEmpty(setVisibility) || (setVisibility != "assembly" &&
                    setVisibility != "private" && setVisibility != "family and assembly"))
                {
                    writer.WriteLine();
                    WriteMemberName(reflection, writer);
                    WritePropertyParameters(reflection, writer);
                    writer.WriteString(" = ");
                    writer.WriteParameter("value");
                }
            }

        }
        // !EFW - Added indent parameter for property getter/setter attributes.  Added parameterAttributes to
        // suppress line feeds for method parameter attributes.
        private void WriteAttributes(XPathNavigator reflection, SyntaxWriter writer, string indent = null,
            bool parameterAttributes = false)
        {
            // Handle interop attributes first as they are output in metadata
            if(!parameterAttributes)
                WriteInteropAttributes(reflection, writer, indent);

            // Add the standard attributes
            XPathNodeIterator attributes = (XPathNodeIterator)reflection.Evaluate(apiAttributesExpression);

            foreach(XPathNavigator attribute in attributes)
            {
                XPathNavigator type = attribute.SelectSingleNode(attributeTypeExpression);

                // !EFW - Ignore FixedBufferAttribute and ParamArrayAttribute
                if(type.GetAttribute("api", String.Empty) == "T:System.Runtime.CompilerServices.FixedBufferAttribute" ||
                  type.GetAttribute("api", String.Empty) == "T:System.ParamArrayAttribute")
                    continue;

                writer.WriteString("[<");
                WriteTypeReference(type, writer);

                XPathNodeIterator arguments = (XPathNodeIterator)attribute.Select(attributeArgumentsExpression);
                XPathNodeIterator assignments = (XPathNodeIterator)attribute.Select(attributeAssignmentsExpression);

                if((arguments.Count > 0) || (assignments.Count > 0))
                {
                    writer.WriteString("(");

                    while(arguments.MoveNext())
                    {
                        XPathNavigator argument = arguments.Current;

                        if(arguments.CurrentPosition > 1)
                            WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");

                        WriteValue(argument, writer);
                    }

                    if(arguments.Count > 0 && assignments.Count > 0)
                        writer.WriteString(", ");

                    while(assignments.MoveNext())
                    {
                        XPathNavigator assignment = assignments.Current;

                        if(assignments.CurrentPosition > 1)
                            WriteWithLineBreakIfNeeded(writer, ", ", indent + "\t");

                        writer.WriteString((string)assignment.Evaluate(assignmentNameExpression));
                        writer.WriteString(" = ");
                        WriteValue(assignment, writer);
                    }

                    writer.WriteString(")");
                }

                writer.WriteString(">]");

                if(!parameterAttributes)
                    writer.WriteLine();
            }

            if(parameterAttributes && attributes.Count != 0)
                writer.WriteString(" ");
        }
예제 #58
0
        /// <summary>
        /// Write out property syntax if supported
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WritePropertySyntax(XPathNavigator reflection,
                                                 SyntaxWriter writer)
        {
            if (this.IsUnsupported(reflection, writer))
            {
                return;
            }

            if (HasAttribute(reflection, "System.IntrinsicPropertyAttribute"))
            {
                this.WriteFieldSyntax(reflection, writer);
                return;
            }

            string identifier = ReadMemberName(reflection);
            bool   isStatic   = (bool)reflection.Evaluate(
                SyntaxGeneratorTemplate.apiIsStaticExpression);
            bool isReadProp = (bool)reflection.Evaluate(
                SyntaxGeneratorTemplate.apiIsReadPropertyExpression);
            bool isWriteProp = (bool)reflection.Evaluate(
                SyntaxGeneratorTemplate.apiIsWritePropertyExpression);

// EFW - Unused so removed
//            XPathNavigator navigator = reflection.SelectSingleNode(
//                SyntaxGeneratorTemplate.apiReturnTypeExpression);

            if (isReadProp)
            {
                if (isStatic)
                {
                    writer.WriteIdentifier(ReadFullContainingTypeName(
                                               reflection));
                    writer.WriteString(".");
                    writer.WriteString("get_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString(" = ");
                    writer.WriteKeyword("function");
                }
                else
                {
                    writer.WriteKeyword("function");
                    writer.WriteString(" ");
                    writer.WriteString("get_");
                    writer.WriteIdentifier(identifier);
                }

                WriteParameterList(reflection, writer);
                writer.WriteString(";");
                writer.WriteLine();
            }

            if (isWriteProp)
            {
                if (isStatic)
                {
                    writer.WriteIdentifier(ReadFullContainingTypeName(
                                               reflection));
                    writer.WriteString(".");
                    writer.WriteString("set_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString(" = ");
                    writer.WriteKeyword("function");
                }
                else
                {
                    writer.WriteKeyword("function");
                    writer.WriteString(" ");
                    writer.WriteString("set_");
                    writer.WriteIdentifier(identifier);
                }

                writer.WriteString("(");
                writer.WriteParameter("value");
                writer.WriteString(");");
            }
        }
        /// <inheritdoc />
        public override void WriteDelegateSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            // !EFW - Added unsafe check
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);

            if(isSerializable)
                WriteAttribute("T:System.SerializableAttribute", true, writer);

            WriteAttributes(reflection, writer);

            writer.WriteKeyword("type");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            writer.WriteString(" = ");
            writer.WriteLine();
            writer.WriteString("    ");
            writer.WriteKeyword("delegate");
            writer.WriteString(" ");
            writer.WriteKeyword("of");
            writer.WriteString(" ");

            WriteParameters(reflection, writer);

            writer.WriteKeyword("->");
            writer.WriteString(" ");
            WriteReturnValue(reflection, writer);

        }
 /// <summary>
 /// Write an indented new line
 /// </summary>
 /// <param name="writer">The syntax writer to which it is written</param>
 private static void WriteIndentedNewLine(SyntaxWriter writer)
 {
     writer.WriteString(",");
     writer.WriteLine();
     writer.WriteString("\t");
 }