/// <inheritdoc />
        public override void WriteClassSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if(IsUnsupportedGeneric(reflection, writer))
                return;

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

            WriteAccessModifier(reflection, writer);

            if(isSealed)
            {
                writer.WriteKeyword("final");
                writer.WriteString(" ");
            }
            else if(isAbstract)
            {
                writer.WriteKeyword("abstract");
                writer.WriteString(" ");
            }
            writer.WriteKeyword("class");
            writer.WriteString(" ");
            writer.WriteString(name);
            WriteBaseClass(reflection, writer);
            WriteInterfaceList(reflection, writer);
        }
        // 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);
        }
        /// <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(");");
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Write out the record constructor syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        private static void WriteRecordConstructorSyntax(
            XPathNavigator reflection, SyntaxWriter writer)
        {
            string nameSpace      = ReadNamespaceName(reflection);
            string containingType = ReadContainingTypeName(reflection);

            writer.WriteString(nameSpace);
            writer.WriteString(".$create_");
            writer.WriteString(containingType);
            writer.WriteString(" = ");
            writer.WriteKeyword("function");
            WriteParameterList(reflection, writer);
            writer.WriteString(";");
        }
Beispiel #5
0
        /// <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 (this.IsUnsupported(reflection, writer))
            {
                return;
            }

            if (HasAttribute(reflection, "System.AttachedPropertyAttribute"))
            {
                this.WriteAttachedPropertySyntax(reflection, writer);
                return;
            }

            string identifier = ReadMemberName(reflection);
            bool   isStatic   = (bool)reflection.Evaluate(SyntaxGeneratorTemplate.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(";");
        }
        private void ParameterDeclaration(string name, XPathNavigator type, SyntaxWriter writer)
        {
            writer.WriteKeyword("Dim");
            writer.WriteString(" ");
            writer.WriteParameter(name);
            writer.WriteString(" ");
            writer.WriteKeyword("As");
            writer.WriteString(" ");

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

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

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

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

            writer.WriteKeyword("function");
            WriteParameterList(reflection, writer);
            writer.WriteString(";");
        }
Beispiel #8
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(");");
        }
Beispiel #9
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("');");
            }
        }
        /// <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);
        }
Beispiel #11
0
        private void WriteMethodThrows(XPathNodeIterator exceptions, XPathNavigator reflection, SyntaxWriter writer)
        {
            writer.WriteString(" ");
            writer.WriteKeyword("throws");
            writer.WriteString(" ");

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

                WriteTypeReference(exception, writer);

                if (exceptions.CurrentPosition < exceptions.Count)
                {
                    writer.WriteString(",");
                }
                writer.WriteLine();
            }
        }
Beispiel #12
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);
            }
        }
        /// <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);
        }
        /// <inheritdoc />
        public override void WriteCastSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

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

            XPathNavigator parameter = reflection.SelectSingleNode(apiParametersExpression);

            if (parameter == null)
            {
                return;
            }

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

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

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

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

            WriteTypeReference(outputType, writer);

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

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

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

            WriteAccessModifier(reflection, writer);
            writer.WriteKeyword("enum");
            writer.WriteString(" ");
            writer.WriteString(name);
            // no JScript support for underlying types
        }
Beispiel #16
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(";");
                }
            }
        }
        /// <inheritdoc />
        public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (reflection == null)
            {
                throw new ArgumentNullException(nameof(reflection));
            }

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

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

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

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

            ParameterDeclaration("handler", handler, writer);

            // adder
            writer.WriteLine();
            writer.WriteKeyword("AddHandler");
            writer.WriteString(" ");
            WriteMemberName(reflection, writer);
            writer.WriteString(", ");
            writer.WriteParameter("handler");
            writer.WriteLine();
        }
Beispiel #18
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);
            }
        }
        private void WriteImplementedInterfaces(string keyword, XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNodeIterator implements = reflection.Select(apiImplementedInterfacesExpression);

            if (implements.Count != 0)
            {
                writer.WriteString(" ");
                writer.WriteKeyword(keyword);
                writer.WriteString(" ");

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

                    if (implements.CurrentPosition < implements.Count)
                    {
                        WriteWithLineBreakIfNeeded(writer, ", ", "\t");
                    }
                }
            }
        }
