コード例 #1
0
        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);
        }
コード例 #2
0
		private void WriteParameters (XPathNodeIterator parameters, XPathNavigator reflection, SyntaxWriter writer) {

			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 (isIn) WriteAttribute("T:System.Runtime.InteropServices.InAttribute", writer, false);
				if (isOut) WriteAttribute("T:System.Runtime.InteropServices.OutAttribute", writer, false);
				if (isRef) {
					writer.WriteString("/** @ref */");
				}

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

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

		}
コード例 #3
0
        public override void WritePropertySyntax (XPathNavigator reflection, SyntaxWriter writer) {

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

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

			if (isGettable) {
				writer.WriteString("/** @property */");
				writer.WriteLine();
				// 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();
				// write setter method
                WriteAttributes(reflection, writer);
                WriteProcedureModifiers(reflection, writer);
                writer.WriteString(" ");
                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();
			}

		}
コード例 #4
0
		public override void WriteEventSyntax (XPathNavigator reflection, SyntaxWriter writer) {
			string name = (string) reflection.Evaluate(apiNameExpression);
			XPathNavigator handler = reflection.SelectSingleNode(apiHandlerOfEventExpression);

			WriteAttributes(reflection, writer);
			WriteProcedureVisibility(reflection, writer);
			WritePrefixProcedureModifiers(reflection, writer);
			writer.WriteString(" ");
			writer.WriteKeyword("event");
			writer.WriteString(" ");
			WriteTypeReference(handler, writer);
			writer.WriteString(" ");
			writer.WriteIdentifier(name);
			writer.WriteString(" {");
			writer.WriteLine();

			writer.WriteString("\t");
			writer.WriteKeyword("void");
			writer.WriteString(" ");
			writer.WriteKeyword("add");
			writer.WriteString(" (");
			WriteTypeReference(handler, writer);
			writer.WriteString(" ");
			writer.WriteParameter("value");
			writer.WriteString(")");
			writer.WriteString(";");
			writer.WriteLine();

			writer.WriteString("\t");
			writer.WriteKeyword("void");
			writer.WriteString(" ");
			writer.WriteKeyword("remove");
			writer.WriteString(" (");
			WriteTypeReference(handler, writer);
			writer.WriteString(" ");
			writer.WriteParameter("value");
			writer.WriteString(")");
			writer.WriteString(";");
			writer.WriteLine();


			writer.WriteString("}");

		}
コード例 #5
0
        /// <summary>
        /// Write out a parameter
        /// </summary>
        /// <param name="parameter">The parameter information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        private static void WriteParameter(XPathNavigator parameter,
          SyntaxWriter writer)
        {
            string paramName = (string)parameter.Evaluate(
                SyntaxGeneratorTemplate.parameterNameExpression);

            // EFW - Unused so removed
            //            XPathNavigator navigator = parameter.SelectSingleNode(
            //                SyntaxGeneratorTemplate.parameterTypeExpression);

            if((bool)parameter.Evaluate(
              SyntaxGeneratorTemplate.parameterIsParamArrayExpression))
            {
                writer.WriteString("... ");
            }

            writer.WriteParameter(paramName);
        }
