summaryrefslogtreecommitdiffstats
path: root/tools/Sandcastle/Source/BuildAssembler/SyntaxComponents/CSharpDeclarationSyntax.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-09-20 21:45:59 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-09-21 08:06:25 -0700
commite4e6423ed5f5ba51c500780b5ce72fcd64d63156 (patch)
treecded6512b7591e569aeeb78419ca0007f7dced01 /tools/Sandcastle/Source/BuildAssembler/SyntaxComponents/CSharpDeclarationSyntax.cs
parentbbe3f9cc9c8a1e5909273c1a162a63ea7a66afd8 (diff)
downloadDotNetOpenAuth-e4e6423ed5f5ba51c500780b5ce72fcd64d63156.zip
DotNetOpenAuth-e4e6423ed5f5ba51c500780b5ce72fcd64d63156.tar.gz
DotNetOpenAuth-e4e6423ed5f5ba51c500780b5ce72fcd64d63156.tar.bz2
Upgraded to latest Sandcastle changeset (26202).
Diffstat (limited to 'tools/Sandcastle/Source/BuildAssembler/SyntaxComponents/CSharpDeclarationSyntax.cs')
-rw-r--r--tools/Sandcastle/Source/BuildAssembler/SyntaxComponents/CSharpDeclarationSyntax.cs144
1 files changed, 93 insertions, 51 deletions
diff --git a/tools/Sandcastle/Source/BuildAssembler/SyntaxComponents/CSharpDeclarationSyntax.cs b/tools/Sandcastle/Source/BuildAssembler/SyntaxComponents/CSharpDeclarationSyntax.cs
index 747d53f..3b5922d 100644
--- a/tools/Sandcastle/Source/BuildAssembler/SyntaxComponents/CSharpDeclarationSyntax.cs
+++ b/tools/Sandcastle/Source/BuildAssembler/SyntaxComponents/CSharpDeclarationSyntax.cs
@@ -1,5 +1,8 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-//
+// Copyright © Microsoft Corporation.
+// This source file is subject to the Microsoft Permissive License.
+// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
+// All other rights reserved.
+
using System;
using System.Collections.Generic;
using System.Xml.XPath;
@@ -10,7 +13,7 @@ namespace Microsoft.Ddue.Tools {
public class CSharpDeclarationSyntaxGenerator : SyntaxGeneratorTemplate {
public CSharpDeclarationSyntaxGenerator (XPathNavigator configuration) : base(configuration) {
- if (String.IsNullOrEmpty(language)) language = "CSharp";
+ if (String.IsNullOrEmpty(Language)) Language = "CSharp";
}
// namespace: done
@@ -88,7 +91,7 @@ namespace Microsoft.Ddue.Tools {
writer.WriteKeyword("interface");
writer.WriteString(" ");
writer.WriteIdentifier(name);
- WriteGenericTemplates(reflection, writer);
+ WriteGenericTemplates(reflection, writer, true); // interfaces need co/contravariance info
WriteImplementedInterfaces(reflection, writer);
WriteGenericTemplateConstraints(reflection, writer);
@@ -109,7 +112,7 @@ namespace Microsoft.Ddue.Tools {
WriteReturnValue(reflection, writer);
writer.WriteString(" ");
writer.WriteIdentifier(name);
- WriteGenericTemplates(reflection, writer);
+ WriteGenericTemplates(reflection, writer, true); // delegates need co/contravariance info
WriteMethodParameters(reflection, writer);
WriteGenericTemplateConstraints(reflection, writer);
@@ -291,7 +294,7 @@ namespace Microsoft.Ddue.Tools {
} else if (name == "Explicit") {
writer.WriteKeyword("explicit operator");
} else {
- throw new Exception();
+ throw new InvalidCastException("Invalid cast.");
}
writer.WriteString(" ");
WriteReturnValue(reflection, writer);
@@ -300,61 +303,77 @@ namespace Microsoft.Ddue.Tools {
}
- public override void WritePropertySyntax (XPathNavigator reflection, SyntaxWriter writer) {
-
- string name = (string) reflection.Evaluate(apiNameExpression);
+ 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);
-
- WriteAttributes(reflection, writer);
- if (!isExplicit) WriteProcedureModifiers(reflection, writer);
- WriteReturnValue(reflection, writer);
- writer.WriteString(" ");
+ 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);
- //string id = (string) member.GetAttribute("api", String.Empty);
- XPathNavigator contract = member.SelectSingleNode(memberDeclaringTypeExpression);
- WriteTypeReference(contract, writer);
- writer.WriteString(".");
- WriteMemberReference(member, writer);
- //writer.WriteReferenceLink(id);
- // writer.WriteIdentifier(memberName);
- } else {
- if (isDefault) {
+ 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 {
+ }
+ 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) {
+ WritePropertyParameters(reflection, writer);
+ writer.WriteString(" {");
+ if (isGettable)
+ {
writer.WriteString(" ");
string getVisibility = (string)reflection.Evaluate(apiGetVisibilityExpression);
- if (!String.IsNullOrEmpty(getVisibility)) {
+ if (!String.IsNullOrEmpty(getVisibility))
+ {
WriteVisibility(getVisibility, writer);
writer.WriteString(" ");
}
writer.WriteKeyword("get");
writer.WriteString(";");
}
- if (isSettable) {
+ if (isSettable)
+ {
writer.WriteString(" ");
string setVisibility = (string)reflection.Evaluate(apiSetVisibilityExpression);
- if (!String.IsNullOrEmpty(setVisibility)) {
+ if (!String.IsNullOrEmpty(setVisibility))
+ {
WriteVisibility(setVisibility, writer);
writer.WriteString(" ");
}
writer.WriteKeyword("set");
writer.WriteString(";");
}
- writer.WriteString(" }");
-
- }
+ writer.WriteString(" }");
+ }
public override void WriteEventSyntax (XPathNavigator reflection, SyntaxWriter writer) {
string name = (string) reflection.Evaluate(apiNameExpression);
@@ -667,21 +686,44 @@ namespace Microsoft.Ddue.Tools {
// Generics
- private void WriteGenericTemplates (XPathNavigator reflection, SyntaxWriter writer) {
+ 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(name);
- if (templates.CurrentPosition < templates.Count) writer.WriteString(", ");
- }
- writer.WriteString(">");
+ WriteGenericTemplates(reflection, writer, false);
}
+ private void WriteGenericTemplates(XPathNavigator reflection, SyntaxWriter writer, bool writeVariance)
+ {
+ XPathNodeIterator templates = (XPathNodeIterator)reflection.Evaluate(apiTemplatesExpression);
+
+ if (templates.Count == 0) return;
+ writer.WriteString("<");
+ while (templates.MoveNext())
+ {
+ XPathNavigator template = templates.Current;
+ 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);
+ if (templates.CurrentPosition < templates.Count) writer.WriteString(", ");
+ }
+ writer.WriteString(">");
+
+ }
+
private void WriteGenericTemplateConstraints (XPathNavigator reflection, SyntaxWriter writer) {
XPathNodeIterator templates = reflection.Select(apiTemplatesExpression);