Beispiel #20
0
        /// <summary>
        /// Write out attached property syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteAttachedPropertySyntax(
            XPathNavigator reflection, SyntaxWriter writer)
        {
            string containingTypeName = ReadContainingTypeName(reflection);
            string memberName         = ReadMemberName(reflection);
            string fullName           = String.Concat(containingTypeName, ".",
                                                      memberName.Substring(3));

            if (memberName.StartsWith("Get", StringComparison.OrdinalIgnoreCase))
            {
                writer.WriteKeyword("var");
                writer.WriteString(" value = obj['");
                writer.WriteString(fullName);
                writer.WriteString("'];");
            }
            else
            if (memberName.StartsWith("Set", StringComparison.OrdinalIgnoreCase))
            {
                writer.WriteString("obj['");
                writer.WriteString(fullName);
                writer.WriteString("'] = value;");
            }
        }
Beispiel #21
0
        private void WriteInterfaceList(string keyword, XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNodeIterator implements = reflection.Select(apiImplementedInterfacesExpression);

            if (implements.Count == 0)
            {
                return;
            }

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

            while (implements.MoveNext())
            {
                XPathNavigator implement = implements.Current;
                WriteTypeReference(implement, writer);
                if (implements.CurrentPosition < implements.Count)
                {
                    writer.WriteString(", ");
                }
            }
        }
        /// <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);

        }
        // References

        /// <inheritdoc />
        protected override void WriteTypeReference(XPathNavigator reference, SyntaxWriter writer)
        {
            switch(reference.LocalName)
            {
                case "arrayOf":
                    int rank = Convert.ToInt32(reference.GetAttribute("rank", String.Empty),
                        CultureInfo.InvariantCulture);

                    XPathNavigator element = reference.SelectSingleNode(typeExpression);
                    WriteTypeReference(element, writer);
                    writer.WriteString("[");

                    for(int i = 1; i < rank; i++)
                        writer.WriteString(",");

                    writer.WriteString("]");
                    break;

                case "pointerTo":
                    XPathNavigator pointee = reference.SelectSingleNode(typeExpression);
                    writer.WriteKeyword("nativeptr");
                    writer.WriteString("<");
                    WriteTypeReference(pointee, writer);
                    writer.WriteString(">");
                    break;

                case "referenceTo":
                    XPathNavigator referee = reference.SelectSingleNode(typeExpression);
                    WriteTypeReference(referee, writer);
                    break;

                case "type":
                    string id = reference.GetAttribute("api", String.Empty);
                    WriteNormalTypeReference(id, writer);
                    XPathNodeIterator typeModifiers = reference.Select(typeModifiersExpression);

                    while(typeModifiers.MoveNext())
                        WriteTypeReference(typeModifiers.Current, writer);

                    break;
                case "template":
                    string name = reference.GetAttribute("name", String.Empty);
                    writer.WriteString("'");
                    writer.WriteString(name);
                    XPathNodeIterator modifiers = reference.Select(typeModifiersExpression);

                    while(modifiers.MoveNext())
                        WriteTypeReference(modifiers.Current, writer);

                    break;
                case "specialization":
                    writer.WriteString("<");
                    XPathNodeIterator arguments = reference.Select(specializationArgumentsExpression);

                    while(arguments.MoveNext())
                    {
                        if(arguments.CurrentPosition > 1)
                            writer.WriteString(", ");

                        WriteTypeReference(arguments.Current, writer);
                    }

                    writer.WriteString(">");
                    break;
            }
        }
        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();
            }
        }
        private void WriteGenericTemplateConstraints(XPathNavigator reflection, SyntaxWriter writer)
        {

            XPathNodeIterator templates = reflection.Select(apiTemplatesExpression);

            if(templates.Count == 0)
                return;

            foreach(XPathNavigator template in templates)
            {

                bool constrained = (bool)template.Evaluate(templateIsConstrainedExpression);
                if(constrained)
                {
                    string name = (string)template.Evaluate(templateNameExpression);

                    writer.WriteString(" ");
                    writer.WriteKeyword("when");
                    writer.WriteString(" '");
                    writer.WriteString(name);
                    writer.WriteString(" : ");
                }
                else
                {
                    continue;
                }

                bool value = (bool)template.Evaluate(templateIsValueTypeExpression);
                bool reference = (bool)template.Evaluate(templateIsReferenceTypeExpression);
                bool constructor = (bool)template.Evaluate(templateIsConstructableExpression);
                XPathNodeIterator constraints = template.Select(templateConstraintsExpression);

                // keep track of whether there is a previous constraint, so we know whether to put a comma
                bool previous = false;

                if(value)
                {
                    if(previous)
                        writer.WriteString(", ");
                    writer.WriteKeyword("struct");
                    previous = true;
                }

                if(reference)
                {
                    if(previous)
                        writer.WriteString(", ");
                    writer.WriteKeyword("not struct");
                    previous = true;
                }

                if(constructor)
                {
                    if(previous)
                        writer.WriteString(", ");
                    writer.WriteKeyword("new");
                    writer.WriteString("()");
                    previous = true;
                }

                foreach(XPathNavigator constraint in constraints)
                {
                    if(previous)
                        writer.WriteString(" and ");
                    WriteTypeReference(constraint, writer);
                    previous = true;
                }

            }

        }
 private static void WriteVisibility(string visibility, SyntaxWriter writer)
 {
     switch(visibility)
     {
         case "public":
             writer.WriteKeyword("Public");
             break;
         case "family":
             writer.WriteKeyword("Protected");
             break;
         case "family or assembly":
             writer.WriteKeyword("Protected Friend");
             break;
         case "family and assembly":
             writer.WriteKeyword("Friend"); // not right, but same outside assembly
             break;
         case "assembly":
             writer.WriteKeyword("Friend");
             break;
         case "private":
             writer.WriteKeyword("Private");
             break;
     }
 }
        private static void WriteProcedureModifiers(XPathNavigator reflection, SyntaxWriter writer)
        {
            // interface members don't get modified
            string typeSubgroup = (string)reflection.Evaluate(apiContainingTypeSubgroupExpression);
            if(typeSubgroup == "interface")
                return;

            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
            bool isVirtual = (bool)reflection.Evaluate(apiIsVirtualExpression);
            bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
            bool isFinal = (bool)reflection.Evaluate(apiIsFinalExpression);
            bool isOverride = (bool)reflection.Evaluate(apiIsOverrideExpression);

            WriteVisibility(reflection, writer);
            writer.WriteString(" ");
            if(isStatic)
            {
                writer.WriteKeyword("Shared");
                writer.WriteString(" ");
            }
            else
            {
                if(isVirtual)
                {
                    if(isAbstract)
                    {
                        writer.WriteKeyword("MustOverride");
                        writer.WriteString(" ");
                    }
                    else if(isOverride)
                    {
                        writer.WriteKeyword("Overrides");
                        writer.WriteString(" ");
                        if(isFinal)
                        {
                            writer.WriteKeyword("NotOverridable");
                            writer.WriteString(" ");
                        }
                    }
                    else
                    {
                        if(!isFinal)
                        {
                            writer.WriteKeyword("Overridable");
                            writer.WriteString(" ");
                        }
                    }
                }
            }

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

        }
