private void WriteGenericTemplates(XPathNavigator type, SyntaxWriter writer, bool writeVariance)
        {
            XPathNodeIterator templates = type.Select(apiTemplatesExpression);

            if (templates.Count == 0) return;
            writer.WriteString("(");
            writer.WriteKeyword("Of");
            writer.WriteString(" ");
            while (templates.MoveNext())
            {
                XPathNavigator template = templates.Current;
                if (templates.CurrentPosition > 1) writer.WriteString(", ");
                if (writeVariance)
                {
                    bool contravariant = (bool)template.Evaluate(templateIsContravariantExpression);
                    bool covariant = (bool)template.Evaluate(templateIsCovariantExpression);

                    if (contravariant)
                    {
                        writer.WriteKeyword("In");
                        writer.WriteString(" ");
                    }
                    if (covariant)
                    {
                        writer.WriteKeyword("Out");
                        writer.WriteString(" ");
                    }
                }

                string name = template.GetAttribute("name", String.Empty);
                writer.WriteString(name);
            }
            writer.WriteString(")");

        }
        // class: done
		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);
		}
        // class: done
		public override void WriteClassSyntax (XPathNavigator reflection, SyntaxWriter writer) {

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

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

		}
		public override void WriteClassSyntax (XPathNavigator reflection, SyntaxWriter writer) {

			if (IsUnsupportedGeneric(reflection, writer)) return;

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

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

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

			WriteImplementedInterfaces(reflection, writer);

		}
        public override void WriteSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            writer.WriteStartBlock(Language);

            // Check the list of assemblies for which to generate XAML syntax
            string assemblyName = (string)reflection.Evaluate(apiContainingAssemblyExpression);
            string namespaceName = (string)reflection.Evaluate(apiContainingNamespaceNameExpression);
            if (!xamlAssemblies.ContainsKey(assemblyName.ToLower()))
            {
                WriteXamlBoilerplate(XamlBoilerplateID.nonXamlAssemblyBoilerplate, writer);
            }
            else
            {
                string group = (string)reflection.Evaluate(apiGroupExpression);
                switch (group)
                {
                    case "namespace":
                        WriteNamespaceSyntax(reflection, writer);
                        break;
                    case "type":
                        WriteTypeSyntax(reflection, writer);
                        break;
                    case "member":
                        WriteMemberSyntax(reflection, writer);
                        break;
                }
                WriteXamlXmlnsUri(assemblyName, namespaceName, writer);
            }

            writer.WriteEndBlock();
        }
        public override void WriteDelegateSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {

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

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

            WriteAttributes(reflection, writer);

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

        }
