/// <summary>
        /// Gets the hash code for a formatted method signature using the C# format.
        /// </summary>
        /// <param name="source">The sources <see cref="CsMethod"/> model.</param>
        /// <param name="includeSecurity">Optional parameter that determines to generate security in the definition. By default this is false.</param>
        /// <param name="includeAttributes">Optional parameter that determines if the attributes should be included in the definition. By default this is false.</param>
        /// <param name="includeKeywords">Optional parameter that determines if all keywords are included in the definition. By default this is false.</param>
        /// <returns>The hash code of the formatted model.</returns>
        /// <exception cref="ArgumentNullException">This is thrown if the  model is null.</exception>
        public static int FormatCSharpComparisonHashCode(this CsMethod source, bool includeSecurity = false,
                                                         bool includeAttributes = false, bool includeKeywords = false)
        {
            var dotNetMethod = source as IDotNetMethod;

            return(dotNetMethod.FormatCSharpComparisonHashCode(includeSecurity, includeAttributes, includeKeywords));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor for the <see cref="CsDelegate"/>
 /// </summary>
 /// <param name="isLoaded">Flag that determines if the model was loaded.</param>
 /// <param name="hasErrors">Flag that determine if errors were found creating the model.</param>
 /// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param>
 /// <param name="language">The target language the model was generated from.</param>
 /// <param name="attributes">List of the attributes assigned to this model.</param>
 /// <param name="isGeneric">Flag that determines if the delegate is a generic definition.</param>
 /// <param name="hasStrongTypesInGenerics">Flag that determines if the generics use strong type definitions.</param>
 /// <param name="genericParameters">Generic parameters assigned to the delegate.</param>
 /// <param name="genericTypes">Target types for the generic parameters assigned to the delegate.</param>
 /// <param name="hasDocumentation">Flag that determines if the model has XML documentation assigned to it.</param>
 /// <param name="documentation">The xml documentation assigned to the model.</param>
 /// <param name="lookupPath">The fully qualified model lookup path for this model.</param>
 /// <param name="sourceFiles">List of the fully qualified paths to the source code files this member is defined in.</param>
 /// <param name="name">The name of the model.</param>
 /// <param name="ns">The namespace this delegate is assigned to.</param>
 /// <param name="isVoid">Flag that determines if the return type is void. </param>
 /// <param name="parentPath">THe fully qualified lookup path for the parent model to this one.</param>
 /// <param name="security">The security scope assigned to this model.</param>
 /// <param name="returnType">The type definition for the return type.</param>
 /// <param name="hasParameters">Flag that determines if the delegate had parameters.</param>
 /// <param name="parameters">The parameters assigned to the delegate.</param>
 /// <param name="invokeMethod">The invoke method definition assigned to this delegate.</param>
 /// <param name="beginInvokeMethod">The begin invoke method definition assigned to this delegate.</param>
 /// <param name="endInvokeMethod">The end invoke method definition assigned to this delegate.</param>
 /// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param>
 /// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param>
 /// <param name="modelErrors">Optional the error that occured while creating the model.</param>
 protected CsDelegate(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCodeType language,
                      IReadOnlyList <CsAttribute> attributes, bool isGeneric, bool hasStrongTypesInGenerics, IReadOnlyList <CsGenericParameter> genericParameters,
                      IReadOnlyList <CsType> genericTypes, bool hasDocumentation, string documentation, string lookupPath,
                      IReadOnlyList <string> sourceFiles, string name, string ns, bool hasParameters, bool isVoid, string parentPath,
                      CsSecurity security, CsType returnType, IReadOnlyList <CsParameter> parameters, CsMethod invokeMethod,
                      CsMethod beginInvokeMethod, CsMethod endInvokeMethod, string sourceDocument = null, ModelStore <ICsModel> modelStore = null, IReadOnlyList <ModelLoadException> modelErrors = null)
     : base(isLoaded, hasErrors, loadedFromSource, language, CsModelType.Delegate, sourceDocument, modelStore, modelErrors)
 {
     _attributes = attributes ?? ImmutableList <CsAttribute> .Empty;
     _isGeneric  = isGeneric;
     _hasStrongTypesInGenerics = hasStrongTypesInGenerics;
     _genericParameters        = genericParameters ?? ImmutableList <CsGenericParameter> .Empty;
     _genericTypes             = genericTypes ?? ImmutableList <CsType> .Empty;
     _hasDocumentation         = hasDocumentation;
     _documentation            = documentation;
     _lookupPath        = lookupPath;
     _sourceFiles       = sourceFiles ?? ImmutableList <string> .Empty;
     _name              = name;
     _ns                = ns;
     _hasParameters     = hasParameters;
     _isVoid            = isVoid;
     _parentPath        = parentPath;
     _security          = security;
     _returnType        = returnType;
     _parameters        = parameters ?? ImmutableList <CsParameter> .Empty;
     _invokeMethod      = invokeMethod;
     _beginInvokeMethod = beginInvokeMethod;
     _endInvokeMethod   = endInvokeMethod;
 }
        /// <summary>
        /// Generates the syntax definition of an method in c# syntax.
        /// </summary>
        /// <param name="source">The source <see cref="CsMethod"/> model to generate.</param>
        /// <param name="includeSecurity">Includes the security scope which was defined in the model.</param>
        /// <param name="includeAttributes">Includes definition of the attributes assigned to the model.</param>
        /// <param name="includeKeywords">Includes all keywords assigned to the source model.</param>
        /// <returns>Fully formatted event definition or null if the event data could not be generated.</returns>
        public static string FormatCSharpDeclarationSyntax(this CsMethod source, bool includeSecurity = true,
                                                           bool includeAttributes = true, bool includeKeywords = true)
        {
            var dotNetMethod = source as IDotNetMethod;

            return(dotNetMethod.FormatCSharpDeclarationSyntax(includeSecurity, includeAttributes, includeKeywords));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a fully formatted method signature that also supports implementation of Async Await formatting.
        ///  </summary>
        ///  <param name="methodData">The method data used to build the signature</param>
        /// <param name="supportAsyncKeyword">Optional parameter that determines if the async keyword will be added to the method signature. Default is true.</param>
        /// <returns>Fully formatted method signature for a method implementation from an interface assignment.</returns>
        public static string FormatInterfaceImplementationSignature(this CsMethod methodData, bool supportAsyncKeyword = true)
        {
            if (methodData == null)
            {
                return(null);
            }

            bool isAsyncReturn = false;

            bool isVoid = methodData.IsVoid;

            if (!isVoid)
            {
                isAsyncReturn = methodData.IsAsync;
                if (!isAsyncReturn)
                {
                    isAsyncReturn = methodData.ReturnType.Name == "Task";
                }
                if (!isAsyncReturn)
                {
                    isAsyncReturn = methodData.ReturnType.Name.StartsWith("Task<");
                }
            }
            StringBuilder methodSignature = new StringBuilder($"{methodData.Security.FormatCSharpSyntax()} ");

            if (isVoid)
            {
                methodSignature.Append($"{CodeFactory.DotNet.CSharp.FormattedSyntax.Keywords.Void} ");
            }
            else
            {
                if (isAsyncReturn & supportAsyncKeyword)
                {
                    methodSignature.Append($"{CodeFactory.DotNet.CSharp.FormattedSyntax.CommonContextualKeywords.Async} ");
                }
                methodSignature.Append($"{methodData.ReturnType.FormatCSharpFullTypeName()} ");
            }
            methodSignature.Append(methodData.Name);
            if (methodData.IsGeneric)
            {
                methodSignature.Append(methodData.GenericParameters.FormatCSharpGenericSignatureSyntax());
            }
            methodSignature.Append(methodData.HasParameters ? methodData.Parameters.FormatCSharpParametersSignatureSyntax() : "()");

            return(methodSignature.ToString());
        }
Exemplo n.º 5
0
 /// <summary>
 /// Constructor for the <see cref="CsEvent"/>
 /// </summary>
 /// <param name="isLoaded">Flag that determines if the model was loaded.</param>
 /// <param name="hasErrors">Flag that determine if errors were found creating the model.</param>
 /// <param name="loadedFromSource">Flag that determines if the model was loaded from source code or from an existing library.</param>
 /// <param name="language">The target language the model was generated from.</param>
 /// <param name="eventType">The type definition that supports this event.</param>
 /// <param name="sourceDocument">The source document that was used to build this model. This is optional parameter and can be null.</param>
 /// <param name="modelStore">Optional the lookup storage for models created during the compile or lookup of the model.</param>
 /// <param name="modelErrors">Optional the error that occured while creating the model.</param>
 /// <param name="attributes">List of the attributes assigned to this model.</param>
 /// <param name="sourceFiles">List of the fully qualified paths to the source code files this member is defined in.</param>
 /// <param name="hasDocumentation">Flag that determines if the model has XML documentation assigned to it.</param>
 /// <param name="documentation">The xml documentation assigned to the model.</param>
 /// <param name="lookupPath">The fully qualified model lookup path for this model.</param>
 /// <param name="name">The name of the model.</param>
 /// <param name="parentPath">THe fully qualified lookup path for the parent model to this one.</param>
 /// <param name="security">The security scope assigned to this model.</param>
 /// <param name="isAbstract">Flag that determines if the model is abstract.</param>
 /// <param name="isVirtual">Flag that determines if the model is virtual.</param>
 /// <param name="isSealed">Flag that determines if the model is sealed.</param>
 /// <param name="isOverride">Flag that determines if the model is overridden.</param>
 /// <param name="isStatic">Flag that determines if the model is static.</param>
 /// <param name="eventHandlerDelegate">Delegate model for this event.</param>
 /// <param name="raiseMethod">Model for the raise method for this event.</param>
 /// <param name="addMethod">Model for the add method for this event.</param>
 /// <param name="removeMethod">Model for the remove method for this event.</param>
 protected CsEvent(bool isLoaded, bool hasErrors, bool loadedFromSource, SourceCodeType language,
                   IReadOnlyList <CsAttribute> attributes, IReadOnlyList <string> sourceFiles, bool hasDocumentation, string documentation,
                   string lookupPath, string name, string parentPath, CsSecurity security, bool isAbstract, bool isVirtual, bool isOverride,
                   bool isSealed, bool isStatic, CsDelegate eventHandlerDelegate, CsMethod raiseMethod, CsMethod addMethod, CsMethod removeMethod,
                   CsType eventType, string sourceDocument = null, ModelStore <ICsModel> modelStore = null, IReadOnlyList <ModelLoadException> modelErrors = null) : base(isLoaded, hasErrors, loadedFromSource,
                                                                                                                                                                          language, CsModelType.Event, attributes, sourceFiles, hasDocumentation, documentation,
                                                                                                                                                                          lookupPath, name, parentPath, security, CsMemberType.Event, sourceDocument, modelStore, modelErrors)
 {
     _isAbstract           = isAbstract;
     _isVirtual            = isVirtual;
     _isOverride           = isOverride;
     _isSealed             = isSealed;
     _isStatic             = isStatic;
     _eventHandlerDelegate = eventHandlerDelegate;
     _raiseMethod          = raiseMethod;
     _addMethod            = addMethod;
     _removeMethod         = removeMethod;
     _eventType            = eventType;
 }