Esempio n. 1
0
        /// <inheritdoc />
        public override void WriteAttachedEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

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

            string         eventName          = (string)reflection.Evaluate(apiNameExpression);
            string         containingTypeName = (string)reflection.Evaluate(apiContainingTypeNameExpression);
            XPathNavigator eventHandler       = reflection.SelectSingleNode(apiHandlerOfEventExpression);

            // xaml syntax block for attached event
            string xamlBlockId = Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);

            writer.WriteStartSubBlock(xamlBlockId);

            writer.WriteString("<");
            writer.WriteParameter("object ");
            writer.WriteIdentifier(containingTypeName + "." + eventName);
            writer.WriteString("=\"");
            WriteTypeReference(eventHandler, writer);
            writer.WriteString("\" .../>");

            writer.WriteEndSubBlock();
        }
        // namespace: done

        /// <inheritdoc />
        public override void WriteNamespaceSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string name = reflection.Evaluate(apiNameExpression).ToString();

            writer.WriteKeyword("namespace");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
        }
Esempio n. 3
0
        /// <inheritdoc />
        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 (IsUnsupportedGeneric(reflection, writer))
            {
                return;
            }

            string name           = reflection.Evaluate(apiNameExpression).ToString();
            bool   isAbstract     = (bool)reflection.Evaluate(apiIsAbstractTypeExpression);
            bool   isSealed       = (bool)reflection.Evaluate(apiIsSealedTypeExpression);
            bool   isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);

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

            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");

            if (isSealed)
            {
                writer.WriteKeyword("final");
                writer.WriteString(" ");
            }
            else if (isAbstract)
            {
                writer.WriteKeyword("abstract");
                writer.WriteString(" ");
            }

            writer.WriteKeyword("class");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);

            XPathNavigator baseClass = reflection.SelectSingleNode(apiBaseClassExpression);

            if ((baseClass != null) && !((bool)baseClass.Evaluate(typeIsObjectExpression)))
            {
                writer.WriteString(" ");
                writer.WriteKeyword("extends");
                writer.WriteString(" ");
                WriteTypeReference(baseClass, writer);
            }

            WriteImplementedInterfaces(reflection, writer);
        }
        /// <summary>
        /// Write out normal method syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteNormalMethodSyntax(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.AttachedPropertyAttribute"))
            {
                this.WriteAttachedPropertySyntax(reflection, writer);
                return;
            }

            string identifier = ReadMemberName(reflection);
            bool   isStatic   = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool   isGlobal   = (bool)reflection.Evaluate(memberIsGlobalExpression);

            if (isStatic && !isGlobal)
            {
                writer.WriteIdentifier(ReadFullContainingTypeName(reflection));
                writer.WriteString(".");
                writer.WriteIdentifier(identifier);
                writer.WriteString(" = ");
                writer.WriteKeyword("function");
            }
            else
            {
                writer.WriteKeyword("function");
                writer.WriteString(" ");
                writer.WriteIdentifier(identifier);
            }

            WriteParameterList(reflection, writer);
            writer.WriteString(";");
        }
Esempio n. 5
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(");");
        }
Esempio n. 6
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("');");
            }
        }
Esempio n. 7
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;
            }

            string name = (string)reflection.Evaluate(apiNameExpression);

            writer.WriteKeyword("Dim");
            writer.WriteString(" ");
            writer.WriteParameter("instance");
            writer.WriteString(" ");
            writer.WriteKeyword("As");
            writer.WriteString(" ");
            writer.WriteKeyword("New");
            writer.WriteString(" ");

            if (reservedWords.Contains(name))
            {
                writer.WriteString("[");
                writer.WriteIdentifier(name);
                writer.WriteString("]");
            }
            else
            {
                writer.WriteIdentifier(name);
            }

            WriteGenericTemplates(reflection, writer, true); // Need to write variance info for interfaces and delegates
            writer.WriteString("(");
            writer.WriteKeyword("AddressOf");
            writer.WriteString(" HandlerMethod)");
        }