Example #7
0
        public override void WriteSyntax (XPathNavigator reflection, SyntaxWriter writer) {

            string group = (string)reflection.Evaluate(groupExpression);
            string subgroup = (string)reflection.Evaluate(subgroupExpression);

            if (group == "type" && subgroup == "class") {
                string prefix = WebControlPrefix(reflection);
                if (!String.IsNullOrEmpty(prefix)) {
                    WriteClassSyntax(reflection, writer, prefix);
                }
            }

            if (group == "member") {

                string prefix = null;
                XPathNavigator containingType = reflection.SelectSingleNode(containingTypeExpression);
                if (containingType != null) prefix = WebControlPrefix(containingType);

                if (!String.IsNullOrEmpty(prefix)) {
                    if (subgroup == "property") {
                        WritePropertySyntax(reflection, writer, prefix);
                    } else if (subgroup == "event") {
                        WriteEventSyntax(reflection, writer, prefix);
                    }
                }
            }


        }
        public override void WriteNamespaceSyntax (XPathNavigator reflection, SyntaxWriter writer) {
            string name = (string)reflection.Evaluate(apiNameExpression);

            writer.WriteKeyword("package");
            writer.WriteString(" ");
            writer.WriteIdentifier(name);
        }
        public override void WriteEnumerationSyntax (XPathNavigator reflection, SyntaxWriter writer) {
            string name = (string)reflection.Evaluate(apiNameExpression);

            WriteAttributeList(reflection, writer);
            WriteAccessModifier(reflection, writer);
            writer.WriteKeyword("enum");
            writer.WriteString(" ");
            writer.WriteString(name);
            // no JScript support for underlying types
        }
        public override void WriteInterfaceSyntax (XPathNavigator reflection, SyntaxWriter writer) {
            if (IsUnsupportedGeneric(reflection, writer)) return;

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

            WriteAttributeList(reflection, writer);
            WriteAccessModifier(reflection, writer);
            writer.WriteKeyword("interface");
            writer.WriteString(" ");
            writer.WriteString(name);
            WriteInterfaceList("extends", reflection, writer);
        }
        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", writer);
            WriteAttributes(reflection, writer);
            writer.WriteKeyword("type");
            writer.WriteString(" ");
            WriteVisibility(reflection, writer);
            writer.WriteIdentifier(name);
        }
        // interface: done
		public override void WriteInterfaceSyntax (XPathNavigator reflection, SyntaxWriter writer) {

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

			WriteAttributes(reflection, writer);
			WriteVisibility(reflection, writer);
			writer.WriteString(" ");
			writer.WriteKeyword("Interface");
			writer.WriteString(" ");
			writer.WriteIdentifier(name);
            WriteGenericTemplates(reflection, writer, true); // Need to write variance info for interfaces and delegates
			WriteImplementedInterfaces(reflection, writer);
		}
        public override void WriteConstructorSyntax (XPathNavigator reflection, SyntaxWriter writer) {
            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);
            if (isStatic) {
                writer.WriteMessage("UnsupportedStaticConstructor_" + Language);
            } else {
                if (IsUnsupportedUnsafe(reflection, writer)) return;
                XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);

                WriteAttributeList(reflection, writer);
                WriteAccessModifier(reflection, writer);
                writer.WriteKeyword("function");
                writer.WriteString(" ");
                WriteTypeReference(declaringType, writer);
                WriteParameterList(reflection, writer);
            }
        }
		public override void WriteInterfaceSyntax (XPathNavigator reflection, SyntaxWriter writer) {

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

			WriteAttributes(reflection, writer);

			WriteGenericTemplates(reflection, writer);

			WriteVisibility(reflection, writer);
			writer.WriteString(" ");
			writer.WriteKeyword("interface class");
			writer.WriteString(" ");
			writer.WriteIdentifier(name);
			WriteImplementedInterfaces(reflection, writer);

		}
        // structure: done
		public override void WriteStructureSyntax (XPathNavigator reflection, SyntaxWriter writer) {

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

			if (isSerializable) WriteAttribute("T:System.SerializableAttribute", writer);
			WriteAttributes(reflection, writer);
			WriteVisibility(reflection, writer);
			writer.WriteString(" ");
			writer.WriteKeyword("struct");
			writer.WriteString(" ");
			writer.WriteIdentifier(name);
			WriteGenericTemplates(reflection, writer);
			WriteImplementedInterfaces(reflection, writer);
			WriteGenericTemplateConstraints(reflection, writer);

		}
Example #16
0
 private void WriteXamlXmlnsUri(string assemblyName, string namespaceName, SyntaxWriter writer)
 {
     Dictionary<string, List<string>> clrNamespaces;
     if (xamlAssemblies.TryGetValue(assemblyName.ToLower(), out clrNamespaces))
     {
         List<string> xmlnsUriList;
         if (clrNamespaces.TryGetValue(namespaceName, out xmlnsUriList))
         {
             foreach (string xmlnsUri in xmlnsUriList)
             {
                 // start the syntax block
                 writer.WriteStartSubBlock("xamlXmlnsUri");
                 writer.WriteString(xmlnsUri);
                 writer.WriteEndSubBlock();
             }
         }
     }
 }
        /// <summary>
        /// Determines whether the feature is unsupported by this language.
        /// </summary>
        /// <param name="reflection"></param>
        /// <param name="writer"></param>
        /// <returns></returns>
        private bool IsUnsupported(XPathNavigator reflection, SyntaxWriter writer) {
            if (IsUnsupportedGeneric(reflection, writer)) {
                return true;
            }

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

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

            if (HasAttribute(reflection, "System.NonScriptableAttribute")) {
                writer.WriteMessage("UnsupportedType_ScriptSharp");
                return true;
            }

            return false;
        }
        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);

            WriteAttributeList(reflection, writer);
            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);
        }
        private void TypeDeclaration (XPathNavigator reflection, SyntaxWriter writer, bool writeVariance) {
            string name = (string)reflection.Evaluate(apiNameExpression);
            XPathNavigator declaringType = reflection.SelectSingleNode(apiContainingTypeExpression);

            writer.WriteKeyword("Dim");
            writer.WriteString(" ");
            writer.WriteParameter("instance");
            writer.WriteString(" ");
            writer.WriteKeyword("As");
            writer.WriteString(" ");
            if (declaringType != null) {
                WriteTypeReference(declaringType, writer);
                writer.WriteString(".");
            }
            if (reservedWords.ContainsKey(name)) {
                writer.WriteString("[");
                writer.WriteIdentifier(name);
                writer.WriteString("]");
            } else {
                writer.WriteIdentifier(name);
            }
            WriteGenericTemplates(reflection, writer, writeVariance);
        }
		public override void WriteStructureSyntax (XPathNavigator reflection, SyntaxWriter writer) {

			if (IsUnsupportedGeneric(reflection, writer)) return;

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

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

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

			WriteImplementedInterfaces(reflection, writer);
		}