Beispiel #29
0
        /// <summary>
        /// Write out property syntax if supported
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WritePropertySyntax(XPathNavigator reflection,
                                                 SyntaxWriter writer)
        {
            if (this.IsUnsupported(reflection, writer))
            {
                return;
            }

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

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

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

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

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

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

                writer.WriteString("(");
                writer.WriteParameter("value");
                writer.WriteString(");");
            }
        }
        /// <inheritdoc />
        public override void 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");
        }
        /// <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 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();
            }
        }
        /// <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)
        {
            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();
            }
        }
        /// <inheritdoc />
        protected override void WriteTypeReference(XPathNavigator reference, SyntaxWriter writer)
        {
            if (reference == null)
            {
                throw new ArgumentNullException(nameof(reference));
            }

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

            switch (reference.LocalName)
            {
            case "arrayOf":
                int rank = Convert.ToInt32(reference.GetAttribute("rank", String.Empty),
                                           CultureInfo.InvariantCulture);

                XPathNavigator element = reference.SelectSingleNode(typeExpression);
                WriteTypeReference(element, writer);
                writer.WriteString("(");

                for (int i = 1; i < rank; i++)
                {
                    writer.WriteString(",");
                }

                writer.WriteString(")");
                break;

            case "pointerTo":
                XPathNavigator pointee = reference.SelectSingleNode(typeExpression);
                WriteTypeReference(pointee, writer);
                writer.WriteString("*");
                break;

            case "referenceTo":
                XPathNavigator referee = reference.SelectSingleNode(typeExpression);
                WriteTypeReference(referee, writer);
                break;

            case "type":
                string            id            = reference.GetAttribute("api", String.Empty);
                XPathNodeIterator typeModifiers = reference.Select(typeModifiersExpression);

                // !EFW - Support value tuple syntax
                if (id.StartsWith("T:System.ValueTuple`", StringComparison.Ordinal))
                {
                    writer.WriteString("(");

                    while (typeModifiers.MoveNext())
                    {
                        XPathNodeIterator args = typeModifiers.Current.Select(specializationArgumentsExpression);

                        while (args.MoveNext())
                        {
                            if (args.CurrentPosition > 1)
                            {
                                writer.WriteString(", ");
                            }

                            var elementName = args.Current.GetAttribute("elementName", String.Empty);

                            if (elementName != null)
                            {
                                writer.WriteString(elementName);
                                writer.WriteString(" As ");
                            }

                            WriteTypeReference(args.Current, writer);
                        }
                    }

                    writer.WriteString(")");
                }
                else if (id.StartsWith("T:System.Nullable`", StringComparison.Ordinal))
                {
                    // !EFW - Support nullable type syntax
                    while (typeModifiers.MoveNext())
                    {
                        XPathNodeIterator args = typeModifiers.Current.Select(specializationArgumentsExpression);

                        while (args.MoveNext())
                        {
                            if (args.CurrentPosition > 1)
                            {
                                writer.WriteString(", ");
                            }

                            WriteTypeReference(args.Current, writer);
                        }
                    }

                    writer.WriteString("?");
                }
                else
                {
                    WriteNormalTypeReference(id, writer);

                    while (typeModifiers.MoveNext())
                    {
                        WriteTypeReference(typeModifiers.Current, writer);
                    }
                }
                break;

            case "template":
                string name = reference.GetAttribute("name", String.Empty);
                writer.WriteString(name);
                XPathNodeIterator modifiers = reference.Select(typeModifiersExpression);

                while (modifiers.MoveNext())
                {
                    WriteTypeReference(modifiers.Current, writer);
                }

                break;

            case "specialization":
                writer.WriteString("(");
                writer.WriteKeyword("Of");
                writer.WriteString(" ");
                XPathNodeIterator arguments = reference.Select(specializationArgumentsExpression);

                while (arguments.MoveNext())
                {
                    if (arguments.CurrentPosition > 1)
                    {
                        writer.WriteString(", ");
                    }

                    WriteTypeReference(arguments.Current, writer);
                }

                writer.WriteString(")");
                break;
            }
        }
        /// <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);

        }
 private static void WriteVisibility(string visibility, SyntaxWriter writer)
 {
     if(visibilityDictionary.ContainsKey(visibility) && visibilityDictionary[visibility] != null)
     {
         writer.WriteKeyword(visibilityDictionary[visibility]);
         writer.WriteString(" ");
     }
 }
        /// <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 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);

        }
        // Parameters

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

            if(parameters.Count > 0)
                WriteParameters(parameters, writer);
            else
            {
                writer.WriteKeyword("unit");
                writer.WriteString(" ");
            }
        }