コード例 #6
0
        /// <summary>
        /// Write out event syntax
        /// </summary>
        /// <param name="reflection">The reflection information</param>
        /// <param name="writer">The syntax writer to which it is written</param>
        public override void WriteEventSyntax(XPathNavigator reflection,
          SyntaxWriter writer)
        {
            if(!this.IsUnsupported(reflection, writer))
            {
                if(reflection.Select(
                  SyntaxGeneratorTemplate.apiParametersExpression).Count > 0)
                    writer.WriteMessage("UnsupportedIndex_" + this.Language);
                else
                {
                    string identifier = ReadMemberName(reflection);

                    writer.WriteKeyword("function");
                    writer.WriteString(" add_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString("(");
                    writer.WriteParameter("value");
                    writer.WriteString(");");
                    writer.WriteLine();
                    writer.WriteKeyword("function");
                    writer.WriteString(" remove_");
                    writer.WriteIdentifier(identifier);
                    writer.WriteString("(");
                    writer.WriteParameter("value");
                    writer.WriteString(");");
                }
            }
        }
コード例 #7
0
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string            name         = (string)reflection.Evaluate(apiNameExpression);
            string            typeSubgroup = (string)reflection.Evaluate(apiContainingTypeSubgroupExpression);
            bool              isDefault    = (bool)reflection.Evaluate(apiIsDefaultMemberExpression);
            bool              hasGetter    = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool              hasSetter    = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
            bool              isExplicit   = (bool)reflection.Evaluate(apiIsExplicitImplementationExpression);
            XPathNodeIterator parameters   = reflection.Select(apiParametersExpression);

            WriteAttributes(reflection, writer);
            WriteProcedureVisibility(reflection, writer);
            WritePrefixProcedureModifiers(reflection, writer);
            writer.WriteKeyword("property");
            writer.WriteString(" ");
            WriteReturnValue(reflection, writer);
            writer.WriteString(" ");

            // if is default member, write default, otherwise write name
            if (isDefault)
            {
                writer.WriteKeyword("default");
            }
            else
            {
                writer.WriteIdentifier(name);
            }

            if (parameters.Count > 0)
            {
                writer.WriteString("[");
                WriteParameters(parameters.Clone(), false, writer);
                writer.WriteString("]");
            }

            writer.WriteString(" {");
            writer.WriteLine();

            if (hasGetter)
            {
                writer.WriteString("\t");

                //write the get visibility
                string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);
                if (!String.IsNullOrEmpty(getVisibility))
                {
                    WriteVisibility(getVisibility, writer);
                    writer.WriteString(":");
                    writer.WriteString(" ");
                }

                WriteReturnValue(reflection, writer);
                writer.WriteString(" ");
                writer.WriteKeyword("get");
                writer.WriteString(" ");

                writer.WriteString("(");
                WriteParameters(parameters.Clone(), false, writer);
                writer.WriteString(")");

                WritePostfixProcedureModifiers(reflection, writer);
                if (isExplicit)
                {
                    XPathNavigator implement = reflection.SelectSingleNode(apiImplementedMembersExpression);
                    XPathNavigator contract  = implement.SelectSingleNode(memberDeclaringTypeExpression);
                    //string id = (string) implement.GetAttribute("api", String.Empty);

                    writer.WriteString(" = ");
                    WriteTypeReference(contract, false, writer);
                    writer.WriteString("::");
                    WriteMemberReference(implement, writer);
                    //writer.WriteReferenceLink(id);
                    writer.WriteString("::");
                    writer.WriteKeyword("get");
                }
                writer.WriteString(";");
                writer.WriteLine();
            }

            if (hasSetter)
            {
                writer.WriteString("\t");

                // write the set visibility
                string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);
                if (!String.IsNullOrEmpty(setVisibility))
                {
                    WriteVisibility(setVisibility, writer);
                    writer.WriteString(":");
                    writer.WriteString(" ");
                }

                writer.WriteKeyword("void");
                writer.WriteString(" ");
                writer.WriteKeyword("set");
                writer.WriteString(" ");

                writer.WriteString("(");
                if (parameters.Count > 0)
                {
                    WriteParameters(parameters.Clone(), false, writer);
                    writer.WriteString(", ");
                }
                WriteReturnValue(reflection, writer);
                writer.WriteString(" ");
                writer.WriteParameter("value");
                writer.WriteString(")");

                WritePostfixProcedureModifiers(reflection, writer);
                if (isExplicit)
                {
                    XPathNavigator implement = reflection.SelectSingleNode(apiImplementedMembersExpression);
                    XPathNavigator contract  = implement.SelectSingleNode(memberDeclaringTypeExpression);
                    //string id = (string) implement.GetAttribute("api", String.Empty);

                    writer.WriteString(" = ");
                    WriteTypeReference(contract, false, writer);
                    writer.WriteString("::");
                    WriteMemberReference(implement, writer);
                    //writer.WriteReferenceLink(id);
                    writer.WriteString("::");
                    writer.WriteKeyword("set");
                }
                writer.WriteString(";");
                writer.WriteLine();
            }


            writer.WriteString("}");
        }
コード例 #8
0
        public override void WriteAttachedEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string eventName = (string)reflection.Evaluate(apiNameExpression);
            string containingTypeName = (string)reflection.Evaluate(apiContainingTypeNameExpression);
            XPathNavigator eventHandler = reflection.SelectSingleNode(apiHandlerOfEventExpression);

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

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

            writer.WriteEndSubBlock();
        }
コード例 #9
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(")");
            }

        }
コード例 #10
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(");");
            }
        }