Example #21
0
 /// <inheritdoc />
 public override void WriteEnumerationSyntax(XPathNavigator reflection, SyntaxWriter writer)
 {
     WriteXamlBoilerplate(XamlBoilerplateID.enumerationOverviewXamlSyntax, writer);
 }
Example #22
0
        /// <inheritdoc />
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            bool              isSettable         = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
            bool              isSetterPublic     = (bool)reflection.Evaluate(apiIsSetterPublicExpression);
            bool              isAbstract         = (bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
            string            propertyVisibility = (string)reflection.Evaluate(apiVisibilityExpression);
            XPathNodeIterator parameters         = reflection.Select(apiParametersExpression);

            XPathNavigator returnType                 = reflection.SelectSingleNode(apiReturnTypeExpression);
            bool           notWriteableReturnType     = (bool)returnType.Evaluate(noSettablePropertiesExpression);
            string         returnTypeId               = returnType.GetAttribute("api", string.Empty);
            string         returnTypeSubgroup         = (string)returnType.Evaluate(apiSubgroupExpression);
            bool           returnTypeIsAbstract       = (bool)returnType.Evaluate(apiIsAbstractTypeExpression);
            bool           returnTypeIsReadonlyStruct = (returnTypeSubgroup == "structure" && notWriteableReturnType &&
                                                         !IsPrimitiveType(returnTypeId));

            XPathNavigator containingType         = reflection.SelectSingleNode(apiContainingTypeExpression);
            string         containingTypeSubgroup = (string)containingType.Evaluate(apiSubgroupExpression);

            // an ordinary property, not an attached prop
            if (containingTypeSubgroup == "interface")
            {
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_noXamlSyntaxForInterfaceMembers, writer);
            }
            else if ((bool)containingType.Evaluate(apiIsAbstractTypeExpression) &&
                     (bool)containingType.Evaluate(apiIsSealedTypeExpression))
            {
                // the property's containing type is static if it's abstract and sealed
                // members of a static class cannot be used in XAML.
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_nonXamlParent, writer);
            }
            else if (IsExcludedSubClass(containingType))
            {
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_parentIsExcludedSubClass, writer);
            }
            else if (!DoesParentSupportXaml(reflection))
            {
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_nonXamlParent, writer);
            }
            else if (propertyVisibility != "public")
            {
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_notPublic, writer);
            }
            else if (isAbstract)
            {
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_abstract, writer);
            }
            else if (parameters.Count > 0)
            {
                // per DDUERELTools bug 1373: indexer properties cannot be used in XAML
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_nonXaml, writer);
            }
            else if (IsContentProperty(reflection) && !returnTypeIsReadonlyStruct)
            {
                PropertyContentElementUsageSimple(reflection, writer);
            }
            else if (!isSettable || !isSetterPublic)
            {
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_readOnly, writer);
            }
            else if (returnTypeIsAbstract && !HasTypeConverterAttribute(returnType))    // !EFW - Allow it if there's a type converter
            {
                WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_abstractType, returnType, writer);
            }
            else if (IsPrimitiveType(returnTypeId))
            {
                PropertyAttributeUsage(reflection, writer);
            }
            else if (returnTypeSubgroup == "enumeration")
            {
                PropertyAttributeUsage(reflection, writer);
            }
            else
            {
                bool hasDefaultConstructor = HasDefaultConstructor(returnType);
                if (HasTypeConverterAttribute(returnType))
                {
                    if (hasDefaultConstructor && !returnTypeIsReadonlyStruct)
                    {
                        PropertyElementUsageGrande(reflection, writer);
                    }
                    PropertyAttributeUsage(reflection, writer);
                }
                else if (hasDefaultConstructor && !returnTypeIsReadonlyStruct)
                {
                    PropertyElementUsageGrande(reflection, writer);
                }
                else
                {
                    WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_nonXaml, writer);
                }
            }
        }