Esempio n. 8
0
        /// <summary>
        /// Write out namespace syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteNamespaceSyntax(XPathNavigator reflection,
                                                  SyntaxWriter writer)
        {
            string identifier = reflection.Evaluate(
                SyntaxGeneratorTemplate.apiNameExpression).ToString();

            writer.WriteString("Type.createNamespace('");
            writer.WriteIdentifier(identifier);
            writer.WriteString("');");
        }
Esempio n. 9
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();
        }
Esempio n. 10
0
        /// <summary>
        /// Write out field syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteFieldSyntax(XPathNavigator reflection,
                                              SyntaxWriter writer)
        {
            if (!this.IsUnsupported(reflection, writer))
            {
                string identifier = ReadMemberName(reflection);

                // EFW - Added "var" keyword before field name
                writer.WriteKeyword("var");
                writer.WriteString(" ");

                if ((bool)reflection.Evaluate(
                        SyntaxGeneratorTemplate.apiIsStaticExpression))
                {
                    writer.WriteIdentifier(ReadFullContainingTypeName(
                                               reflection));
                    writer.WriteString(".");
                }

                writer.WriteIdentifier(identifier);
            }
        }
Esempio n. 11
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);
            XPathNavigator type       = reflection.SelectSingleNode(apiReturnTypeExpression);

            WriteAccessModifier(reflection, writer);

            if (isStatic)
            {
                if (isLiteral)
                {
                    writer.WriteKeyword("const");
                }
                else
                {
                    writer.WriteKeyword("static");
                }

                writer.WriteString(" ");
            }

            if (isInitOnly)
            {
                writer.WriteKeyword("final");
                writer.WriteString(" ");
            }

            writer.WriteKeyword("var");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            writer.WriteString(" : ");
            WriteTypeReference(type, writer);
        }
        /// <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(");");
                }
            }
        }
Esempio n. 13
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));
            }

            // !EFW - Added unsafe check
            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   isSerialized = (bool)reflection.Evaluate(apiIsSerializedFieldExpression);

            if (!isSerialized)
            {
                WriteAttribute("T:System.NonSerializedAttribute", writer);
            }
            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");

            // Java doesn't support literals as distinct from static initonly
            if (isStatic)
            {
                writer.WriteKeyword("static");
                writer.WriteString(" ");
            }

            if (isLiteral || isInitOnly)
            {
                writer.WriteKeyword("final");
                writer.WriteString(" ");
            }

            WriteReturnValue(reflection, writer);
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
        }
Esempio n. 14
0
        // what about generic methods?

        private void WriteMemberName(XPathNavigator reflection, SyntaxWriter writer)
        {
            string         name          = (string)reflection.Evaluate(apiNameExpression);
            bool           isExplicit    = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);
            bool           isStatic      = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool           isFamily      = (bool)reflection.Evaluate(apiIsFamilyMemberExpression);
            bool           isDefault     = (bool)reflection.Evaluate(apiIsDefaultMemberExpression);
            XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);

            if (isExplicit)
            {
                XPathNavigator member   = reflection.SelectSingleNode(apiImplementedMembersExpression);
                XPathNavigator contract = member.SelectSingleNode(memberDeclaringTypeExpression);
                writer.WriteKeyword("CType");
                writer.WriteString("(");
                writer.WriteParameter("instance");
                writer.WriteString(", ");
                WriteTypeReference(contract, writer);
                writer.WriteString(").");
                WriteMemberReference(member, writer);
            }
            else
            {
                if (isStatic)
                {
                    WriteTypeReference(declaringType, writer);
                }
                else
                {
                    if (isFamily)
                    {
                        writer.WriteKeyword("Me");
                    }
                    else
                    {
                        writer.WriteString("instance");
                    }
                }
                if (!isDefault)
                {
                    writer.WriteString(".");
                    writer.WriteIdentifier(name);
                }
            }
        }
