internal static CodeTypeDeclaration GenerateScopeEnumeration(IEnumerable <Scope> scopes) { CodeTypeDeclaration decl = new CodeTypeDeclaration(EnumName); decl.IsEnum = true; decl.Comments.AddRange(DecoratorUtil.CreateSummaryComment(EnumDescription)); // Add the enumeration members. List <string> usedWords = new List <string>(); foreach (Scope scope in scopes) { // Create a enum name string valueName = GetValueName(scope); string safeName = GeneratorUtils.GetEnumValueName(valueName, usedWords); // Create the value and add the StringValue attribute. var newMember = new CodeMemberField(typeof(int), safeName); var stringValueRef = new CodeTypeReference(typeof(StringValueAttribute)); var stringValueAttribute = new CodeAttributeDeclaration(stringValueRef); stringValueAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(scope.ID))); newMember.CustomAttributes.Add(stringValueAttribute); // Add the description. newMember.Comments.AddRange(DecoratorUtil.CreateSummaryComment(scope.Description)); usedWords.Add(safeName); decl.Members.Add(newMember); } return(decl); }
public void CreateSummaryCommentXmlEscapeTest() { string aShortDescription = "A 'Short\" <description> <for/> test & fun"; var result = DecoratorUtil.CreateSummaryComment(aShortDescription); string desiredComment = "<summary>A 'Short" <description> <for/> test & fun</summary>"; Assert.AreEqual(desiredComment, result[0].Comment.Text); }
public void CreateSummaryCommentTest() { string aShortDescription = "A Short description for test"; var result = DecoratorUtil.CreateSummaryComment(aShortDescription); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); Assert.IsNotNull(result[0].Comment); Assert.AreEqual(true, result[0].Comment.DocComment); Assert.AreEqual("<summary>" + aShortDescription + "</summary>", result[0].Comment.Text); }
internal static CodeTypeDeclaration GenerateEnum(CodeTypeDeclaration typeDeclaration, string proposedName, string description, IEnumerable <KeyValuePair <string, string> > entries) { typeDeclaration.ThrowIfNull("typeDeclaration"); proposedName.ThrowIfNullOrEmpty("proposedName"); entries.ThrowIfNull("entries"); // Create a safe enum name by avoiding the names of all members which are already in this type. IEnumerable <string> memberNames = from CodeTypeMember m in typeDeclaration.Members select m.Name; string name = GeneratorUtils.GetEnumName(proposedName, memberNames); // Create the enum type. var decl = new CodeTypeDeclaration(name); decl.IsEnum = true; // Get the EnumStringValueTypeConverter type. Type converterType = typeof(EnumStringValueTypeConverter); // [TypeConverter(..)] var typeConvAttribute = new CodeAttributeDeclaration( new CodeTypeReference(typeof(TypeConverterAttribute))); // .. typeof(EnumStringValueTypeConverter) .. typeConvAttribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(converterType))); decl.CustomAttributes.Add(typeConvAttribute); foreach (KeyValuePair <string, string> enumEntry in entries) { // Consider the names of all members in the current type as used words. IEnumerable <string> usedNames = from CodeTypeMember m in decl.Members select m.Name; string safeName = GeneratorUtils.GetEnumValueName(enumEntry.Key, usedNames); var member = new CodeMemberField(typeof(int), safeName); // Attribute: var valueAttribute = new CodeAttributeDeclaration(); valueAttribute.Name = typeof(StringValueAttribute).FullName; valueAttribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(enumEntry.Key))); member.CustomAttributes.Add(valueAttribute); // Comments: member.Comments.AddRange(DecoratorUtil.CreateSummaryComment(enumEntry.Value)); // Add member to enum. decl.Members.Add(member); } // Class comment: decl.Comments.AddRange(DecoratorUtil.CreateSummaryComment(description)); return(decl); }
public void CreateSummaryCommentEmptyCommentTest() { // Test an empty comment. var result = DecoratorUtil.CreateSummaryComment(""); Assert.IsNotNull(result); Assert.IsEmpty(result); // Test a null comment. result = DecoratorUtil.CreateSummaryComment(null); Assert.IsNotNull(result); Assert.IsEmpty(result); }
internal CodeCommentStatementCollection CreateComment(JsonSchema schema) { schema.ThrowIfNull("schema"); return(DecoratorUtil.CreateSummaryComment(schema.Description)); }