Beispiel #41
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(")");
            }
        }
        // Return Value

        private void WriteReturnValue(XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);

            if(type == null)
                writer.WriteKeyword("unit");
            else
                WriteTypeReference(type, 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 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);
            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);
                }
            }
        }
        /// <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 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);
        }
        /// <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();
            }
        }
        /// <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");
            }
        }
        /// <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);

        }
        /// <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);
        }
        private void WriteExplicitImplementations(XPathNavigator reflection, SyntaxWriter writer)
        {
            bool isExplicit = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);

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

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

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

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

                    WriteTypeReference(contract, writer);
                    writer.WriteString(".");
                    WriteMemberReference(implementation, writer);
                    //writer.WriteReferenceLink(id);	
                }
            }
        }
        private void WriteValue(XPathNavigator parent, SyntaxWriter writer)
        {
            XPathNavigator type  = parent.SelectSingleNode(attributeTypeExpression);
            XPathNavigator value = parent.SelectSingleNode(valueExpression);

            switch (value.LocalName)
            {
            case "nullValue":
                writer.WriteKeyword("null");
                break;

            case "defaultValue":
                // I'm making an assumption about syntax here
                writer.WriteString("new ");
                this.WriteTypeReference(type, writer);
                writer.WriteString("()");
                break;

            case "typeValue":
                // this isn't really supported in J#; there is no compile-time way to get a type representation
                // writer.WriteKeyword("typeof");
                // writer.WriteString("(");
                WriteTypeReference(value.SelectSingleNode(typeExpression), writer);
                // writer.WriteString(")");
                break;

            case "enumValue":
                XPathNodeIterator fields = value.SelectChildren(XPathNodeType.Element);
                while (fields.MoveNext())
                {
                    string name = fields.Current.GetAttribute("name", String.Empty);
                    if (fields.CurrentPosition > 1)
                    {
                        writer.WriteString("|");
                    }
                    WriteTypeReference(type, writer);
                    writer.WriteString(".");
                    writer.WriteString(name);
                }
                break;

            case "value":
                string text   = value.Value;
                string typeId = type.GetAttribute("api", String.Empty);

                switch (typeId)
                {
                case "T:System.String":
                    writer.WriteString("\"");
                    writer.WriteString(text);
                    writer.WriteString("\"");
                    break;

                case "T:System.Boolean":
                    writer.WriteKeyword(Convert.ToBoolean(text, CultureInfo.InvariantCulture) ?
                                        "true" : "false");
                    break;

                case "T:System.Char":
                    writer.WriteString("'");
                    writer.WriteString(text);
                    writer.WriteString("'");
                    break;

                // !EFW - Bug fix.  Support numeric values and other potential types.
                // Note that decimal isn't supported as an attribute value so it is omitted.
                case "T:System.Byte":
                case "T:System.Double":
                case "T:System.SByte":
                case "T:System.Int16":
                case "T:System.Int64":
                case "T:System.Int32":
                case "T:System.UInt16":
                case "T:System.UInt32":
                case "T:System.UInt64":
                    writer.WriteString(text);
                    break;

                case "T:System.Single":
                    writer.WriteString(text);
                    writer.WriteString("f");
                    break;

                default:
                    // If not a recognized type, just write out the value so that something shows
                    if (type.LocalName != "arrayOf")
                    {
                        writer.WriteString(text);
                    }
                    else
                    {
                        // It's an array.  We don't get the values so just write out the type.
                        writer.WriteString("new ");
                        this.WriteTypeReference(type, writer);
                        writer.WriteString(" { ... }");
                    }
                    break;
                }
                break;
            }
        }
        // Write member | abstract | override
        private static void WriteMemberKeyword(XPathNavigator reflection, SyntaxWriter writer)
        {
            bool isOverride = (bool)reflection.Evaluate(apiIsOverrideExpression);
            bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractProcedureExpression);

            if(isOverride)
                writer.WriteKeyword("override");
            else
                if(isAbstract)
                    writer.WriteKeyword("abstract");
                else
                    writer.WriteKeyword("member");

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

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

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

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

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

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

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

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

                writer.WriteString("(");
                writer.WriteParameter("value");
                writer.WriteString(");");
            }
        }
        private void WriteValue(XPathNavigator parent, SyntaxWriter writer)
        {
            XPathNavigator type = parent.SelectSingleNode(attributeTypeExpression);
            XPathNavigator value = parent.SelectSingleNode(valueExpression);

            switch(value.LocalName)
            {
                case "nullValue":
                    writer.WriteKeyword("null");
                    break;

                case "typeValue":
                    writer.WriteKeyword("typeof");
                    writer.WriteString("(");
                    WriteTypeReference(value.SelectSingleNode(typeExpression), writer);
                    writer.WriteString(")");
                    break;

                case "enumValue":
                    XPathNodeIterator fields = value.SelectChildren(XPathNodeType.Element);
                    while(fields.MoveNext())
                    {
                        string name = fields.Current.GetAttribute("name", String.Empty);
                        if(fields.CurrentPosition > 1)
                            writer.WriteString("|");
                        WriteTypeReference(type, writer);
                        writer.WriteString(".");
                        writer.WriteString(name);
                    }
                    break;

                case "value":
                    string text = value.Value;
                    string typeId = type.GetAttribute("api", String.Empty);

                    switch(typeId)
                    {
                        case "T:System.String":
                            writer.WriteString("\"");
                            writer.WriteString(text);
                            writer.WriteString("\"");
                            break;

                        case "T:System.Boolean":
                            writer.WriteKeyword(Convert.ToBoolean(text, CultureInfo.InvariantCulture) ?
                                "true" : "false");
                            break;

                        case "T:System.Char":
                            writer.WriteString("'");
                            writer.WriteString(text);
                            writer.WriteString("'");
                            break;

                        // !EFW - Bug fix.  Support numeric values and other potential types.
                        // Note that decimal isn't supported as an attribute value so it is omitted.
                        case "T:System.Byte":
                        case "T:System.Double":
                        case "T:System.SByte":
                        case "T:System.Int16":
                        case "T:System.Int64":
                        case "T:System.Int32":
                        case "T:System.UInt16":
                        case "T:System.UInt32":
                        case "T:System.UInt64":
                            writer.WriteString(text);
                            break;

                        case "T:System.Single":
                            writer.WriteString(text);
                            writer.WriteString("f");
                            break;

                        default:
                            // If not a recognized type, just write out the value so that something shows
                            if(type.LocalName != "arrayOf")
                                writer.WriteString(text);
                            else
                            {
                                // It's an array.  We don't get the values so just write out the type.
                                writer.WriteString("new ");
                                this.WriteTypeReference(type, writer);
                                writer.WriteString(" { ... }");
                            }
                            break;
                    }
                    break;
            }
        }
        /// <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);
            }

        }