コード例 #11
0
        private void ParameterDeclaration (string name, XPathNavigator type, SyntaxWriter writer) {
            writer.WriteKeyword("Dim");
            writer.WriteString(" ");
            writer.WriteParameter(name);
            writer.WriteString(" ");
            writer.WriteKeyword("As");
            writer.WriteString(" ");

            string typeName = (string) type.Evaluate(apiNameExpression);
                        
            if (reservedWords.ContainsKey(typeName)) {
                writer.WriteString("[");
                WriteTypeReference(type, writer);
                writer.WriteString("]");
            } else {
                WriteTypeReference(type, writer);
            }
            
            writer.WriteLine();
        }
コード例 #12
0
        private void WriteParameters(XPathNodeIterator parameters, XPathNavigator reflection, SyntaxWriter writer)
        {
            while (parameters.MoveNext())
            {
                XPathNavigator parameter = parameters.Current;
                string name = (string)parameter.Evaluate(parameterNameExpression);
                writer.WriteParameter(name);

                if (parameters.CurrentPosition < parameters.Count)
                {
                    writer.WriteString(", ");
                    if (writer.Position > maxPosition)
                    {
                        writer.WriteString("_");
                        writer.WriteLine();
                        writer.WriteString("\t");
                    }
                }
            }
        }
コード例 #13
0
        public override void WriteEventSyntax (XPathNavigator reflection, SyntaxWriter writer) {
            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();
        }
コード例 #14
0
        public override void WritePropertySyntax (XPathNavigator reflection, SyntaxWriter writer) {

            if (IsUnsupportedUnsafe(reflection, writer)) return;

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

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

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

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

        }
コード例 #15
0
        public override void WriteCastSyntax (XPathNavigator reflection, SyntaxWriter writer) {
            XPathNavigator parameter = reflection.SelectSingleNode(apiParametersExpression);
            if (parameter == null) return;
            XPathNavigator inputType = parameter.SelectSingleNode(typeExpression);
            XPathNavigator outputType = reflection.SelectSingleNode(apiReturnTypeExpression);
            if ((inputType == null) || (outputType == null)) return;

            ParameterDeclaration("input", inputType, writer);
            ParameterDeclaration("output", outputType, writer);
            writer.WriteLine();
            writer.WriteParameter("output");
            writer.WriteString(" = ");
            writer.WriteKeyword("CType");
            writer.WriteString("(");
            writer.WriteParameter("input");
            writer.WriteString(", ");
            WriteTypeReference(outputType, writer);
            writer.WriteString(")");
        }
コード例 #16
0
 public override void WriteAttachedPropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
 {
     string propertyName = (string)reflection.Evaluate(apiNameExpression);
     string containingTypeName = (string)reflection.Evaluate(apiContainingTypeNameExpression);
     bool isSettable = (bool)reflection.Evaluate(apiIsWritePropertyExpression);
     XPathNavigator returnType = reflection.SelectSingleNode(apiReturnTypeExpression);
     if (!isSettable)
     {
         WriteXamlBoilerplate(XamlBoilerplateID.propertyXamlSyntax_readOnly, writer);
     }
     else
     {
         // xaml syntax block for attached property
         string xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);
         writer.WriteStartSubBlock(xamlBlockId);
         writer.WriteString("<");
         writer.WriteParameter("object");
         writer.WriteString(" ");
         writer.WriteIdentifier(containingTypeName + "." + propertyName);
         writer.WriteString("=\"");
         WriteTypeReference(returnType, writer);
         writer.WriteString("\" .../>");
         writer.WriteEndSubBlock();
     }
 }
コード例 #17
0
        // An Attribute Usage block
        private void PropertyAttributeUsage(XPathNavigator propertyReflection, SyntaxWriter writer)
        {
            string xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlAttributeUsageHeading);
            string propertyName = (string)propertyReflection.Evaluate(apiNameExpression);
            XPathNavigator returnType = propertyReflection.SelectSingleNode(apiReturnTypeExpression);

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

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

            writer.WriteEndSubBlock();
        }
コード例 #18
0
        // JScript has no in, out, optional, or reference parameters
        private void WriteParameter (XPathNavigator parameter, SyntaxWriter writer) {
            string name = (string)parameter.Evaluate(parameterNameExpression);
            XPathNavigator type = parameter.SelectSingleNode(parameterTypeExpression);
            bool isParamArray = (bool)parameter.Evaluate(parameterIsParamArrayExpression);

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

            writer.WriteParameter(name);
            writer.WriteString(" : ");
            WriteTypeReference(type, writer);
        }