Example #23
0
 /// <inheritdoc />
 public override void WriteFieldSyntax(XPathNavigator reflection, SyntaxWriter writer)
 {
     WriteXamlBoilerplate(XamlBoilerplateID.fieldOverviewXamlSyntax, writer);
 }
Example #24
0
        // operator: done
        public override void WriteOperatorSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string name = (string)reflection.Evaluate(apiNameExpression);

            string identifier;

            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 = "!";
                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 = "~";
                break;

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

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

            // unrecognized operator
            default:
                identifier = null;
                break;
            }
            if (identifier == null)
            {
                writer.WriteMessage("UnsupportedOperator_" + Language);
            }
            else
            {
                WriteProcedureModifiers(reflection, writer);
                WriteReturnValue(reflection, writer);
                writer.WriteString(" ");
                writer.WriteKeyword("operator");
                writer.WriteString(" ");
                writer.WriteIdentifier(identifier);
                WriteMethodParameters(reflection, writer);
            }
        }
Example #25
0
        // Visibility

        private void WriteVisibility(XPathNavigator reflection, SyntaxWriter writer)
        {
            string visibility = reflection.Evaluate(apiVisibilityExpression).ToString();

            WriteVisibility(visibility, writer);
        }
Example #26
0
        private void WriteGenericTemplateConstraints(XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNodeIterator templates = reflection.Select(apiTemplatesExpression);

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

            writer.WriteLine();
            foreach (XPathNavigator template in templates)
            {
                bool constrained = (bool)template.Evaluate(templateIsConstrainedExpression);
                if (constrained)
                {
                    string name = (string)template.Evaluate(templateNameExpression);

                    writer.WriteKeyword("where");
                    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("class");
                    previous = true;
                }

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

                foreach (XPathNavigator constraint in constraints)
                {
                    if (previous)
                    {
                        writer.WriteString(", ");
                    }
                    WriteTypeReference(constraint, writer);
                    previous = true;
                }
                writer.WriteLine();
            }
        }
Example #27
0
 /// <inheritdoc />
 public override void WriteDelegateSyntax(XPathNavigator reflection, SyntaxWriter writer)
 {
     WriteXamlBoilerplate(XamlBoilerplateID.delegateOverviewXamlSyntax, writer);
 }
Example #28
0
        private void WriteTypeReference(XPathNavigator reference, SyntaxWriter writer)
        {
            switch (reference.LocalName)
            {
            case "arrayOf":
                int            rank    = Convert.ToInt32(reference.GetAttribute("rank", String.Empty));
                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);
                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(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;
            }
        }
Example #29
0
 private void WriteParameterList(XPathNavigator reflection, SyntaxWriter writer)
 {
     WriteParameterList(reflection, writer, true);
 }
Example #30
0
 private void WriteInterfaceList(XPathNavigator reflection, SyntaxWriter writer)
 {
     WriteInterfaceList("implements", reflection, writer);
 }
Example #31
0
 public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
 {
     writer.WriteMessage("UnsupportedEvent_" + Language);
 }
Example #32
0
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter 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)
            {
                WriteAttributeList(reflection, writer);

                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);
                writer.WriteString(" () : ");
                WriteTypeReference(type, writer);
                writer.WriteLine();
            }

            if (isSettable)
            {
                WriteAttributeList(reflection, writer);

                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");
                writer.WriteString(" : ");
                WriteTypeReference(type, writer);
                writer.WriteString(")");
            }
        }