Esempio n. 15
0
        /// <inheritdoc />
        public override void WriteNamespaceSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

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

            string name = reflection.Evaluate(apiNameExpression).ToString();

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

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

            string identifier = reflection.Evaluate(apiNameExpression).ToString();

            writer.WriteString("Type.createNamespace('");
            writer.WriteIdentifier(identifier);
            writer.WriteString("');");
        }
Esempio n. 17
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));
            }

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

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

            WriteProcedureModifiers(reflection, writer);
            writer.WriteKeyword("function");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteParameterList(reflection, writer);
            if (returnType != null)
            {
                writer.WriteString(" : ");
                WriteTypeReference(returnType, writer);
            }
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        /// <inheritdoc />
        public override void WriteStructureSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

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

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

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

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

            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);

            writer.WriteString(" ");
            writer.WriteKeyword("final");
            writer.WriteString(" ");
            writer.WriteKeyword("class");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);

            writer.WriteString(" ");
            writer.WriteKeyword("extends");
            writer.WriteString(" ");
            writer.WriteReferenceLink("T:System.ValueType");

            WriteImplementedInterfaces(reflection, writer);
        }
Esempio n. 20
0
        // An Attribute Usage block
        private void PropertyAttributeUsage(XPathNavigator propertyReflection, SyntaxWriter writer)
        {
            string         xamlBlockId  = Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);
            string         propertyName = (string)propertyReflection.Evaluate(apiNameExpression);
            XPathNavigator returnType   = propertyReflection.SelectSingleNode(apiReturnTypeExpression);

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

            // syntax looks like:
            //   <object PropertyName="linkToType" .../>
            writer.WriteString("<");
            writer.WriteParameter("object ");
            writer.WriteIdentifier(propertyName);
            writer.WriteString("=\"");
            WriteTypeReference(returnType, writer);
            writer.WriteString("\" .../>");

            writer.WriteEndSubBlock();
        }
Esempio n. 21
0
        /// <summary>
        /// Write out constructor syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteConstructorSyntax(XPathNavigator reflection,
                                                    SyntaxWriter writer)
        {
            if (!this.IsUnsupported(reflection, writer))
            {
                if ((bool)reflection.Evaluate(typeIsRecordExpression))
                {
                    WriteRecordConstructorSyntax(reflection, writer);
                }
                else
                {
                    string identifier = ReadFullContainingTypeName(reflection);

                    writer.WriteIdentifier(identifier);
                    writer.WriteString(" = ");
                    writer.WriteKeyword("function");
                    WriteParameterList(reflection, writer);
                    writer.WriteString(";");
                }
            }
        }
Esempio n. 22
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));
            }

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

            string name = (string)reflection.Evaluate(apiNameExpression);

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

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

            WriteMethodParameters(reflection, writer);
        }