コード例 #19
0
        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;
                }
            }

        }
コード例 #20
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(")");
            }
        }
コード例 #21
0
		private void WriteParameters (XPathNodeIterator parameters, bool multiline, SyntaxWriter writer) {
            bool isVarargs = (bool)parameters.Current.Evaluate(apiIsVarargsExpression);

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

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

				if (multiline) {
					writer.WriteString("\t");
				}
				if (isIn) {
					WriteAttribute("T:System.Runtime.InteropServices.InAttribute", false, writer);
					writer.WriteString(" ");
				}
				if (isOut) {
					WriteAttribute("T:System.Runtime.InteropServices.OutAttribute", false, writer);
					writer.WriteString(" ");
				}
				if (isParamArray) writer.WriteString("... ");
				WriteTypeReference(type, writer);
				writer.WriteString(" ");
				writer.WriteParameter(name);

				if (parameters.CurrentPosition < parameters.Count || isVarargs) writer.WriteString(", ");
				if (multiline) writer.WriteLine();
			}
            if (isVarargs)
            {
                if (multiline) writer.WriteString("\t");
                writer.WriteString("...");
                if (multiline) writer.WriteLine();
            }


		}
コード例 #22
0
 private void WriteParameter(XPathNavigator parameter, SyntaxWriter writer) {
     string text = (string)parameter.Evaluate(parameterNameExpression);
     XPathNavigator reference = parameter.SelectSingleNode(parameterTypeExpression);
     if ((bool)parameter.Evaluate(parameterIsParamArrayExpression)) {
         writer.WriteString("... ");
     }
     writer.WriteParameter(text);
 }
コード例 #23
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(");");
            }
        }
コード例 #24
0
        public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer) {
            if (IsUnsupported(reflection, writer)) return;
            
            if (reflection.Select(apiParametersExpression).Count > 0) {
                writer.WriteMessage("UnsupportedIndex_" + Language);
                return;
            }

            string memberName = ReadMemberName(reflection);

            writer.WriteKeyword("function");
            writer.WriteString(" add_");
            writer.WriteIdentifier(memberName);
            writer.WriteString("(");
            writer.WriteParameter("value");
            writer.WriteString(");");

            writer.WriteLine();

            writer.WriteKeyword("function");
            writer.WriteString(" remove_");
            writer.WriteIdentifier(memberName);
            writer.WriteString("(");
            writer.WriteParameter("value");
            writer.WriteString(");");
        }