Example #33
0
        // Generics

        private void WriteGenericTemplates(XPathNavigator reflection, SyntaxWriter writer)
        {
            WriteGenericTemplates(reflection, writer, false);
        }
        private void WriteValue(XPathNavigator parent, SyntaxWriter writer)
        {

            XPathNavigator type = parent.SelectSingleNode(attributeTypeExpression);
            XPathNavigator value = parent.SelectSingleNode(valueExpression);
            if (value == null) Console.WriteLine("null value");

            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":
                            bool bool_value = Convert.ToBoolean(text);
                            if (bool_value)
                            {
                                writer.WriteKeyword("true");
                            }
                            else
                            {
                                writer.WriteKeyword("false");
                            }
                            break;
                        case "T:System.Char":
                            writer.WriteString("'");
                            writer.WriteString(text);
                            writer.WriteString("'");
                            break;
                    }
                    break;
            }
        }
        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;
                }
                
            }

        }
Example #36
0
        private void WriteNormalTypeReference(string api, SyntaxWriter writer)
        {
            switch (api)
            {
            case "T:System.Boolean":
                writer.WriteReferenceLink(api, "boolean");
                break;

            case "T:System.Byte":
                writer.WriteReferenceLink(api, "byte");
                break;

            case "T:System.SByte":
                writer.WriteReferenceLink(api, "sbyte");
                break;

            case "T:System.Char":
                writer.WriteReferenceLink(api, "char");
                break;

            case "T:System.Int16":
                writer.WriteReferenceLink(api, "short");
                break;

            case "T:System.Int32":
                writer.WriteReferenceLink(api, "int");
                break;

            case "T:System.Int64":
                writer.WriteReferenceLink(api, "long");
                break;

            case "T:System.UInt16":
                writer.WriteReferenceLink(api, "ushort");
                break;

            case "T:System.UInt32":
                writer.WriteReferenceLink(api, "uint");
                break;

            case "T:System.UInt64":
                writer.WriteReferenceLink(api, "ulong");
                break;

            case "T:System.Single":
                writer.WriteReferenceLink(api, "float");
                break;

            case "T:System.Double":
                writer.WriteReferenceLink(api, "double");
                break;

            case "T:System.Decimal":
                writer.WriteReferenceLink(api, "decimal");
                break;

            default:
                writer.WriteReferenceLink(api);
                break;
            }
        }
        // Return Value

        private void WriteReturnValue(XPathNavigator reflection, SyntaxWriter writer)
        {

            XPathNavigator type = reflection.SelectSingleNode(apiReturnTypeExpression);

            if (type == null)
            {
                writer.WriteKeyword("unit");
            }
            else
            {
                WriteTypeReference(type, writer);
            }
        }
Example #38
0
 private void WriteAttributeList(XPathNavigator reflection, SyntaxWriter writer)
 {
     // fill in this logic
 }