Esempio n. 23
0
        /// <inheritdoc />
        public override void WriteAttachedPropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

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

            string         propertyName       = (string)reflection.Evaluate(apiNameExpression);
            string         containingTypeName = (string)reflection.Evaluate(apiContainingTypeNameExpression);
            bool           isSettable         = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
            XPathNavigator returnType         = reflection.SelectSingleNode(apiReturnTypeExpression);

            if (!isSettable)
            {
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_readOnly, writer);
            }
            else
            {
                // xaml syntax block for attached property
                string xamlBlockId = Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);

                writer.WriteStartSubBlock(xamlBlockId);
                writer.WriteString("<");
                writer.WriteParameter("object ");
                writer.WriteIdentifier(containingTypeName + "." + propertyName);
                writer.WriteString("=\"");
                WriteTypeReference(returnType, writer);
                writer.WriteString("\" .../>");
                writer.WriteEndSubBlock();
            }
        }
        /// <inheritdoc />
        public override void WriteEnumerationSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {

            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(" ");
            WriteVisibility(reflection, writer);
            writer.WriteIdentifier(name);
        }
        /// <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();
            }
        }
        /// <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);

            WriteAttributes(reflection, writer);
            WriteProcedureModifiers(reflection, writer);
            writer.WriteString("Event");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            writer.WriteString(" ");
            writer.WriteKeyword("As");
            writer.WriteString(" ");
            WriteTypeReference(handler, writer);
            WriteExplicitImplementations(reflection, writer);
        }
        /// <inheritdoc />
        public override void WriteClassSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {

            string name = (string)reflection.Evaluate(apiNameExpression);
            bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractTypeExpression);
            bool isSealed = (bool)reflection.Evaluate(apiIsSealedTypeExpression);
            bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);

            if(isSerializable)
                WriteAttribute("T:System.SerializableAttribute", writer);
            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            if(isAbstract)
            {
                if(isSealed)
                {
                    // static -- VB doesn't really handle this case
                    writer.WriteKeyword("NotInheritable");
                    writer.WriteString(" ");
                }
                else
                {
                    writer.WriteKeyword("MustInherit");
                    writer.WriteString(" ");
                }
            }
            else if(isSealed)
            {
                writer.WriteKeyword("NotInheritable");
                writer.WriteString(" ");
            }
            writer.WriteKeyword("Class");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteGenericTemplates(reflection, writer);
            WriteBaseClass(reflection, writer);
            WriteImplementedInterfaces(reflection, writer);
        }
        /// <inheritdoc />
        public override void WriteConstructorSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);

            WriteAttributes(reflection, writer);
            if(isStatic)
            {
                writer.WriteKeyword("Shared");
            }
            else
            {
                WriteVisibility(reflection, writer);
            }
            writer.WriteString(" ");
            writer.WriteKeyword("Sub");
            writer.WriteString(" ");
            writer.WriteIdentifier("New");
            WriteParameters(reflection, writer);
        }
        /// <inheritdoc />
        public override void WriteOperatorSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {

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

            string identifier = null;
            if(!(bool)reflection.Evaluate(apiIsUdtReturnExpression))
            {
                switch(name)
                {
                    // unary math operators
                    case "UnaryPlus":
                        identifier = "+";
                        break;
                    case "UnaryNegation":
                        identifier = "-";
                        break;
                    case "Increment":
                        identifier = "++";
                        break;
                    case "Decrement":
                        identifier = "--";
                        break;
                    // unary logical operators
                    case "LogicalNot":
                        identifier = "Not";
                        break;
                    case "True":
                        identifier = "IsTrue";
                        break;
                    case "False":
                        identifier = "IsFalse";
                        break;
                    // binary comparison operators
                    case "Equality":
                        identifier = "=";
                        break;
                    case "Inequality":
                        identifier = "<>";
                        break;
                    case "LessThan":
                        identifier = "<";
                        break;
                    case "GreaterThan":
                        identifier = ">";
                        break;
                    case "LessThanOrEqual":
                        identifier = "<=";
                        break;
                    case "GreaterThanOrEqual":
                        identifier = ">=";
                        break;
                    // binary math operators
                    case "Addition":
                        identifier = "+";
                        break;
                    case "Subtraction":
                        identifier = "-";
                        break;
                    case "Multiply":
                        identifier = "*";
                        break;
                    case "Division":
                        identifier = "/";
                        break;
                    case "Exponent":
                        identifier = "^";
                        break;
                    case "Modulus":
                        identifier = "Mod";
                        break;
                    case "IntegerDivision":
                        identifier = @"\";
                        break;
                    // binary logical operators
                    case "BitwiseAnd":
                        identifier = "And";
                        break;
                    case "BitwiseOr":
                        identifier = "Or";
                        break;
                    case "ExclusiveOr":
                        identifier = "Xor";
                        break;
                    // bit-array operators
                    case "OnesComplement":
                        identifier = "~";
                        break;
                    case "LeftShift":
                        identifier = "<<";
                        break;
                    case "RightShift":
                        identifier = ">>";
                        break;
                    // concatenation
                    case "Concatenate":
                        identifier = "&";
                        break;
                    // casting operators
                    case "Implicit":
                    case "Explicit":
                        identifier = "CType";
                        break;
                    case "Assign":
                        identifier = "=";
                        break;
                    // didn't recognize an operator
                    default:
                        identifier = null;
                        break;
                }
            }
            if(identifier == null)
            {
                writer.WriteMessage("UnsupportedOperator_" + Language);
                return;
            }

            WriteProcedureModifiers(reflection, writer);

            if(name == "Implicit")
            {
                writer.WriteKeyword("Widening");
                writer.WriteString(" ");
            }
            else if(name == "Explicit")
            {
                writer.WriteKeyword("Narrowing");
                writer.WriteString(" ");
            }

            writer.WriteKeyword("Operator");
            writer.WriteString(" ");
            writer.WriteIdentifier(identifier);
            WriteParameters(reflection, writer);
            writer.WriteString(" ");
            writer.WriteKeyword("As");
            writer.WriteString(" ");
            WriteTypeReference(type, writer);
        }