コード例 #25
0
		public override void WritePropertySyntax (XPathNavigator reflection, SyntaxWriter writer) {
			string name = (string) reflection.Evaluate(apiNameExpression);
			string typeSubgroup = (string) reflection.Evaluate(apiContainingTypeSubgroupExpression);
            bool isDefault = (bool)reflection.Evaluate(apiIsDefaultMemberExpression);
			bool hasGetter = (bool) reflection.Evaluate(apiIsReadPropertyExpression);
			bool hasSetter = (bool) reflection.Evaluate(apiIsWritePropertyExpression);
			bool isExplicit = (bool) reflection.Evaluate(apiIsExplicitImplementationExpression);
			XPathNodeIterator parameters = reflection.Select(apiParametersExpression);

			WriteAttributes(reflection, writer);
			WriteProcedureVisibility(reflection, writer);
			WritePrefixProcedureModifiers(reflection, writer);
            writer.WriteKeyword("property");
            writer.WriteString(" ");
			WriteReturnValue(reflection, writer);
			writer.WriteString(" ");

            // if is default member, write default, otherwise write name
            if (isDefault) {
                writer.WriteKeyword("default");
            } else {
                writer.WriteIdentifier(name);
            }

            if (parameters.Count > 0) {
                writer.WriteString("[");
                WriteParameters(parameters.Clone(), false, writer);
                writer.WriteString("]");
            }

			writer.WriteString(" {");
			writer.WriteLine();

			if (hasGetter) {
				writer.WriteString("\t");

                //write the get visibility
                string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);
                if (!String.IsNullOrEmpty(getVisibility))
                {
                    WriteVisibility(getVisibility, writer);
                    writer.WriteString(":");
                    writer.WriteString(" ");
                }

				WriteReturnValue(reflection, writer);
				writer.WriteString(" ");
				writer.WriteKeyword("get");
				writer.WriteString(" ");

				writer.WriteString("(");
				WriteParameters(parameters.Clone(), false, writer);
				writer.WriteString(")");

				WritePostfixProcedureModifiers(reflection, writer);
				if (isExplicit) {
					XPathNavigator implement = reflection.SelectSingleNode(apiImplementedMembersExpression);
					XPathNavigator contract = implement.SelectSingleNode(memberDeclaringTypeExpression);
					//string id = (string) implement.GetAttribute("api", String.Empty);

					writer.WriteString(" = ");
					WriteTypeReference(contract, false, writer);
					writer.WriteString("::");
                    WriteMemberReference(implement, writer);
					//writer.WriteReferenceLink(id);
					writer.WriteString("::");
					writer.WriteKeyword("get");
				}
				writer.WriteString(";");
				writer.WriteLine();
			}

			if (hasSetter) {
				writer.WriteString("\t");

                // write the set visibility
                string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);
                if (!String.IsNullOrEmpty(setVisibility))
                {
                    WriteVisibility(setVisibility, writer);
                    writer.WriteString(":");
                    writer.WriteString(" ");
                }

				writer.WriteKeyword("void");
				writer.WriteString(" ");
				writer.WriteKeyword("set");
				writer.WriteString(" ");

				writer.WriteString("(");
				if (parameters.Count > 0) {
					WriteParameters(parameters.Clone(), false, writer);
					writer.WriteString(", ");
				}
				WriteReturnValue(reflection, writer);
				writer.WriteString(" ");
				writer.WriteParameter("value");
				writer.WriteString(")");

				WritePostfixProcedureModifiers(reflection, writer);
				if (isExplicit) {
					XPathNavigator implement = reflection.SelectSingleNode(apiImplementedMembersExpression);
					XPathNavigator contract = implement.SelectSingleNode(memberDeclaringTypeExpression);
					//string id = (string) implement.GetAttribute("api", String.Empty);

					writer.WriteString(" = ");
					WriteTypeReference(contract, false, writer);
					writer.WriteString("::");
                    WriteMemberReference(implement, writer);
					//writer.WriteReferenceLink(id);
					writer.WriteString("::");
					writer.WriteKeyword("set");
				}
				writer.WriteString(";");
				writer.WriteLine();
			}


			writer.WriteString("}");
		}
コード例 #26
0
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer) {
            if (IsUnsupported(reflection, writer)) return;
            
            if (HasAttribute(reflection, "System.IntrinsicPropertyAttribute")) {
                WriteFieldSyntax(reflection, writer);
                return;
            }

            string memberName = ReadMemberName(reflection);

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

            bool isGetter = (bool)reflection.Evaluate(apiIsReadPropertyExpression);
            bool isSetter = (bool)reflection.Evaluate(apiIsWritePropertyExpression);

            XPathNavigator reference = reflection.SelectSingleNode(apiReturnTypeExpression);

            if (isGetter) {
                if (isStatic) {
                    writer.WriteIdentifier(ReadFullContainingTypeName(reflection));
                    writer.WriteString(".");

                    writer.WriteString("get_");
                    writer.WriteIdentifier(memberName);
                    writer.WriteString(" = ");
                    writer.WriteKeyword("function");
                }
                else {
                    writer.WriteKeyword("function");
                    writer.WriteString(" ");

                    writer.WriteString("get_");
                    writer.WriteIdentifier(memberName);
                }

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

            if (isSetter) {
                if (isStatic) {
                    writer.WriteIdentifier(ReadFullContainingTypeName(reflection));
                    writer.WriteString(".");

                    writer.WriteString("set_");
                    writer.WriteIdentifier(memberName);
                    writer.WriteString(" = ");
                    writer.WriteKeyword("function");
                }
                else {
                    writer.WriteKeyword("function");
                    writer.WriteString(" ");

                    writer.WriteString("set_");
                    writer.WriteIdentifier(memberName);
                }

                writer.WriteString("(");
                writer.WriteParameter("value");
                writer.WriteString(");");
            }
        }
コード例 #27
0
		// Parameters

		private void WriteParameters (XPathNavigator reflection, SyntaxWriter writer) {

			XPathNodeIterator parameters = reflection.Select(apiParametersExpression);
			if (parameters.Count == 0) return;

			writer.WriteString(" ( _");
			writer.WriteLine();
			while (parameters.MoveNext()) {
				XPathNavigator parameter = parameters.Current;
				XPathNavigator type = parameter.SelectSingleNode(parameterTypeExpression);
				string name = (string) parameter.Evaluate(parameterNameExpression);
				bool isIn = (bool) parameter.Evaluate(parameterIsInExpression);
				bool isOut = (bool) parameter.Evaluate(parameterIsOutExpression);
				bool isParamArray = (bool) parameter.Evaluate(parameterIsParamArrayExpression);
				bool isByRef = (bool) parameter.Evaluate(parameterIsRefExpression);

				writer.WriteString("\t");
				if (isOut) {
					WriteAttribute("T:System.Runtime.InteropServices.OutAttribute", false, writer);
					writer.WriteString(" ");
				}
				if (isParamArray) {
					writer.WriteKeyword("ParamArray");
					writer.WriteString(" ");
				}
				if (isByRef) {
					writer.WriteKeyword("ByRef");
					writer.WriteString(" ");
				}
				writer.WriteParameter(name);
				writer.WriteString(" ");
				writer.WriteKeyword("As");
				writer.WriteString(" ");
				WriteTypeReference(type, writer);
				if (parameters.CurrentPosition < parameters.Count) writer.WriteString(",");
				writer.WriteString(" _");
				writer.WriteLine();
			}
			writer.WriteString(")");

		}
コード例 #28
0
        private 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(Language);

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

        }