Example #39
0
        private void WriteAttributes(XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNodeIterator attributes = (XPathNodeIterator)reflection.Evaluate(apiAttributesExpression);

            foreach (XPathNavigator attribute in attributes)
            {
                XPathNavigator type = attribute.SelectSingleNode(attributeTypeExpression);
                if (type.GetAttribute("api", String.Empty) == "T:System.Runtime.CompilerServices.ExtensionAttribute")
                {
                    continue;
                }

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

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

                if ((arguments.Count > 0) || (assignments.Count > 0))
                {
                    writer.WriteString("(");
                    while (arguments.MoveNext())
                    {
                        XPathNavigator argument = arguments.Current;
                        if (arguments.CurrentPosition > 1)
                        {
                            writer.WriteString(", ");
                            if (writer.Position > maxPosition)
                            {
                                writer.WriteLine();
                                writer.WriteString("\t");
                            }
                        }
                        WriteValue(argument, writer);
                    }
                    if ((arguments.Count > 0) && (assignments.Count > 0))
                    {
                        writer.WriteString(", ");
                    }
                    while (assignments.MoveNext())
                    {
                        XPathNavigator assignment = assignments.Current;
                        if (assignments.CurrentPosition > 1)
                        {
                            writer.WriteString(", ");
                            if (writer.Position > maxPosition)
                            {
                                writer.WriteLine();
                                writer.WriteString("\t");
                            }
                        }
                        writer.WriteString((string)assignment.Evaluate(assignmentNameExpression));
                        writer.WriteString(" = ");
                        WriteValue(assignment, writer);
                    }
                    writer.WriteString(")");
                }

                writer.WriteString("]");
                writer.WriteLine();
            }
        }
 // DONE
 private void WriteNormalTypeReference(string api, SyntaxWriter writer)
 {
     switch (api)
     {
         case "T:System.Void":
             writer.WriteReferenceLink(api, "unit");
             break;
         case "T:System.String":
             writer.WriteReferenceLink(api, "string");
             break;
         case "T:System.Boolean":
             writer.WriteReferenceLink(api, "bool");
             break;
         case "T:System.Byte":
             writer.WriteReferenceLink(api, "byte");
             break;
         case "T:System.SByte":
             writer.WriteReferenceLink(api, "sbyte");
             break;
         case "T:System.Char":
             writer.WriteReferenceLink(api, "char");
             break;
         case "T:System.Int16":
             writer.WriteReferenceLink(api, "int16");
             break;
         case "T:System.Int32":
             writer.WriteReferenceLink(api, "int");
             break;
         case "T:System.Int64":
             writer.WriteReferenceLink(api, "int64");
             break;
         case "T:System.UInt16":
             writer.WriteReferenceLink(api, "uint16");
             break;
         case "T:System.UInt32":
             writer.WriteReferenceLink(api, "uint32");
             break;
         case "T:System.UInt64":
             writer.WriteReferenceLink(api, "uint64");
             break;
         case "T:System.Single":
             writer.WriteReferenceLink(api, "float32");
             break;
         case "T:System.Double":
             writer.WriteReferenceLink(api, "float");
             break;
         case "T:System.Decimal":
             writer.WriteReferenceLink(api, "decimal");
             break;
         default:
             writer.WriteReferenceLink(api);
             break;
     }
 }
Example #41
0
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string            name       = (string)reflection.Evaluate(apiNameExpression);
            bool              isDefault  = (bool)reflection.Evaluate(apiIsDefaultMemberExpression);
            bool              isGettable = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool              isSettable = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
            bool              isExplicit = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);
            XPathNodeIterator parameters = reflection.Select(apiParametersExpression);

            WriteAttributes(reflection, writer);
            if (!isExplicit)
            {
                WriteProcedureModifiers(reflection, writer);
            }
            WriteReturnValue(reflection, writer);
            writer.WriteString(" ");

            if (isExplicit)
            {
                XPathNavigator member   = reflection.SelectSingleNode(apiImplementedMembersExpression);
                XPathNavigator contract = member.SelectSingleNode(memberDeclaringTypeExpression);
                WriteTypeReference(contract, writer);
                writer.WriteString(".");
                if (parameters.Count > 0)
                {
                    // In C#, EII property with parameters is an indexer; use 'this' instead of the property's name
                    writer.WriteKeyword("this");
                }
                else
                {
                    WriteMemberReference(member, writer);
                }
            }
            else
            {
                // In C#, any property with parameters is an indexer, which is declared using 'this' instead of the property's name
                if (isDefault || parameters.Count > 0)
                {
                    writer.WriteKeyword("this");
                }
                else
                {
                    writer.WriteIdentifier(name);
                }
            }

            WritePropertyParameters(reflection, writer);
            writer.WriteString(" {");
            if (isGettable)
            {
                writer.WriteString(" ");
                string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);
                if (!String.IsNullOrEmpty(getVisibility))
                {
                    WriteVisibility(getVisibility, writer);
                    writer.WriteString(" ");
                }
                writer.WriteKeyword("get");
                writer.WriteString(";");
            }
            if (isSettable)
            {
                writer.WriteString(" ");
                string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);
                if (!String.IsNullOrEmpty(setVisibility))
                {
                    WriteVisibility(setVisibility, writer);
                    writer.WriteString(" ");
                }
                writer.WriteKeyword("set");
                writer.WriteString(";");
            }
            writer.WriteString(" }");
        }