Esempio n. 30
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));
            }

            string         eventName       = (string)reflection.Evaluate(apiNameExpression);
            string         eventVisibility = (string)reflection.Evaluate(apiVisibilityExpression);
            bool           isAbstract      = (bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
            XPathNavigator eventHandler    = reflection.SelectSingleNode(apiHandlerOfEventExpression);

            XPathNavigator containingType           = reflection.SelectSingleNode(apiContainingTypeExpression);
            string         containingTypeSubgroup   = (string)containingType.Evaluate(apiSubgroupExpression);
            bool           containingTypeIsAbstract = (bool)containingType.Evaluate(apiIsAbstractTypeExpression);
            bool           containingTypeIsSealed   = (bool)containingType.Evaluate(apiIsSealedTypeExpression);

            if (containingTypeSubgroup == "interface")
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_noXamlSyntaxForInterfaceMembers, writer);
            }
            else if (containingTypeIsAbstract && containingTypeIsSealed)
            {
                // the event's containing type is static if it's abstract and sealed
                // members of a static class cannot be used in XAML.
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_nonXamlParent, writer);
            }
            else if (IsExcludedSubClass(containingType))
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_parentIsExcludedSubClass, writer);
            }
            else if (!DoesParentSupportXaml(reflection))
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_nonXamlParent, writer);
            }
            else if (eventVisibility != "public")
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_notPublic, writer);
            }
            else if (isAbstract)
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_abstract, writer);
            }
            else
            {
                // start the syntax block
                string xamlBlockId = Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);
                writer.WriteStartSubBlock(xamlBlockId);

                // syntax looks like:
                //   <object eventName="eventHandlerLink" .../>
                writer.WriteString("<");
                writer.WriteParameter("object ");
                writer.WriteIdentifier(eventName);
                writer.WriteString("=\"");
                WriteTypeReference(eventHandler, writer);
                writer.WriteString("\" .../>");

                writer.WriteEndSubBlock();
            }
        }
        /// <inheritdoc />
        public override void WriteInterfaceSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {

            string name = (string)reflection.Evaluate(apiNameExpression);

            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            writer.WriteKeyword("Interface");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteGenericTemplates(reflection, writer, true); // Need to write variance info for interfaces and delegates
            WriteImplementedInterfaces(reflection, writer);
        }
        /// <inheritdoc />
        public override void WriteFieldSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            // !EFW - Added unsafe check
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool isInitOnly = (bool)reflection.Evaluate(apiIsInitOnlyFieldExpression);
            bool isSerialized = (bool)reflection.Evaluate(apiIsSerializedFieldExpression);

            if(!isSerialized)
                WriteAttribute("T:System.NonSerializedAttribute", true, writer);

            WriteAttributes(reflection, writer);

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

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

            if(!isInitOnly)
            {
                writer.WriteKeyword("mutable");
                writer.WriteString(" ");
            }

            WriteVisibility(reflection, writer);

            writer.WriteIdentifier(name);

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

        }
Esempio n. 33
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(")");
            }
        }
