Skip to content

Commit e2cdf6c

Browse files
authored
Merge pull request #1 from CodeFactoryLLC/InitialRelease
Initial release and release to github 0.90.202401
2 parents d1765fd + 4545e09 commit e2cdf6c

26 files changed

+2087
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{89050BA1-6328-4A5F-981D-AF9ED7C7983C}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>CodeFactory.Formatting.CSharp</RootNamespace>
11+
<AssemblyName>CodeFactory.Formatting.CSharp</AssemblyName>
12+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="CodeFactory, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0ddb4eb5aaae6a7c, processorArchitecture=MSIL">
35+
<HintPath>..\packages\CodeFactorySDK.1.0.202301\lib\net472\CodeFactory.dll</HintPath>
36+
</Reference>
37+
<Reference Include="CodeFactory.DotNet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0ddb4eb5aaae6a7c, processorArchitecture=MSIL">
38+
<HintPath>..\packages\CodeFactorySDK.1.0.202301\lib\net472\CodeFactory.DotNet.dll</HintPath>
39+
</Reference>
40+
<Reference Include="CodeFactory.Logging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6ebe0889dadef152, processorArchitecture=MSIL">
41+
<HintPath>..\packages\CodeFactorySDK.1.0.202301\lib\net472\CodeFactory.Logging.dll</HintPath>
42+
</Reference>
43+
<Reference Include="CodeFactory.VisualStudio, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0ddb4eb5aaae6a7c, processorArchitecture=MSIL">
44+
<HintPath>..\packages\CodeFactorySDK.1.0.202301\lib\net472\CodeFactory.VisualStudio.dll</HintPath>
45+
</Reference>
46+
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
47+
<HintPath>..\packages\NLog.4.6.8\lib\net45\NLog.dll</HintPath>
48+
</Reference>
49+
<Reference Include="System" />
50+
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
51+
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
52+
</Reference>
53+
<Reference Include="System.Configuration" />
54+
<Reference Include="System.Core" />
55+
<Reference Include="System.IO.Compression" />
56+
<Reference Include="System.Runtime.Serialization" />
57+
<Reference Include="System.ServiceModel" />
58+
<Reference Include="System.Transactions" />
59+
<Reference Include="System.Xml.Linq" />
60+
<Reference Include="System.Data.DataSetExtensions" />
61+
<Reference Include="Microsoft.CSharp" />
62+
<Reference Include="System.Data" />
63+
<Reference Include="System.Net.Http" />
64+
<Reference Include="System.Xml" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<Compile Include="CsAttributeExtensions.cs" />
68+
<Compile Include="CsAttributeParameterExtensions.cs" />
69+
<Compile Include="CsAttributeParameterValueExtensions.cs" />
70+
<Compile Include="CsClassExtensions.cs" />
71+
<Compile Include="CsEnumExtensions.cs" />
72+
<Compile Include="CsEventExtensions.cs" />
73+
<Compile Include="CsFieldExtensions.cs" />
74+
<Compile Include="CsGenericParameterExtensions.cs" />
75+
<Compile Include="CsInterfaceExtensions.cs" />
76+
<Compile Include="CsMethodExtensions.cs" />
77+
<Compile Include="CsParameterDefaultValueExtensions.cs" />
78+
<Compile Include="CsParameterExtensions.cs" />
79+
<Compile Include="CsPropertyExtensions.cs" />
80+
<Compile Include="CsSecurityExtensions.cs" />
81+
<Compile Include="CsSourceExtensions.cs" />
82+
<Compile Include="CsStructureExtensions.cs" />
83+
<Compile Include="CsTypeExtensions.cs" />
84+
<Compile Include="CsUsingStatementExtensions.cs" />
85+
<Compile Include="DocumentationExtensions.cs" />
86+
<Compile Include="NamespaceManager.cs" />
87+
<Compile Include="Properties\AssemblyInfo.cs" />
88+
<Compile Include="CsSourceFormatter.cs" />
89+
</ItemGroup>
90+
<ItemGroup>
91+
<None Include="CodeFactory.Formatting.CSharp.nuspec" />
92+
<None Include="packages.config" />
93+
</ItemGroup>
94+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
95+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd" >
3+
<metadata>
4+
<id>CodeFactory.Formatting.CSharp</id>
5+
<version>0.90.202401</version>
6+
<title>Code Factory Formatting Library for C#</title>
7+
<authors>CodeFactory, LLC.</authors>
8+
<owners>CodeFactory, LLC.</owners>
9+
<license type="expression">MIT</license>
10+
<projectUrl>https://www.codefactory.software/</projectUrl>
11+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
12+
<description>Extension libraries that provide formatters for code factory models to C#</description>
13+
<releaseNotes>Defect fixes for issue #13 source formatter fix and issue #14 Async keyword creating new line on method signature generation.</releaseNotes>
14+
<copyright>Copyright 2020</copyright>
15+
<tags>Factory Automation C#</tags>
16+
<dependencies>
17+
<dependency id="CodeFactorySDK" version="1.0.202301"/>
18+
</dependencies>
19+
</metadata>
20+
</package>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+