Example #42
0
        private void WriteBaseClassAndImplementedInterfaces(XPathNavigator reflection, SyntaxWriter writer)
        {
            XPathNavigator    baseClass  = reflection.SelectSingleNode(apiBaseClassExpression);
            XPathNodeIterator implements = reflection.Select(apiImplementedInterfacesExpression);

            bool hasBaseClass             = (baseClass != null) && !((bool)baseClass.Evaluate(typeIsObjectExpression));
            bool hasImplementedInterfaces = (implements.Count > 0);

            if (hasBaseClass || hasImplementedInterfaces)
            {
                writer.WriteString(" : ");
                if (hasBaseClass)
                {
                    WriteTypeReference(baseClass, writer);
                    if (hasImplementedInterfaces)
                    {
                        writer.WriteString(", ");
                        if (writer.Position > maxPosition)
                        {
                            writer.WriteLine();
                            writer.WriteString("\t");
                        }
                    }
                }

                while (implements.MoveNext())
                {
                    XPathNavigator implement = implements.Current;
                    WriteTypeReference(implement, writer);
                    if (implements.CurrentPosition < implements.Count)
                    {
                        writer.WriteString(", ");
                        if (writer.Position > maxPosition)
                        {
                            writer.WriteLine();
                            writer.WriteString("\t");
                        }
                    }
                }
            }
        }
Example #43
0
 /// <inheritdoc />
 public override void WriteEnumerationSyntax(XPathNavigator reflection, SyntaxWriter writer)
 {
     TypeDeclaration(reflection, writer);
 }
Example #44
0
        /// <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           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");
        }
Example #45
0
        // A simple Property Element Usage block for a content property
        // syntax looks like:
        //   <object>
        //     <linkToType .../>
        //   </object>
        private void PropertyContentElementUsageSimple(XPathNavigator propertyReflection, SyntaxWriter writer)
        {
            string         xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlContentElementUsageHeading);
            XPathNavigator returnType  = propertyReflection.SelectSingleNode(apiReturnTypeExpression);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

                    writer.WriteString(")");
                    break;
                }
            }
        }
Example #47
0
 /// <inheritdoc />
 public override void WriteConstructorSyntax(XPathNavigator reflection, SyntaxWriter writer)
 {
     WriteXamlBoilerplate(XamlBoilerplateID.constructorOverviewXamlSyntax, writer);
 }
Example #48
0
 private void TypeDeclaration(XPathNavigator reflection, SyntaxWriter writer)
 {
     TypeDeclaration(reflection, writer, false);
 }
        // Initial version
        private void WriteAttributes(XPathNavigator reflection, SyntaxWriter writer)
        {

            XPathNodeIterator attributes = (XPathNodeIterator)reflection.Evaluate(apiAttributesExpression);

            foreach (XPathNavigator attribute in attributes)
            {

                XPathNavigator type = attribute.SelectSingleNode(attributeTypeExpression);
                if (type.GetAttribute("api", String.Empty) == "T:System.Runtime.CompilerServices.ExtensionAttribute") continue;

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

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

                if ((arguments.Count > 0) || (assignments.Count > 0))
                {
                    writer.WriteString("(");
                    while (arguments.MoveNext())
                    {
                        XPathNavigator argument = arguments.Current;
                        if (arguments.CurrentPosition > 1)
                        {
                            writer.WriteString(", ");
                            if (writer.Position > maxPosition)
                            {
                                writer.WriteLine();
                                writer.WriteString("    ");
                            }
                        }
                        WriteValue(argument, writer);
                    }
                    if ((arguments.Count > 0) && (assignments.Count > 0)) writer.WriteString(", ");
                    while (assignments.MoveNext())
                    {
                        XPathNavigator assignment = assignments.Current;
                        if (assignments.CurrentPosition > 1)
                        {
                            writer.WriteString(", ");
                            if (writer.Position > maxPosition)
                            {
                                writer.WriteLine();
                                writer.WriteString("    ");
                            }
                        }
                        writer.WriteString((string)assignment.Evaluate(assignmentNameExpression));
                        writer.WriteString(" = ");
                        WriteValue(assignment, writer);

                    }
                    writer.WriteString(")");
                }

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

        }
Example #50
0
        /// <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);
                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
                {
                    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;
            }
        }
        // Generics

        private void WriteGenericTemplates(XPathNavigator reflection, SyntaxWriter writer)
        {

            XPathNodeIterator templates = (XPathNodeIterator)reflection.Evaluate(apiTemplatesExpression);

            if (templates.Count == 0) return;
            writer.WriteString("<");
            while (templates.MoveNext())
            {
                XPathNavigator template = templates.Current;
                string name = template.GetAttribute("name", String.Empty);
                writer.WriteString("'");
                writer.WriteString(name);
                if (templates.CurrentPosition < templates.Count) writer.WriteString(", ");
            }
            WriteGenericTemplateConstraints(reflection, writer);
            writer.WriteString(">");
        }