Esempio n. 34
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");
        }
Esempio n. 35
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;
                }
            }
        }
        /// <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(");");
        }
        /// <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();
            }
        }
Esempio n. 38
0
        /// <inheritdoc />
        public override void WriteFieldSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            // !EFW - Added unsafe check
            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 isSerialized = (bool)reflection.Evaluate(apiIsSerializedFieldExpression);

            if(!isSerialized)
                WriteAttribute("T:System.NonSerializedAttribute", writer);
            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            // Java doesn't support literals as distinct from static initonly
            if(isStatic)
            {
                writer.WriteKeyword("static");
                writer.WriteString(" ");
            }
            if(isLiteral || isInitOnly)
            {
                writer.WriteKeyword("final");
                writer.WriteString(" ");
            }
            WriteReturnValue(reflection, writer);
            writer.WriteString(" ");
            writer.WriteIdentifier(name);

        }
Esempio n. 39
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(");");
            }
        }
Esempio n. 40
0
        /// <inheritdoc />
        public override void WriteClassSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if(IsUnsupportedGeneric(reflection, writer))
                return;

            string name = reflection.Evaluate(apiNameExpression).ToString();
            bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractTypeExpression);
            bool isSealed = (bool)reflection.Evaluate(apiIsSealedTypeExpression);
            bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);

            if(isSerializable)
                WriteAttribute("T:System.SerializableAttribute", writer);
            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            if(isSealed)
            {
                writer.WriteKeyword("final");
                writer.WriteString(" ");
            }
            else if(isAbstract)
            {
                writer.WriteKeyword("abstract");
                writer.WriteString(" ");
            }
            writer.WriteKeyword("class");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);

            XPathNavigator baseClass = reflection.SelectSingleNode(apiBaseClassExpression);
            if((baseClass != null) && !((bool)baseClass.Evaluate(typeIsObjectExpression)))
            {
                writer.WriteString(" ");
                writer.WriteKeyword("extends");
                writer.WriteString(" ");
                WriteTypeReference(baseClass, writer);
            }

            WriteImplementedInterfaces(reflection, writer);

        }
        /// <inheritdoc />
        public override void WriteDelegateSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if(IsUnsupportedUnsafe(reflection, writer))
                return;

            string name = (string)reflection.Evaluate(apiNameExpression);
            bool isSerializable = (bool)reflection.Evaluate(apiIsSerializableTypeExpression);
            XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);

            if(isSerializable)
                WriteAttribute("T:System.SerializableAttribute", writer);
            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            writer.WriteKeyword("Delegate");
            writer.WriteString(" ");
            if(type == null)
            {
                writer.WriteKeyword("Sub");
            }
            else
            {
                writer.WriteKeyword("Function");
            }
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteGenericTemplates(reflection, writer, true); // Need to write variance info for interfaces and delegates
            WriteParameters(reflection, writer);
            if(type != null)
            {
                writer.WriteString(" ");
                writer.WriteKeyword("As");
                writer.WriteString(" ");
                WriteTypeReference(type, writer);
            }

        }
Esempio n. 42
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();
        }
        /// <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);
                }
            }
        }
Esempio n. 44
0
 /// <inheritdoc />
 public override void WriteAttachedPropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
 {
     string propertyName = (string)reflection.Evaluate(apiNameExpression);
     string containingTypeName = (string)reflection.Evaluate(apiContainingTypeNameExpression);
     bool isSettable = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
     XPathNavigator returnType = reflection.SelectSingleNode(apiReturnTypeExpression);
     if(!isSettable)
     {
         WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_readOnly, writer);
     }
     else
     {
         // xaml syntax block for attached property
         string xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);
         writer.WriteStartSubBlock(xamlBlockId);
         writer.WriteString("<");
         writer.WriteParameter("object ");
         writer.WriteIdentifier(containingTypeName + "." + propertyName);
         writer.WriteString("=\"");
         WriteTypeReference(returnType, writer);
         writer.WriteString("\" .../>");
         writer.WriteEndSubBlock();
     }
 }
        /// <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");
            }
        }
