/// <summary> /// Implements a default property implementation for a missing member. /// </summary> /// <param name="memberData">Property data to be loaded.</param> /// <param name="manager">The namespace manager to use for namespace management with type declarations.</param> /// <returns>The fully formatted property source code or null if the member could not be implemented.</returns> public static string FormatMemberProperty(CsProperty memberData, NamespaceManager manager) { //Bounds checking to make sure all data that is needed is provided. If any required data is missing will return null. if (memberData == null) { return(null); } if (!memberData.IsLoaded) { return(null); } if (manager == null) { return(null); } //C# helper used to format output syntax. var formatter = new CodeFactory.SourceFormatter(); //Using the formatter helper to generate a default property signature. string propertySyntax = memberData.CSharpFormatDefaultPropertySignature(manager); //If the property syntax was not created return. if (string.IsNullOrEmpty(propertySyntax)) { return(null); } //If the member has document then will build the documentation. if (memberData.HasDocumentation) { //Using a documentation helper that will generate an enumerator that will output all XML documentation for the member. foreach (var documentation in memberData.CSharpFormatXmlDocumentationEnumerator()) { //Appending each xml document line to the being of the member definition. formatter.AppendCodeLine(0, documentation); } } //The member has attributes assigned to it, append the attributes. if (memberData.HasAttributes) { //Using a documentation helper that will generate an enumerator that will output each attribute definition. foreach (var attributeSyntax in memberData.Attributes.CSharpFormatAttributeDeclarationEnumerator(manager)) { //Appending each attribute definition before the member definition. formatter.AppendCodeLine(0, attributeSyntax); } } //Adding the property declaration formatter.AppendCodeLine(0, propertySyntax); //Adding a extra line feed at the end of the declaration. formatter.AppendCodeLine(0); //The source formatter returning the final results. return(formatter.ReturnSource()); }
/// <summary> /// Generates the source code for a standard property definition. That uses a standard getter and setter. /// </summary> /// <param name="memberData">property data to be loaded.</param> /// <param name="manager">The namespace manager to use for namespace management with type declarations.</param> /// <param name="security">The security level to set the source event source code to. Will default to public if not provided.</param> /// <param name="getSecurity">Set the security level of the get accessor if defined for the property, will default to unknown</param> /// <param name="setSecurity">Set the security level of the set accessor if defined for the property, will default to unknown</param> /// <param name="useKeywords">Include the keywords currently assigned to the event model. Default value is to not include them.</param> /// <param name="includeAbstractKeyword">Optional parameter that determines if it will include the definition for the abstract keyword in the definition if it is defined. default is false.</param> /// <param name="requireStaticKeyword">Adds the static keyword to the signature, default is false.</param> /// <param name="requireSealedKeyword">Adds the sealed keyword to the signature, default is false.</param> /// <param name="requireAbstractKeyword">Adds the abstract keyword to the signature, default is false.</param> /// <param name="requireOverrideKeyword">Adds the override keyword to the signature, default is false.</param> /// <param name="requireVirtualKeyword">Adds the virtual keyword to the signature, default is false.</param> /// <returns>The fully formatted event source code or null if the member could not be implemented.</returns> public static string GenerateStandardPropertySourceCode(CsProperty memberData, NamespaceManager manager, bool useKeywords = false, bool includeAbstractKeyword = false, bool requireStaticKeyword = false, bool requireSealedKeyword = false, bool requireAbstractKeyword = false, bool requireOverrideKeyword = false, bool requireVirtualKeyword = false, CsSecurity security = CsSecurity.Public, CsSecurity getSecurity = CsSecurity.Unknown, CsSecurity setSecurity = CsSecurity.Unknown) { //Bounds checking to make sure all data that is needed is provided. If any required data is missing will return null. if (memberData == null) { return(null); } if (!memberData.IsLoaded) { return(null); } if (manager == null) { return(null); } //C# helper used to format output syntax. var formatter = new CodeFactory.SourceFormatter(); //Using the formatter helper to generate a default event signature. string propertySyntax = memberData.CSharpFormatDefaultPropertySignature(manager, useKeywords, includeAbstractKeyword, requireStaticKeyword, requireSealedKeyword, requireAbstractKeyword, requireOverrideKeyword, requireVirtualKeyword, security, setSecurity, getSecurity); //If the property syntax was not created return. if (string.IsNullOrEmpty(propertySyntax)) { return(null); } //If the member has document then will build the documentation. if (memberData.HasDocumentation) { //Using a documentation helper that will generate an enumerator that will output all XML documentation for the member. foreach (var documentation in memberData.CSharpFormatXmlDocumentationEnumerator()) { //Appending each xml document line to the being of the member definition. formatter.AppendCodeLine(0, documentation); } } //The member has attributes assigned to it, append the attributes. if (memberData.HasAttributes) { //Using a documentation helper that will generate an enumerator that will output each attribute definition. foreach (var attributeSyntax in memberData.Attributes.CSharpFormatAttributeDeclarationEnumerator(manager)) { //Appending each attribute definition before the member definition. formatter.AppendCodeLine(0, attributeSyntax); } } //Adding the event declaration formatter.AppendCodeBlock(0, propertySyntax); //Adding a extra line feed at the end of the declaration. formatter.AppendCodeLine(0); //The source formatter returning the final results. return(formatter.ReturnSource()); }