コード例 #29
0
		public override void WriteEventSyntax (XPathNavigator reflection, SyntaxWriter writer) {

			if (IsUnsupportedUnsafe(reflection, writer)) return;

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

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

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

		}
コード例 #30
0
        /// <summary>
        /// Write out property syntax
        /// </summary>
        /// <param name="reflection">An XPath navigator containing the member information</param>
        /// <param name="writer">The syntax writer to which the information is written</param>
        /// <param name="prefix">The web control prefix to use</param>
        private static void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer, string prefix)
        {
            bool set = (bool)reflection.Evaluate(propertyIsSettable);

            if(!set)
                return;

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

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

            writer.WriteStartBlock(LanguageName, StyleIdName);

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

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

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

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

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

                writer.WriteLine();

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

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

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

            writer.WriteEndBlock();
        }
コード例 #31
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();
			}

		}
コード例 #32
0
        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");
        }
コード例 #33
0
        // A grandiose Property Element Usage block
        // syntax looks like: 
        //   <object>
        //     <object.PropertyName>
        //       <linkToType .../>
        //     </object.PropertyName>
        //   </object>
        private void PropertyElementUsageGrande(XPathNavigator propertyReflection, SyntaxWriter writer)
        {
            string xamlBlockId = System.Enum.GetName(typeof(XamlHeadingID), XamlHeadingID.xamlPropertyElementUsageHeading);
            string propertyName = (string)propertyReflection.Evaluate(apiNameExpression);
            XPathNavigator returnType = propertyReflection.SelectSingleNode(apiReturnTypeExpression);

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

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

            writer.WriteEndSubBlock();
        }
コード例 #34
0
        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;
            int    type;

            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;

            // 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;
                }
            }
        }
コード例 #35
0
        public override void WriteEventSyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            string eventName = (string)reflection.Evaluate(apiNameExpression);
            string eventVisibility = (string)reflection.Evaluate(apiVisibilityExpression);
            bool isAbstract = (bool)reflection.Evaluate(apiIsAbstractProcedureExpression);
            XPathNavigator eventHandler = reflection.SelectSingleNode(apiHandlerOfEventExpression);

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

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

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

                writer.WriteEndSubBlock();
            }
        }
コード例 #36
0
        /// <inheritdoc />
        public override void WritePropertySyntax(XPathNavigator reflection, SyntaxWriter writer)
        {
            if (IsUnsupportedUnsafe(reflection, writer))
            {
                return;
            }

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

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

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

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

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

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

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

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

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

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

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

                // end parameters
                writer.WriteLine();
            }
        }
コード例 #37
0
        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(" ");
                }
            }

        }
コード例 #38
0
        private void WriteParameters(XPathNodeIterator parameters, SyntaxWriter writer)
        {
            while (parameters.MoveNext())
            {
                XPathNavigator parameter = parameters.Current;

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

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

                writer.WriteString("\t");

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

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

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

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

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

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

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

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

                writer.WriteLine();
            }
        }