Example #52
0
        private void WriteValue(XPathNavigator parent, SyntaxWriter writer)
        {
            XPathNavigator type  = parent.SelectSingleNode(attributeTypeExpression);
            XPathNavigator value = parent.SelectSingleNode(valueExpression);

            if (value == null)
            {
                Console.WriteLine("null value");
            }

            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":
                    bool bool_value = Convert.ToBoolean(text);
                    if (bool_value)
                    {
                        writer.WriteKeyword("true");
                    }
                    else
                    {
                        writer.WriteKeyword("false");
                    }
                    break;

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

        private void WriteParameters(XPathNavigator reflection, SyntaxWriter writer)
        {

            XPathNodeIterator parameters = reflection.Select(apiParametersExpression);

            if (parameters.Count > 0)
            {
                WriteParameters(parameters, reflection, writer);
            }
            else
            {
                writer.WriteKeyword("unit");
                writer.WriteString(" ");
            }
            return;
        }
        /// <summary>
        /// Write out property syntax
        /// </summary>
        /// <param name="reflection">An XPath navigator containing the member information</param>
        /// <param name="writer">The syntax writer to which the information is written</param>
        /// <param name="prefix">The web control prefix to use</param>
        private static void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer, string prefix)
        {
            bool set = (bool)reflection.Evaluate(propertyIsSettable);

            if(!set)
                return;

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

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

            writer.WriteStartBlock(LanguageName, StyleIdName);

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

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

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

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

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

                writer.WriteLine();

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

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

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

            writer.WriteEndBlock();
        }
        private void WriteParameters(XPathNodeIterator parameters, XPathNavigator reflection, SyntaxWriter writer)
        {

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


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

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

        }
Example #56
0
        private static void WriteMemberReference(XPathNavigator member, SyntaxWriter writer)
        {
            string api = member.GetAttribute("api", String.Empty);

            writer.WriteReferenceLink(api);
        }
        // References

        private void WriteTypeReference(XPathNavigator reference, SyntaxWriter writer)
        {
            switch (reference.LocalName)
            {
                case "arrayOf":
                    int rank = Convert.ToInt32(reference.GetAttribute("rank", String.Empty));
                    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;
            }
        }
Example #58
0
        private void WriteParameters(XPathNodeIterator parameters, XPathNavigator reflection, SyntaxWriter writer)
        {
            bool isExtension = (bool)reflection.Evaluate(apiIsExtensionMethod);


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

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

                writer.WriteString("\t");

                if (isExtension && parameters.CurrentPosition == 1)
                {
                    writer.WriteKeyword("this");
                    writer.WriteString(" ");
                }

                if (isRef)
                {
                    if (isOut)
                    {
                        writer.WriteKeyword("out");
                    }
                    else
                    {
                        writer.WriteKeyword("ref");
                    }
                    writer.WriteString(" ");
                }

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

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

                if (parameters.CurrentPosition < parameters.Count)
                {
                    writer.WriteString(",");
                }
                writer.WriteLine();
            }
        }
        public override void WriteConstructorSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {

            string name = (string)reflection.Evaluate(apiContainingTypeNameExpression);
            bool isStatic = (bool)reflection.Evaluate(apiIsStaticExpression);

            WriteAttributes(reflection, writer);

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

        }
Example #60
0
 /// <inheritdoc />
 public override void WriteInterfaceSyntax(XPathNavigator reflection, SyntaxWriter writer)
 {
     TypeDeclaration(reflection, writer, true);  // Need to write variance info for interfaces and delegates
 }