Esempio n. 46
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();
        }
        /// <inheritdoc />
        public override void WriteFieldSyntax(XPathNavigator reflection, SyntaxWriter 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 isSerialized = (bool)reflection.Evaluate(apiIsSerializedFieldExpression);
            XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);

            if(!isSerialized)
                WriteAttribute("T:System.NonSerializedAttribute", writer);
            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            if(isStatic)
            {
                if(isLiteral)
                {
                    writer.WriteKeyword("Const");
                }
                else
                {
                    writer.WriteKeyword("Shared");
                }
                writer.WriteString(" ");
            }
            if(isInitOnly)
            {
                writer.WriteKeyword("ReadOnly");
                writer.WriteString(" ");
            }
            writer.WriteIdentifier(name);
            writer.WriteString(" ");
            writer.WriteKeyword("As");
            writer.WriteString(" ");
            WriteTypeReference(type, writer);

        }
Esempio n. 48
0
        // An Attribute Usage block
        private void PropertyAttributeUsage(XPathNavigator propertyReflection, SyntaxWriter writer)
        {
            string xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);
            string propertyName = (string)propertyReflection.Evaluate(apiNameExpression);
            XPathNavigator returnType = propertyReflection.SelectSingleNode(apiReturnTypeExpression);

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

            // syntax looks like: 
            //   <object PropertyName="linkToType" .../>
            writer.WriteString("<");
            writer.WriteParameter("object ");
            writer.WriteIdentifier(propertyName);
            writer.WriteString("=\"");
            WriteTypeReference(returnType, writer);
            writer.WriteString("\" .../>");

            writer.WriteEndSubBlock();
        }
        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();
            }
        }
Esempio n. 50
0
        /// <inheritdoc />
        public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string eventName = (string)reflection.Evaluate(apiNameExpression);
            string eventVisibility = (string)reflection.Evaluate(apiVisibilityExpression);
            bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
            XPathNavigator eventHandler = reflection.SelectSingleNode(apiHandlerOfEventExpression);

            XPathNavigator containingType = reflection.SelectSingleNode(apiContainingTypeExpression);
            string containingTypeSubgroup = (string)containingType.Evaluate(apiSubgroupExpression);
            bool containingTypeIsAbstract = (bool)containingType.Evaluate(apiIsAbstractTypeExpression);
            bool containingTypeIsSealed = (bool)containingType.Evaluate(apiIsSealedTypeExpression);

            if(containingTypeSubgroup == "interface")
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_noXamlSyntaxForInterfaceMembers, writer);
            }
            else if(containingTypeIsAbstract && containingTypeIsSealed)
            {
                // the event's containing type is static if it's abstract and sealed
                // members of a static class cannot be used in XAML.
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_nonXamlParent, writer);
            }
            else if(IsExcludedSubClass(containingType))
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_parentIsExcludedSubClass, writer);
            }
            else if(!DoesParentSupportXaml(reflection))
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_nonXamlParent, writer);
            }
            else if(eventVisibility != "public")
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_notPublic, writer);
            }
            else if(isAbstract)
            {
                WriteXamlBoilerplate(XamlBoilerplateID.eventXamlSyntax_abstract, writer);
            }
            else
            {
                // start the syntax block
                string xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);
                writer.WriteStartSubBlock(xamlBlockId);

                // syntax looks like: 
                //   <object eventName="eventHandlerLink" .../>
                writer.WriteString("<");
                writer.WriteParameter("object ");
                writer.WriteIdentifier(eventName);
                writer.WriteString("=\"");
                WriteTypeReference(eventHandler, writer);
                writer.WriteString("\" .../>");

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

            string name = (string)reflection.Evaluate(apiContainingTypeNameExpression);

            WriteAttributes(reflection, writer);

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

        }