2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using CodeFactory.DotNet.CSharp;
5+
using CodeFactory.DotNet.CSharp.FormattedSyntax;
6+
7+
namespace CodeFactory.Formatting.CSharp
8+
{
9+
/// <summary>
10+
/// Extensions class that provides common automation tasks rolled up under standard extension methods that support the <see cref="CsAttribute"/> model.
11+
/// </summary>
12+
public static class CsAttributeExtensions
13+
{
14+
/// <summary>
15+
/// Extension method that returns a full attribute declaration in the C# language format.
16+
/// </summary>
17+
/// <param name="source">The attribute toe generate the c# signature for.</param>
18+
/// <param name="manager">Optional parameter that contains all the using statements from the source code, when used will replace namespaces on type definition in code.</param>
19+
/// <returns>The formatted attribute signature or null if data was missing to create the attribute.</returns>
20+
public static string CSharpFormatAttributeSignature(this CsAttribute source,NamespaceManager manager = null)
21+
{
22+
if (source == null) return null;
23+
if (!source.IsLoaded) return null;
24+
25+
return !source.HasParameters ? $"[{source.Type.CSharpFormatTypeName(manager)}{Symbols.ParametersDefinitionStart}{Symbols.ParametersDefinitionEnd}]" : $"[{source.Type.CSharpFormatTypeName(manager)}{source.Parameters.CSharpFormatAttributeParametersSignature()}]";
26+
}
27+
28+
29+
/// <summary>
30+
/// An iterator that returns fully formatted declaration syntax for a attribute in the C# language
31+
/// </summary>
32+
/// <param name="source">List of attributes to be processed.</param>
33+
/// <param name="manager">Namespace manager used to format type names.This is an optional parameter.</param>
34+
/// <returns>Fully formatted syntax for the attribute.</returns>
35+
public static IEnumerable<string> CSharpFormatAttributeDeclarationEnumerator(this IReadOnlyList<CsAttribute> source,
36+
NamespaceManager manager = null)
37+
{
38+
//No documentation was found for the model, stop the enumeration.
39+
if (source == null) yield break;
40+
41+
if(!source.Any()) yield break;
42+
43+
44+
//iterate over each attribute and confirm it can be formatted as c# attribute syntax.
45+
foreach (CsAttribute attributeData in source)
46+
{
47+
if(attributeData == null) continue;
48+
if(!attributeData.IsLoaded) continue;
49+
50+
var declaration = attributeData.CSharpFormatAttributeSignature(manager);
51+
52+
if(string.IsNullOrEmpty(declaration)) continue;
53+
54+
yield return declaration;
55+
}
56+
}
57+
}
58+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using CodeFactory.DotNet.CSharp;
7+
using CodeFactory.DotNet.CSharp.FormattedSyntax;
8+
9+
namespace CodeFactory.Formatting.CSharp
10+
{
11+
/// <summary>
12+
/// Extensions class that provides common automation tasks rolled up under standard extension methods that support the <see cref="CsAttributeParameter"/> model.
13+
/// </summary>
14+
public static class CsAttributeParameterExtensions
15+
{
16+
/// <summary>
17+
/// Extension method that creates the attributes parameters list for a attribute definition in c# syntax format.
18+
/// </summary>
19+
/// <param name="source">THe source list of parameters to be created.</param>
20+
/// <returns>The fully formatted parameters section of a attribute declaration.</returns>
21+
public static string CSharpFormatAttributeParametersSignature(this IReadOnlyList<CsAttributeParameter> source)
22+
{
23+
if (source == null) return null;
24+
if (!source.Any()) return null;
25+
26+
StringBuilder attributeParameterSignature = new StringBuilder(Symbols.ParametersDefinitionStart);
27+
28+
int totalParameters = source.Count;
29+
int currentParameter = 0;
30+
foreach (var sourceParameter in source)
31+
{
32+
currentParameter++;
33+
string parameter = !sourceParameter.HasNamedParameter ? $"{sourceParameter.Value.CSharpFormatAttributeParameterValueSignature()}" : $"{sourceParameter.Name} = {sourceParameter.Value.CSharpFormatAttributeParameterValueSignature()}";
34+
35+
attributeParameterSignature.Append(parameter);
36+
if (totalParameters > currentParameter) attributeParameterSignature.Append(", ");
37+
}
38+
39+
attributeParameterSignature.Append(Symbols.ParametersDefinitionEnd);
40+
41+
return attributeParameterSignature.ToString();
42+
}
43+
}
44+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using CodeFactory.DotNet;
7+
using CodeFactory.DotNet.CSharp;
8+
using CodeFactory.DotNet.CSharp.FormattedSyntax;
9+
10+
namespace CodeFactory.Formatting.CSharp
11+
{
12+
/// <summary>
13+
/// Extensions class that provides common automation tasks rolled up under standard extension methods that support the <see cref="CsAttributeParameterValue"/> model.
14+
/// </summary>
15+
public static class CsAttributeParameterValueExtensions
16+
{
17+
/// <summary>
18+
/// Creates the implementation of an attribute value formatted for C#.
19+
/// </summary>
20+
/// <param name="source">The source value to format.</param>
21+
/// <returns>The formatted value, or null if the model does not exist.</returns>
22+
public static string CSharpFormatAttributeParameterValueSignature(this CsAttributeParameterValue source)
23+
{
24+
if (source == null) return null;
25+
26+
if (source.ParameterKind != AttributeParameterKind.Array)
27+
return source.TypeValue.FormatCSharpValueSyntax(source.Value);
28+
29+
StringBuilder attributeValueSignature = new StringBuilder($"{Symbols.MultipleStatementStart}");
30+
31+
int totalParameters = source.Values.Count;
32+
int currentValue = 0;
33+
foreach (var sourceValue in source.Values)
34+
{
35+
currentValue++;
36+
string value = sourceValue.ParameterKind != AttributeParameterKind.Array ? $"{sourceValue.TypeValue.FormatCSharpValueSyntax(sourceValue.Value)}" : $"{sourceValue.CSharpFormatAttributeParameterValueSignature()}";
37+
38+
attributeValueSignature.Append(value);
39+
if (totalParameters < currentValue) attributeValueSignature.Append(", ");
40+
}
41+
42+
attributeValueSignature.Append($"{Symbols.MultipleStatementEnd}");
43+
44+
return attributeValueSignature.ToString();
45+
}
46+
}
47+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+

2+
using System.Linq;
3+
using System.Text;
4+
using CodeFactory.DotNet.CSharp;
5+
using CodeFactory.DotNet.CSharp.FormattedSyntax;
6+
7+
namespace CodeFactory.Formatting.CSharp
8+
{
9+
/// <summary>
10+
/// Extensions class that manage extensions that support CodeFactory models that implement the <see cref="CsClass"/> model.
11+
/// </summary>
12+
public static class CsClassExtensions
13+
{
14+
/// <summary>
15+
/// Defines the fully qualified base type name for the class model.
16+
/// </summary>
17+
/// <param name="source">The source interface model to generate the type name from.</param>
18+
/// <param name="manager">Namespace manager used to format type names.This is an optional parameter.</param>
19+
/// <returns>The full type name or null if model data was missing.</returns>
20+
public static string CSharpFormatBaseTypeName(this CsClass source, NamespaceManager manager = null)
21+
{
22+
if (source == null) return null;
23+
if (!source.IsLoaded) return null;
24+
25+
StringBuilder baseNameBuilder = new StringBuilder();
26+
var namespaceManager = manager ?? new NamespaceManager(null);
27+
28+
var targetNamespace = namespaceManager.AppendingNamespace(source.Namespace);
29+
30+
baseNameBuilder.Append(targetNamespace == null ? source.Name : $"{targetNamespace}.{source.Name}");
31+
32+
33+
if (source.IsGeneric)
34+
baseNameBuilder.Append(
35+
source.GenericParameters.CSharpFormatGenericParametersSignature(namespaceManager));
36+
37+
return baseNameBuilder.ToString();
38+
}
39+
40+
/// <summary>
41+
/// Extension method that generates a the full class declaration syntax based on the provided model.
42+
/// </summary>
43+
/// <example>
44+
/// Format with no generics [security] class [name] [:[base class*], [inherited interfaces*]]
45+
/// Format with generics [security] class [name] &lt;[generic parameters]&gt; [: [base class*], [inherited interfaces*]] [Generic Where Clauses*]
46+
/// </example>
47+
/// <param name="source">The source class model to format.</param>
48+
/// <param name="security">The security level the class should be implemented as.</param>
49+
/// <param name="manager">Namespace manager used to format type names.This is an optional parameter.</param>
50+
/// <param name="className">Optional parameter that allows you to specify a new name for the class.</param>
51+
/// <returns>The full class declaration or null if model data was missing.</returns>
52+
public static string CSharpFormatDeclaration(this CsClass source, CsSecurity security, NamespaceManager manager = null,
53+
string className = null)
54+
{
55+
if (source == null) return null;
56+
if (!source.IsLoaded) return null;
57+
bool hasBaseClass = false;
58+
var name = className ?? source.Name;
59+
StringBuilder classBuilder = new StringBuilder($"{security.CSharpFormatKeyword()} {Keywords.Class} {name}");
60+
61+
if (source.IsGeneric) classBuilder.Append(source.GenericParameters.CSharpFormatGenericParametersSignature(manager));
62+
63+
if(source.BaseClass != null)
64+
if (source.BaseClass.Namespace.ToLowerInvariant() == "system" &
65+
source.BaseClass.Name.ToLowerInvariant() == "object") hasBaseClass = false;
66+
else hasBaseClass = true;
67+
68+
if (hasBaseClass)
69+
{
70+
var baseName = source.BaseClass.CSharpFormatBaseTypeName(manager);
71+
if (string.IsNullOrEmpty(baseName)) return null;
72+
classBuilder.Append($":{baseName}");
73+
}
74+
75+
if (source.InheritedInterfaces.Any())
76+
{
77+
var interfaces = source.InheritedInterfaces;
78+
79+
int totalCount = interfaces.Count;
80+
int currentInterface = 0;
81+
82+
classBuilder.Append(hasBaseClass ? ", " :":");
83+
84+
foreach (var csInterface in interfaces)
85+
{
86+
currentInterface++;
87+
88+
var interfaceType = csInterface.CSharpFormatInheritanceTypeName(manager);
89+
90+
if (interfaceType == null) continue;
91+
92+
classBuilder.Append(interfaceType);
93+
if (totalCount > currentInterface) classBuilder.Append(", ");
94+
}
95+
96+
}
97+
98+
if (source.IsGeneric)
99+
{
100+
classBuilder.Append(" ");
101+
102+
foreach (var sourceGenericParameter in source.GenericParameters)
103+
{
104+
var whereClause = sourceGenericParameter.CSharpFormatGenericWhereClauseSignature(manager);
105+
if (string.IsNullOrEmpty(whereClause)) continue;
106+
107+
classBuilder.Append($"{whereClause} ");
108+
109+
}
110+
}
111+
112+
return classBuilder.ToString();
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)