public void DocumentAttributeProperty(CodeTypeMember cmm, CodeTypeDeclaration type) { if (this.memberDocumentation.ContainsKey(type)) { IList<string> docs = this.memberDocumentation[type]; string typeName = Regex.Escape(type.Name); string originalName = Char.ToLowerInvariant(cmm.Name[0]) + cmm.Name.Substring(1); const string memberDoc = @"{0}::{1}\n\W*(?<docs>.*?)(\n\s*){{3}}"; for (int i = 0; i < docs.Count; i++) { Match match = Regex.Match(docs[i], string.Format(memberDoc, typeName, originalName), RegexOptions.Singleline | RegexOptions.ExplicitCapture); if (match.Success) { FormatComment(match.Groups["docs"].Value, cmm, i > 0); break; } } } }
public static void FormatComment(string docs, CodeTypeMember cmp, bool obsolete = false, string tag = "summary") { StringBuilder obsoleteMessageBuilder = new StringBuilder(); cmp.Comments.Add(new CodeCommentStatement(string.Format("<{0}>", tag), true)); foreach (string line in HtmlEncoder.HtmlEncode(docs).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.None)) { cmp.Comments.Add(new CodeCommentStatement(string.Format("<para>{0}</para>", line), true)); if (obsolete && (line.Contains("instead") || line.Contains("deprecated"))) { obsoleteMessageBuilder.Append(HtmlEncoder.HtmlDecode(line)); obsoleteMessageBuilder.Append(' '); } } cmp.Comments.Add(new CodeCommentStatement(string.Format("</{0}>", tag), true)); if (obsoleteMessageBuilder.Length > 0) { obsoleteMessageBuilder.Remove(obsoleteMessageBuilder.Length - 1, 1); CodeTypeReference obsoleteAttribute = new CodeTypeReference(typeof(ObsoleteAttribute)); CodePrimitiveExpression obsoleteMessage = new CodePrimitiveExpression(obsoleteMessageBuilder.ToString()); cmp.CustomAttributes.Add(new CodeAttributeDeclaration(obsoleteAttribute, new CodeAttributeArgument(obsoleteMessage))); } }
private void ValidateTypeMember(CodeTypeMember e) { ValidateCommentStatements(e.Comments); ValidateCodeDirectives(e.StartDirectives); ValidateCodeDirectives(e.EndDirectives); if (e.LinePragma != null) ValidateLinePragmaStart(e.LinePragma); if (e is CodeMemberEvent) { ValidateEvent((CodeMemberEvent)e); } else if (e is CodeMemberField) { ValidateField((CodeMemberField)e); } else if (e is CodeMemberMethod) { ValidateMemberMethod((CodeMemberMethod)e); } else if (e is CodeMemberProperty) { ValidateProperty((CodeMemberProperty)e); } else if (e is CodeSnippetTypeMember) { ValidateSnippetMember((CodeSnippetTypeMember)e); } else if (e is CodeTypeDeclaration) { ValidateTypeDeclaration((CodeTypeDeclaration)e); } else { throw new ArgumentException(SR.Format(SR.InvalidElementType, e.GetType().FullName), nameof(e)); } }
private void TypeMemberEnd(CodeTypeMember member) { LinePragmaEnd(member.LinePragma); currentMember = null; }
/// <summary> /// Adds a <c>remarks</c> documentation comment. /// </summary> public virtual void AddRemarksComment(CodeTypeMember item, string remarks) { AddDocumentationComment(item, "remarks", null, "Remarks", remarks); }
private void GenerateMethods(CodeTypeDeclaration e) { foreach (CodeTypeMember current in e.Members) { if (current is CodeMemberMethod && !(current is CodeTypeConstructor) && !(current is CodeConstructor)) { _currentMember = current; if (_options.BlankLinesBetweenMembers) { Output.WriteLine(); } if (_currentMember.StartDirectives.Count > 0) { GenerateDirectives(_currentMember.StartDirectives); } GenerateCommentStatements(_currentMember.Comments); CodeMemberMethod imp = (CodeMemberMethod)current; if (imp.LinePragma != null) { GenerateLinePragmaStart(imp.LinePragma); } if (current is CodeEntryPointMethod) { GenerateEntryPointMethod((CodeEntryPointMethod)current, e); } else { GenerateMethod(imp, e); } if (imp.LinePragma != null) { GenerateLinePragmaEnd(imp.LinePragma); } if (_currentMember.EndDirectives.Count > 0) { GenerateDirectives(_currentMember.EndDirectives); } } } }
/// <summary> /// 增加注释 /// </summary> /// <param name="s"></param> /// <param name="inTarget"></param> public void SetComment(string s, CodeTypeMember inTarget) { inTarget.Comments.Add(new CodeCommentStatement("<summary>", true)); inTarget.Comments.Add(new CodeCommentStatement(s, true)); inTarget.Comments.Add(new CodeCommentStatement("</summary>", true)); }
private static string GetMemberCode(CodeTypeMember member, TextWriter writer) { CodeTypeDeclaration dummyType = new CodeTypeDeclaration(); dummyType.Members.Add(member); Provider.GenerateCodeFromType(dummyType, writer, null); string propertyCode = writer.ToString(); StringBuilder propertyCodeBuilder = new StringBuilder(propertyCode); propertyCodeBuilder.Remove(0, propertyCode.IndexOf('{') + 1); propertyCodeBuilder.Length -= propertyCode.Length - propertyCode.LastIndexOf('}'); propertyCode = propertyCodeBuilder.ToString(); return propertyCode; }
// Methods public int Add(CodeTypeMember value) {}
public int IndexOf(CodeTypeMember value) {}
protected static void AddAttribute(CodeTypeMember type, string attributeName, string value) { var attribute = CreatePrimitiveAttribute(attributeName, value); AddAttribute(type, attribute); }
private void GenerateType(CodeTypeDeclaration type) { this.currentType = type; #if NET_2_0 if (type.StartDirectives.Count > 0) { GenerateDirectives(type.StartDirectives); } #endif foreach (CodeCommentStatement statement in type.Comments) { GenerateCommentStatement(statement); } if (type.LinePragma != null) { GenerateLinePragmaStart(type.LinePragma); } GenerateTypeStart(type); CodeTypeMember[] members = new CodeTypeMember[type.Members.Count]; type.Members.CopyTo(members, 0); #if NET_2_0 if (!Options.VerbatimOrder) #endif { int[] order = new int[members.Length]; for (int n = 0; n < members.Length; n++) { order[n] = Array.IndexOf(memberTypes, members[n].GetType()) * members.Length + n; } Array.Sort(order, members); } // WARNING: if anything is missing in the foreach loop and you add it, add the type in // its corresponding place in CodeTypeMemberComparer class (below) CodeTypeDeclaration subtype = null; foreach (CodeTypeMember member in members) { CodeTypeMember prevMember = this.currentMember; this.currentMember = member; if (prevMember != null && subtype == null) { if (prevMember.LinePragma != null) { GenerateLinePragmaEnd(prevMember.LinePragma); } #if NET_2_0 if (prevMember.EndDirectives.Count > 0) { GenerateDirectives(prevMember.EndDirectives); } #endif } if (options.BlankLinesBetweenMembers) { output.WriteLine(); } subtype = member as CodeTypeDeclaration; if (subtype != null) { GenerateType(subtype); this.currentType = type; continue; } #if NET_2_0 if (currentMember.StartDirectives.Count > 0) { GenerateDirectives(currentMember.StartDirectives); } #endif foreach (CodeCommentStatement statement in member.Comments) { GenerateCommentStatement(statement); } if (member.LinePragma != null) { GenerateLinePragmaStart(member.LinePragma); } CodeMemberEvent eventm = member as CodeMemberEvent; if (eventm != null) { GenerateEvent(eventm, type); continue; } CodeMemberField field = member as CodeMemberField; if (field != null) { GenerateField(field); continue; } CodeEntryPointMethod epmethod = member as CodeEntryPointMethod; if (epmethod != null) { GenerateEntryPointMethod(epmethod, type); continue; } CodeTypeConstructor typeCtor = member as CodeTypeConstructor; if (typeCtor != null) { GenerateTypeConstructor(typeCtor); continue; } CodeConstructor ctor = member as CodeConstructor; if (ctor != null) { GenerateConstructor(ctor, type); continue; } CodeMemberMethod method = member as CodeMemberMethod; if (method != null) { GenerateMethod(method, type); continue; } CodeMemberProperty property = member as CodeMemberProperty; if (property != null) { GenerateProperty(property, type); continue; } CodeSnippetTypeMember snippet = member as CodeSnippetTypeMember; if (snippet != null) { GenerateSnippetMember(snippet); continue; } this.currentMember = prevMember; } // Hack because of previous continue usage if (currentMember != null && !(currentMember is CodeTypeDeclaration)) { if (currentMember.LinePragma != null) { GenerateLinePragmaEnd(currentMember.LinePragma); } #if NET_2_0 if (currentMember.EndDirectives.Count > 0) { GenerateDirectives(currentMember.EndDirectives); } #endif } this.currentType = type; GenerateTypeEnd(type); if (type.LinePragma != null) { GenerateLinePragmaEnd(type.LinePragma); } #if NET_2_0 if (type.EndDirectives.Count > 0) { GenerateDirectives(type.EndDirectives); } #endif }
protected abstract void CreateTypeDocComment(KeyValuePair <string, OpenApiSchema> item, CodeTypeMember typeDeclaration);
public virtual void AddReturnsComment(CodeTypeMember item, string description) { AddDocumentationComment(item, "returns", null, "Returns", description); }
public virtual void AddValueComment(CodeTypeMember item, string description) { AddDocumentationComment(item, "value", null, "Value", description); }
public virtual void AddExceptionComment(CodeTypeMember item, Type exceptionType, string condition) { AddDocumentationComment(item, "exception", "cref=\"" + exceptionType.FullName + "\"", "Exception " + exceptionType, condition); }
/// <summary> /// Adds a <c>param</c> documentation comment. /// </summary> public virtual void AddParameterComment(CodeTypeMember item, string parameterName, string description) { AddDocumentationComment(item, "param", "name=\"" + parameterName + "\"", "Parameter " + parameterName, description); }
private void GenerateType(CodeTypeDeclaration type) { this.currentType = type; this.currentMember = null; // EXTENDED OutputDocumentation(type.Documentation); GenerateTypeStart(type); CodeTypeMember[] members = new CodeTypeMember[type.Members.Count]; type.Members.CopyTo(members, 0); int[] order = new int[members.Length]; for (int n = 0; n < members.Length; n++) order[n] = Array.IndexOf(memberTypes, members[n].GetType()) * members.Length + n; Array.Sort(order, members); // WARNING: if anything is missing in the foreach loop and you add it, add the type in // its corresponding place in CodeTypeMemberComparer class (below) // CLEANUP: This code no longer generates an empty line before the first member // in a class, nor does it generate an empty line between field declarations. CodeTypeDeclaration subtype = null; bool first = true; foreach (CodeTypeMember member in members) { CodeTypeMember prevMember = this.currentMember; this.currentMember = member; if (!first && options.BlankLinesBetweenMembers && !(prevMember is CodeMemberField && currentMember is CodeMemberField)) output.WriteLine(); subtype = member as CodeTypeDeclaration; if (subtype != null) { GenerateType(subtype); this.currentType = type; continue; } // EXTENDED OutputDocumentation(member.Documentation); try { member.Accept(visitor); } catch (NotImplementedException) { throw new ArgumentException("Element type " + member.GetType() + " is not supported."); } first = false; } this.currentType = type; GenerateTypeEnd(type); }
public bool Contains(CodeTypeMember value) {}
protected static void AddAttribute(CodeTypeMember codeObject, CodeAttributeDeclaration attribute) { codeObject.CustomAttributes.Add(attribute); }
public void Remove(CodeTypeMember value) {}
private void MergeTypeMember(CodeTypeMember newMember, CodeTypeMember oldMember) { //!!! need to merge statements. CopyLineInfo(newMember, oldMember); }
private static void AddAttributes(CodeTypeMember method, CodeTypeMember property, CodeSnippetTypeMember propertySnippet, string findRegex, string replaceRegex) { if (method.CustomAttributes.Count > 0) { using (StringWriter writer = new StringWriter()) { string propertyCode = string.IsNullOrEmpty(propertySnippet.Name) ? GetMemberCode(property, writer) : propertySnippet.Text; writer.GetStringBuilder().Length = 0; for (int i = method.CustomAttributes.Count - 1; i >= 0; i--) { CodeAttributeDeclaration attributeDeclaration = method.CustomAttributes[i]; if (attributeDeclaration.AttributeType.BaseType != "SmokeMethod") { propertySnippet.CustomAttributes.Insert(0, attributeDeclaration); method.CustomAttributes.RemoveAt(i); } } string getterCode = GetMemberCode(method, writer); string attribute = string.Format(replaceRegex, regexAttribute.Match(getterCode).Groups[1].Value); string propertyWithAttribute = Regex.Replace(propertyCode, findRegex, attribute); propertySnippet.Name = property.Name; propertySnippet.Attributes = property.Attributes; propertySnippet.Text = propertyWithAttribute; } } }
private static void AdjustField(int fromLine, int lines, int chars, CodeTypeMember cmm) { CodeMemberField field = cmm as CodeMemberField; DoOneAdjust(fromLine, lines, chars, field.InitExpression); }
private void SetPropertyModifiers(Smoke.Method* method, CodeTypeMember cmp) { MemberAttributes access = 0; bool foundInInterface; bool? isOverride = null; if ((cmp.Attributes & MemberAttributes.Override) == MemberAttributes.Override) { isOverride = MethodsGenerator.MethodOverrides(this.data.Smoke, method, out access, out foundInInterface); if (!isOverride.Value) { cmp.Attributes &= ~MemberAttributes.Override; } } if ((method->flags & (uint) Smoke.MethodFlags.mf_virtual) == (int) Smoke.MethodFlags.mf_virtual) { if (!isOverride.HasValue) { isOverride = MethodsGenerator.MethodOverrides(this.data.Smoke, method, out access, out foundInInterface); } if (isOverride.Value) { cmp.Attributes = access | MemberAttributes.Override; } else { cmp.Attributes &= ~MemberAttributes.Final; } } else { if ((method->flags & (uint) Smoke.MethodFlags.mf_purevirtual) == (int) Smoke.MethodFlags.mf_purevirtual) { cmp.Attributes |= MemberAttributes.Abstract; } } }
private static CodeElement CodeElementFromMember(TextPoint Point, vsCMElement Scope, CodeTypeMember ctm) { CodeElement res = CheckAttributes(Point, Scope, ctm.CustomAttributes); if (res != null) { return(res); } CodeMemberMethod method = ctm as CodeMemberMethod; if (method != null) { if (Scope == vsCMElement.vsCMElementFunction) { if (IsInBlockRange(method, Point)) { return((CodeElement)method.UserData[CodeKey]); } } //!!! walk method if (Scope == vsCMElement.vsCMElementParameter || Scope == vsCMElement.vsCMElementAttribute) { foreach (CodeParameterDeclarationExpression param in method.Parameters) { if (IsInRange(param, Point)) { return((CodeElement)method.UserData[CodeKey]); } res = CheckAttributes(Point, Scope, param.CustomAttributes); if (res != null) { return(res); } } foreach (CodeTypeParameter ctp in method.TypeParameters) { if (IsInRange(ctp, Point)) { return((CodeElement)method.UserData[CodeKey]); } res = CheckAttributes(Point, Scope, ctp.CustomAttributes); if (res != null) { return(res); } } } res = CheckAttributes(Point, Scope, method.ReturnTypeCustomAttributes); if (res != null) { return(res); } res = WalkStatements(Point, Scope, method.Statements); if (res != null) { return(res); } } else if (ctm is CodeMemberEvent) { if (Scope == vsCMElement.vsCMElementEvent) { if (IsInRange(ctm, Point)) { return((CodeElement)ctm.UserData[CodeKey]); } } } else if (ctm is CodeMemberProperty) { CodeMemberProperty cmp = ctm as CodeMemberProperty; foreach (CodeParameterDeclarationExpression param in cmp.Parameters) { if (IsInRange(param, Point)) { return((CodeElement)method.UserData[CodeKey]); } res = CheckAttributes(Point, Scope, param.CustomAttributes); if (res != null) { return(res); } } if (Scope == vsCMElement.vsCMElementProperty) { if (IsInBlockRange(ctm, Point)) { return((CodeElement)ctm.UserData[CodeKey]); } } if (cmp.HasGet) { WalkStatements(Point, Scope, cmp.GetStatements); } if (cmp.HasSet) { WalkStatements(Point, Scope, cmp.SetStatements); } } else if (ctm is CodeMemberField) { if (Scope == vsCMElement.vsCMElementVariable) { if (IsInRange(ctm, Point)) { return((CodeElement)ctm.UserData[CodeKey]); } } } return(null); }
public virtual void GenerateCodeFromMember(CodeTypeMember member, TextWriter writer, CodeGeneratorOptions options) { if (_output != null) { throw new InvalidOperationException(SR.CodeGenReentrance); } _options = options ?? new CodeGeneratorOptions(); _output = new ExposedTabStringIndentedTextWriter(writer, _options.IndentString); try { CodeTypeDeclaration dummyClass = new CodeTypeDeclaration(); _currentClass = dummyClass; GenerateTypeMember(member, dummyClass); } finally { _currentClass = null; _output = null; _options = null; } }
/// <summary> /// 增加注释 /// </summary> /// <param name="s"></param> /// <param name="inTarget"></param> public void SetComment(string s, CodeTypeMember inTarget) { inTarget.Comments.Add(new CodeCommentStatement("<summary>", true)); inTarget.Comments.Add(new CodeCommentStatement(s, true)); inTarget.Comments.Add(new CodeCommentStatement("</summary>", true)); }
private void SetProperty(CodeTypeMember codeTypeMember, string name, string value) { CodeDomHelper.AddAttribute(codeTypeMember, PROPERTY_ATTR, name, value); }
private void GenerateConstructors(CodeTypeDeclaration e) { IEnumerator en = e.Members.GetEnumerator(); while (en.MoveNext()) { if (en.Current is CodeConstructor) { currentMember = (CodeTypeMember)en.Current; if (options.BlankLinesBetweenMembers) { Output.WriteLine(); } GenerateCommentStatements(currentMember.Comments, currentMember); CodeConstructor imp = (CodeConstructor)en.Current; GenerateConstructor(imp, e); } } }
public override void GenerateCodeFromMember(CodeTypeMember member, TextWriter writer, CodeGeneratorOptions options) { throw new NotImplementedException(); }
private void RecursivelyAddDependentMembers(IList members, IList constructorStatements, CodeTypeMember current, HashSet <CodeTypeMember> shadows) { if (shadows.Add(current)) { var conflict = members.Cast <CodeTypeMember>().FirstOrDefault(member => AreConflicting(member, current)); if (conflict == null) { members.Add(current); } else { members.Remove(conflict); members.Add(conflict.Merge(current)); } var conStmts = current.ImpliedConstructorStatements(false); if (conStmts != null) { foreach (var stmt in conStmts) { constructorStatements.Add(stmt); } } var dependent = CodeDomHelper.DependentMembers(current, false); if (dependent != null) { foreach (var item in dependent) { RecursivelyAddDependentMembers(members, constructorStatements, item, shadows); } } } }
// Generate various categories of type member. private void TypeMemberStart(CodeTypeMember member) { currentMember = member; if(options.BlankLinesBetweenMembers) { Output.WriteLine(); } GenerateCommentStatements(member.Comments); LinePragmaStart(member.LinePragma); }
public void AddMemeber(CodeTypeMember value) { _targetClass.Members.Add(value); }
public virtual void GenerateCodeFromMember(CodeTypeMember member, TextWriter writer, CodeGeneratorOptions options) { throw new NotImplementedException(); }
public void SetIgnore(CodeTypeMember codeTypeMember) { codeTypeMember.CustomAttributes.Add( new CodeAttributeDeclaration( new CodeTypeReference(IGNORE_ATTR))); }
public void AddRange(CodeTypeMember[] value) {}
public static void AddSummary(CodeTypeMember member, string summary) { member.Comments.Add(new CodeCommentStatement("<summary>", true)); member.Comments.Add(new CodeCommentStatement(summary, true)); member.Comments.Add(new CodeCommentStatement("</summary>", true)); }
public void CopyTo(CodeTypeMember[] array, int index) {}
public static CodeAttributeDeclaration AddAttribute(this CodeTypeMember typeMember, CodeTypeReference type, params CodeExpression[] arguments) { return(Easy.AddAttribute(typeMember.CustomAttributes, type, arguments)); }
public void Insert(int index, CodeTypeMember value) {}
public static CodeTypeDeclaration AddProperty(this CodeTypeDeclaration targetClass, CodeTypeMember property) { targetClass.Members.Add(property); return(targetClass); }
public CodeTypeMemberCollection(CodeTypeMember[] value) {}
public static CodeTypeDeclaration AddProperty(this CodeTypeMember member, CodeMemberProperty property) { var classCode = member.GetDeclaration(); return(classCode.AddProperty(property)); }
private static CodeSnippetTypeMember AddAttributes(CodeTypeMember getter, CodeTypeMember setter, CodeMemberProperty property) { CodeSnippetTypeMember propertySnippet = new CodeSnippetTypeMember(); AddAttributes(getter, property, propertySnippet, @"{(\s*)get", @"{{$1{0}$1get"); if (setter != null) { AddAttributes(setter, property, propertySnippet, @"}(\s*)set", @"}}$1{0}$1set"); } propertySnippet.UserData["interface"] = property.PrivateImplementationType; return propertySnippet; }
public override void GenerateCodeFromMember(CodeTypeMember member, TextWriter writer, CodeGeneratorOptions options) => _generator.GenerateCodeFromMember(member, writer, options);
private static void AddComments(CodeTypeMember completeProperty, CodeCommentStatementCollection comments, bool readOnly) { if (!readOnly) { for (int i = comments.Count - 2; i >= 1; i--) { string comment = comments[i].Comment.Text; if (comment == "<summary>" || comment == "</summary>" || comment.StartsWith("<para>See also ")) { comments.RemoveAt(i); } } } completeProperty.Comments.AddRange(comments); }
private static void AddWarningComment(CodeTypeMember member, int index) { // CONSIDER: add warning comment for filtered member }
private static string NameProperty(CodeTypeMember cmp, Property prop, CodeTypeDeclaration type, IEnumerable<GeneratorData.InternalMemberInfo> members, string className) { cmp.Name = prop.Name; // capitalize the first letter StringBuilder builder = new StringBuilder(cmp.Name); builder[0] = char.ToUpperInvariant(builder[0]); string capitalized = builder.ToString(); // If the new name clashes with a name of a type declaration, keep the lower-case name (or even make the name lower-case). CodeMemberProperty existing = type.Members.OfType<CodeMemberProperty>().FirstOrDefault(p => p.Name == capitalized); if (members.Any(m => m.Name == capitalized && (m.Type == MemberTypes.NestedType || m.Type == MemberTypes.Method)) || existing != null) { Debug.Print( " |--Conflicting names: property/(type or method): {0} in class {1} - keeping original property name", capitalized, className); if (capitalized == cmp.Name) { builder[0] = char.ToLowerInvariant(builder[0]); cmp.Name = builder.ToString(); // lower case the property if necessary } } else { cmp.Name = capitalized; } if (type.Name == "QSvgGenerator" && capitalized == "ViewBoxF") { return "ViewBox"; } return capitalized; }
GenClass PreProcessClass(List <GenClass> aGenClasses, CodeTypeDeclaration type) { GenClass oGenClass = null; //получаем xml namespace string sNamespace = null; bool bIncludeInSchema = true; bool bIsRoot = false; for (int i = 0; i < type.CustomAttributes.Count; i++) { CodeAttributeDeclaration attribute = type.CustomAttributes[i]; if (attribute.Name == "System.Xml.Serialization.XmlTypeAttribute") { foreach (CodeAttributeArgument argument in attribute.Arguments) { if (argument.Name == "Namespace") { sNamespace = ((CodePrimitiveExpression)argument.Value).Value.ToString(); } else if (argument.Name == "IncludeInSchema") { bIncludeInSchema = Convert.ToBoolean(((CodePrimitiveExpression)argument.Value).Value); } //todo argument.Name == "TypeName" } } else if (attribute.Name == "System.Xml.Serialization.XmlRootAttribute") { bIsRoot = true; string sName = null;//todo foreach (CodeAttributeArgument argument in attribute.Arguments) { if (argument.Name == "Namespace") { sNamespace = ((CodePrimitiveExpression)argument.Value).Value.ToString(); } else if ("" == argument.Name) { sName = ((CodePrimitiveExpression)argument.Value).Value.ToString(); } } } } if (bIncludeInSchema) { oGenClass = new GenClass(type.Name, sNamespace); oGenClass.bIsRoot = bIsRoot; int nItemsElementName = 0; if (type.IsEnum) { oGenClass.bIsEnum = true; for (int i = 0; i < type.Members.Count; ++i) { CodeTypeMember member = type.Members[i]; GenMember oGenMember = new GenMember(member.Name); for (int j = 0; j < member.CustomAttributes.Count; j++) { CodeAttributeDeclaration attribute = member.CustomAttributes[j]; if (attribute.Name == "System.Xml.Serialization.XmlEnumAttribute") { ParseArguments(attribute.Arguments, oGenMember); } } oGenClass.aMembers.Add(oGenMember); } } else { for (int i = 0; i < type.Members.Count; ++i) { CodeTypeMember member = type.Members[i]; //CodeMemberField пропускаем CodeMemberProperty codeMemberProperty = member as CodeMemberProperty; if (codeMemberProperty != null) { GenMember oNewGenMember = PreProcessProperty(aGenClasses, codeMemberProperty, oGenClass, ref nItemsElementName); if (null != oNewGenMember) { oGenClass.aMembers.Add(oNewGenMember); } } } } } return(oGenClass); }
private void CommentMember(Smoke* smoke, Smoke.Method* smokeMethod, CodeTypeMember cmm, CodeTypeDeclaration type) { if (this.memberDocumentation.ContainsKey(type)) { IList<string> docs = this.memberDocumentation[type]; string typeName = Regex.Escape(type.Name); string signature = smoke->GetMethodSignature(smokeMethod); StringBuilder signatureRegex = new StringBuilder(); Match matchSignature = Regex.Match(signature, @"(?<name>[^\(]+)\((?<args>.*)\)"); string methodName = Regex.Escape(matchSignature.Groups["name"].Value); signatureRegex.Append(methodName); signatureRegex.Append(@"\s*\(\s*"); string[] argTypes = matchSignature.Groups["args"].Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); const string separator = @",\s*"; foreach (string argType in argTypes) { StringBuilder typeBuilder = new StringBuilder(Regex.Escape(argType)); typeBuilder.Replace(@"\*", @"\s*\*").Replace(@"&", @"\s*&").Replace(type.Name + "::", string.Empty); signatureRegex.Append(Translator.MatchFunctionPointer(typeBuilder.ToString()).Success ? @"[^,]+" : (typeBuilder + @"\s+\w+(\s*=\s*\w+)?")); signatureRegex.Append(separator); } if (argTypes.Length > 0) { signatureRegex.Remove(signatureRegex.Length - separator.Length, separator.Length); } signatureRegex.Append(@"\s*\)\s*"); string memberDoc = @"{0}( |(::)){1}( const)?( \[(\w+\s*)+\])?\n\W*(?<docs>.*?)(\n\s*){{1,2}}((&?\S* --)|((\n\s*){{2}}))"; for (int i = 0; i < docs.Count; i++) { Match match = Regex.Match(docs[i], string.Format(memberDoc, typeName, signatureRegex), RegexOptions.Singleline); if (match.Success) { Util.FormatComment(match.Groups["docs"].Value, cmm, i > 0); break; } memberDoc = @"{0}( |(::)){1}\s*\([^\n]*\)( const)?( \[(\w+\s*)+\])?\n\W*(?<docs>.*?)(\n\s*){{1,2}}((&?\S* --)|((\n\s*){{2}}))"; match = Regex.Match(docs[i], string.Format(memberDoc, typeName, methodName), RegexOptions.Singleline); if (match.Success) { Util.FormatComment(match.Groups["docs"].Value, cmm, i > 0); break; } } } }
protected override void SetAttributes(CodeTypeMember propNode) { propNode.Attributes = MemberAttributes.Public; }
private void GenerateTypeMember(CodeTypeMember member, CodeTypeDeclaration declaredType) { if (_options.BlankLinesBetweenMembers) { Output.WriteLine(); } if (member is CodeTypeDeclaration) { ((ICodeGenerator)this).GenerateCodeFromType((CodeTypeDeclaration)member, _output.InnerWriter, _options); // Nested types clobber the current class, so reset it. _currentClass = declaredType; // For nested types, comments and line pragmas are handled separately, so return here return; } if (member.StartDirectives.Count > 0) { GenerateDirectives(member.StartDirectives); } GenerateCommentStatements(member.Comments); if (member.LinePragma != null) { GenerateLinePragmaStart(member.LinePragma); } if (member is CodeMemberField) { GenerateField((CodeMemberField)member); } else if (member is CodeMemberProperty) { GenerateProperty((CodeMemberProperty)member, declaredType); } else if (member is CodeMemberMethod) { if (member is CodeConstructor) { GenerateConstructor((CodeConstructor)member, declaredType); } else if (member is CodeTypeConstructor) { GenerateTypeConstructor((CodeTypeConstructor)member); } else if (member is CodeEntryPointMethod) { GenerateEntryPointMethod((CodeEntryPointMethod)member, declaredType); } else { GenerateMethod((CodeMemberMethod)member, declaredType); } } else if (member is CodeMemberEvent) { GenerateEvent((CodeMemberEvent)member, declaredType); } else if (member is CodeSnippetTypeMember) { // Don't indent snippets, in order to preserve the column // information from the original code. This improves the debugging // experience. int savedIndent = Indent; Indent = 0; GenerateSnippetMember((CodeSnippetTypeMember)member); // Restore the indent Indent = savedIndent; // Generate an extra new line at the end of the snippet. // If the snippet is comment and this type only contains comments. // The generated code will not compile. Output.WriteLine(); } if (member.LinePragma != null) { GenerateLinePragmaEnd(member.LinePragma); } if (member.EndDirectives.Count > 0) { GenerateDirectives(member.EndDirectives); } }
void MarkAsCompilerGenerated(CodeTypeMember member) { AddCustomAttribute(member.CustomAttributes, typeof(CompilerGeneratedAttribute)); }
private void GenerateSnippetMembers(CodeTypeDeclaration e) { bool hasSnippet = false; foreach (CodeTypeMember current in e.Members) { if (current is CodeSnippetTypeMember) { hasSnippet = true; _currentMember = current; if (_options.BlankLinesBetweenMembers) { Output.WriteLine(); } if (_currentMember.StartDirectives.Count > 0) { GenerateDirectives(_currentMember.StartDirectives); } GenerateCommentStatements(_currentMember.Comments); CodeSnippetTypeMember imp = (CodeSnippetTypeMember)current; if (imp.LinePragma != null) { GenerateLinePragmaStart(imp.LinePragma); } // Don't indent snippets, in order to preserve the column // information from the original code. This improves the debugging // experience. int savedIndent = Indent; Indent = 0; GenerateSnippetMember(imp); // Restore the indent Indent = savedIndent; if (imp.LinePragma != null) { GenerateLinePragmaEnd(imp.LinePragma); } if (_currentMember.EndDirectives.Count > 0) { GenerateDirectives(_currentMember.EndDirectives); } } } // Generate an extra new line at the end of the snippet. // If the snippet is comment and this type only contains comments. // The generated code will not compile. if (hasSnippet) { Output.WriteLine(); } }
private void GenerateType(CodeTypeDeclaration type) { this.currentType = type; this.currentMember = null; if (type.StartDirectives.Count > 0) { GenerateDirectives(type.StartDirectives); } foreach (CodeCommentStatement statement in type.Comments) { GenerateCommentStatement(statement); } if (type.LinePragma != null) { GenerateLinePragmaStart(type.LinePragma); } GenerateTypeStart(type); CodeTypeMember[] members = new CodeTypeMember[type.Members.Count]; type.Members.CopyTo(members, 0); if (!Options.VerbatimOrder) { int[] order = new int[members.Length]; for (int n = 0; n < members.Length; n++) { order[n] = Array.IndexOf(memberTypes, members[n].GetType()) * members.Length + n; } Array.Sort(order, members); } // WARNING: if anything is missing in the foreach loop and you add it, add the type in // its corresponding place in CodeTypeMemberComparer class (below) CodeTypeDeclaration subtype = null; foreach (CodeTypeMember member in members) { CodeTypeMember prevMember = this.currentMember; this.currentMember = member; if (prevMember != null && subtype == null) { if (prevMember.LinePragma != null) { GenerateLinePragmaEnd(prevMember.LinePragma); } if (prevMember.EndDirectives.Count > 0) { GenerateDirectives(prevMember.EndDirectives); } if (!Options.VerbatimOrder && prevMember is CodeSnippetTypeMember && !(member is CodeSnippetTypeMember)) { output.WriteLine(); } } if (options.BlankLinesBetweenMembers) { output.WriteLine(); } subtype = member as CodeTypeDeclaration; if (subtype != null) { GenerateType(subtype); this.currentType = type; continue; } if (currentMember.StartDirectives.Count > 0) { GenerateDirectives(currentMember.StartDirectives); } foreach (CodeCommentStatement statement in member.Comments) { GenerateCommentStatement(statement); } if (member.LinePragma != null) { GenerateLinePragmaStart(member.LinePragma); } try { member.Accept(visitor); } catch (NotImplementedException) { throw new ArgumentException("Element type " + member.GetType() + " is not supported."); } } // Hack because of previous continue usage if (currentMember != null && !(currentMember is CodeTypeDeclaration)) { if (currentMember.LinePragma != null) { GenerateLinePragmaEnd(currentMember.LinePragma); } if (currentMember.EndDirectives.Count > 0) { GenerateDirectives(currentMember.EndDirectives); } if (!Options.VerbatimOrder && currentMember is CodeSnippetTypeMember) { output.WriteLine(); } } this.currentType = type; GenerateTypeEnd(type); if (type.LinePragma != null) { GenerateLinePragmaEnd(type.LinePragma); } if (type.EndDirectives.Count > 0) { GenerateDirectives(type.EndDirectives); } }
private void GenerateProperties(CodeTypeDeclaration e) { foreach (CodeTypeMember current in e.Members) { if (current is CodeMemberProperty) { _currentMember = current; if (_options.BlankLinesBetweenMembers) { Output.WriteLine(); } if (_currentMember.StartDirectives.Count > 0) { GenerateDirectives(_currentMember.StartDirectives); } GenerateCommentStatements(_currentMember.Comments); CodeMemberProperty imp = (CodeMemberProperty)current; if (imp.LinePragma != null) { GenerateLinePragmaStart(imp.LinePragma); } GenerateProperty(imp, e); if (imp.LinePragma != null) { GenerateLinePragmaEnd(imp.LinePragma); } if (_currentMember.EndDirectives.Count > 0) { GenerateDirectives(_currentMember.EndDirectives); } } } }
protected void SetProperty(CodeTypeMember codeTypeMember, string name, string value) { CodeDomHelper.AddAttribute(codeTypeMember, TRAIT_ATTRIBUTE, name, value); }
public virtual void GenerateCodeFromMember(CodeTypeMember member, TextWriter writer, CodeGeneratorOptions options) { // Documented to always throw an exception (if not overriden) throw GetNotImplemented(); // Note: the pattern is different from other GenerateCodeFrom* because // ICodeGenerator doesn't have a GenerateCodeFromMember member }
protected void SetDescription(CodeTypeMember codeTypeMember, string description) { // xUnit doesn't have a DescriptionAttribute so using a TraitAttribute instead SetProperty(codeTypeMember, DESCRIPTION_PROPERTY_NAME, description); }