Esempio n. 52
0
        /// <inheritdoc />
        public override void WriteAttachedEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string eventName = (string)reflection.Evaluate(apiNameExpression);
            string containingTypeName = (string)reflection.Evaluate(apiContainingTypeNameExpression);
            XPathNavigator eventHandler = reflection.SelectSingleNode(apiHandlerOfEventExpression);

            // xaml syntax block for attached event
            string xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);
            writer.WriteStartSubBlock(xamlBlockId);

            writer.WriteString("<");
            writer.WriteParameter("object ");
            writer.WriteIdentifier(containingTypeName + "." + eventName);
            writer.WriteString("=\"");
            WriteTypeReference(eventHandler, writer);
            writer.WriteString("\" .../>");

            writer.WriteEndSubBlock();
        }
        /// <inheritdoc />
        public override void WriteOperatorSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string name = (string)reflection.Evaluate(apiNameExpression);
            string identifier = null;

            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);

            if(!(bool)reflection.Evaluate(apiIsUdtReturnExpression))
            {
                switch(name)
                {
                    // unary math operators
                    case "UnaryPlus":
                        identifier = "+";
                        break;
                    case "UnaryNegation":
                        identifier = "-";
                        break;
                    case "Increment":
                        identifier = "++";
                        break;
                    case "Decrement":
                        identifier = "--";
                        break;
                    // unary logical operators
                    case "LogicalNot":
                        identifier = "not";
                        break;
                    case "True":
                        identifier = "true";
                        break;
                    case "False":
                        identifier = "false";
                        break;
                    // binary comparison operators
                    case "Equality":
                        identifier = "=";
                        break;
                    case "Inequality":
                        identifier = "<>";
                        break;
                    case "LessThan":
                        identifier = "<";
                        break;
                    case "GreaterThan":
                        identifier = ">";
                        break;
                    case "LessThanOrEqual":
                        identifier = "<=";
                        break;
                    case "GreaterThanOrEqual":
                        identifier = ">=";
                        break;
                    // binary math operators
                    case "Addition":
                        identifier = "+";
                        break;
                    case "Subtraction":
                        identifier = "-";
                        break;
                    case "Multiply":
                        identifier = "*";
                        break;
                    case "Division":
                        identifier = "/";
                        break;
                    case "Modulus":
                        identifier = "%";
                        break;
                    // binary logical operators
                    case "BitwiseAnd":
                        identifier = "&&&";
                        break;
                    case "BitwiseOr":
                        identifier = "|||";
                        break;
                    case "ExclusiveOr":
                        identifier = "^^^";
                        break;
                    // bit-array operators
                    case "OnesComplement":
                        identifier = null; // No F# equiv.
                        break;
                    case "LeftShift":
                        identifier = "<<<";
                        break;
                    case "RightShift":
                        identifier = ">>>";
                        break;
                    case "Assign":
                        identifier = "=";
                        break;
                    // unrecognized operator
                    default:
                        identifier = null;
                        break;
                }
            }
            if(identifier == null)
            {
                writer.WriteMessage("UnsupportedOperator_" + Language);
            }
            else
            {
                if(isStatic)
                {
                    writer.WriteKeyword("static");
                    writer.WriteString(" ");
                }

                writer.WriteKeyword("let");
                writer.WriteString(" ");
                writer.WriteKeyword("inline");
                writer.WriteKeyword(" ");

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

                WriteParameters(reflection, writer);
                writer.WriteString(" : ");
                WriteReturnValue(reflection, writer);

            }
        }
        /// <inheritdoc />
        public override void WriteStructureSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {

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

            if(isSerializable)
                WriteAttribute("T:System.SerializableAttribute", writer);
            WriteAttributes(reflection, writer);
            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            writer.WriteKeyword("Structure");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
            WriteGenericTemplates(reflection, writer);
            WriteImplementedInterfaces(reflection, writer);
        }
        /// <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();
            }
        }
Esempio n. 56
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();
            }
        }
        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");

        }
        /// <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(");");
            }
        }
        /// <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);

        }
Esempio n. 60
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();

        }