Category: .NET Core

NetCoreUsefullEndpoints-part 13–adding runtime information

In the Nuget NetCoreUsefullEndpoints I have added information about the runtime information :

You can access by going to localhost:5027/api/usefull/runtimeinformationAll and the end result is

{
“frameworkDescription”: “.NET 8.0.8”,
“osDescription”: “Microsoft Windows 10.0.22631”,
“processArchitecture”: “X64”,
“osArchitecture”: “X64”
}

The code that returns this is

route.MapGet("api/usefull/runtimeinformation/", (HttpContext httpContext) =>
        {
            return TypedResults.Ok(new Helper().FromStaticRuntimeInformation());
        })

( I have used a Roslyn Code Generator , https://ignatandrei.github.io/RSCG_Examples/v2/docs/RSCG_Static#example–source-csproj-source-files- , that generates a class from a static class )

NetCoreUsefullEndpoints-part 12–adding url adresses

In the Nuget NetCoreUsefullEndpoints I have added information about the current process :

You can access by going to localhost:5027/api/usefull/adresses and the end result is

[
     “http://localhost:5027″
]

The code that returns this is

route.MapGet("api/usefull/adresses", (HttpContext httpContext, [FromServices] IServer server) =>
        {
            var adresses = server.Features.Get<IServerAddressesFeature>();
            var ret= adresses?.Addresses?.ToArray()??[] ;
            return TypedResults.Ok(ret);
        });

NetCoreUsefullEndpoints-part 11–adding process information

In the Nuget NetCoreUsefullEndpoints I have added information about the current process :

You can access by going to

http://localhost:5027/api/usefull/process

and this is the result

{
     “id”: 24064,
     “processName”: “TestUsefullEndpoints”,
     “startTime”: “2024-06-27T23:24:36.4003351+03:00”,
     “totalProcessorTime”: “00:00:01.0312500”,
     “threadsCount”: 39,
     “workingSet64”: 84385792,
     “privateMemorySize64”: 65458176,
     “pagedMemorySize64”: 65458176,
     “pagedSystemMemorySize64”: 384840,
     “peakPagedMemorySize64”: 67108864,
     “peakVirtualMemorySize64”: 2481013948416,
     “peakWorkingSet64”: 84733952,
     “virtualMemorySize64”: 2481005563904,
     “basePriority”: 8,
     “handleCount”: 592,
     “machineName”: “.”,
     “priorityClassName”: “Normal”,
     “priorityClass”: 32,
     “nonpagedSystemMemorySize64”: 91992,
     “fileName”: “D:\\gth\\NetCoreUsefullEndpoints\\src\\UsefullEndpoints\\TestUsefullEndpoints\\bin\\Debug\\net8.0\\TestUsefullEndpoints.exe”,
     “minWorkingSet”: 204800,
     “maxWorkingSet”: 1413120,
     “totalProcessorTimeSeconds”: 1.03125,
     “totalUserProcessorTimeSeconds”: 0.921875,
     “totalPrivilegedProcessorTimeSeconds”: 0.109375,
     “fileVersionInfoShort”: {
         “fileVersion”: “1.0.0.0”,
         “fileName”: “D:\\gth\\NetCoreUsefullEndpoints\\src\\UsefullEndpoints\\TestUsefullEndpoints\\bin\\Debug\\net8.0\\TestUsefullEndpoints.exe”,
         “fileDescription”: “TestUsefullEndpoints”,
         “originalFilename”: “TestUsefullEndpoints.dll”,
         “productVersion”: “1.0.0+7f426dfd54f515a95654044b725010b159c89b2f”
     },
     “fileVersionInfo”: {
         “comments”: “”,
         “companyName”: “TestUsefullEndpoints”,
         “fileBuildPart”: 0,
         “fileDescription”: “TestUsefullEndpoints”,
         “fileMajorPart”: 1,
         “fileMinorPart”: 0,
         “fileName”: “D:\\gth\\NetCoreUsefullEndpoints\\src\\UsefullEndpoints\\TestUsefullEndpoints\\bin\\Debug\\net8.0\\TestUsefullEndpoints.exe”,
         “filePrivatePart”: 0,
         “fileVersion”: “1.0.0.0”,
         “internalName”: “TestUsefullEndpoints.dll”,
         “isDebug”: false,
         “isPatched”: false,
         “isPrivateBuild”: false,
         “isPreRelease”: false,
         “isSpecialBuild”: false,
         “language”: “Language Neutral”,
         “legalCopyright”: ” “,
         “legalTrademarks”: “”,
         “originalFilename”: “TestUsefullEndpoints.dll”,
         “privateBuild”: “”,
         “productBuildPart”: 0,
         “productMajorPart”: 1,
         “productMinorPart”: 0,
         “productName”: “TestUsefullEndpoints”,
         “productPrivatePart”: 0,
         “productVersion”: “1.0.0+7f426dfd54f515a95654044b725010b159c89b2f”,
         “specialBuild”: “”
     }
}

And now , because it is version and calendar dependent it is now 8.2024.627.800 ( 8 means .net 8 , then year.monthday.hourminutes) . It is convenient, because you know what version to use ;

NetPackageAnalyzer–part 11–Building Blocks , Test Projects and Root Projects

The .NET Tool , https://www.nuget.org/packages/netpackageanalyzerconsole , can now analyze a solution and see the Building Blocks , Test Projects and Root Projects

Building blocks Projects

I define as Building blocks projects the projects that have no reference to other projects.

If you are new to the solution , then you can start to those base projects – should be self contained and self explanatory

diagram

Root Projects

I define as root projects the projects that are not referenced by any other project and that are not test projects

Can be console, winforms, windows api, mobile , services … Important is that they contain the functionality for the business

diagram

Test Projects

The application shows test projects and the projects that are tested.

diagram

Install from https://nuget.org/packages/netpackageanalyzerconsole

RSCG – Coplt.Dropping

RSCG – Coplt.Dropping
 
 

name Coplt.Dropping
nuget https://www.nuget.org/packages/Coplt.Dropping/
link https://github.com/2A5F/Coplt.Dropping
author 2A5F

Generating disposable

 

This is how you can use Coplt.Dropping .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
	 <PropertyGroup>
        <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
        <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
    </PropertyGroup>
	 <ItemGroup>
	   <PackageReference Include="Coplt.Dropping" Version="0.5.1" OutputItemType="Analyzer" />
	   
	 </ItemGroup>

</Project>


The code that you will use is


using IDisposableGeneratorDemo;
//https://github.com/benutomo-dev/RoslynComponents
using (var db = new DALDB())
{
    Console.WriteLine("before releasing");
}
Console.WriteLine("after releasing");


using Coplt.Dropping;

namespace IDisposableGeneratorDemo;

[Dropping]
partial class DALDB :IDisposable
{
    private ConnectionDB cn;
    private ConnectionDB cn1;

    public DALDB()
    {
        cn = new ConnectionDB();
        cn1=new ConnectionDB();
    }
    [Drop]
    public void Drop()
    {
        cn.Dispose();
        cn1.Dispose();
    }
}



namespace IDisposableGeneratorDemo;

class ConnectionDB : IDisposable
{
    public void Dispose()
    {
        Console.WriteLine("disposing connectiondb");
    }
}


 

The code that is generated is

// <auto-generated/>

#nullable enable

using Coplt.Dropping;

namespace IDisposableGeneratorDemo {

internal partial class DALDB : global::System.IDisposable
{

    protected virtual void Dispose(bool disposing)
    {
        if (disposing) Drop();
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    ~DALDB()
    {
        Dispose(false);
    }

}

} // namespace IDisposableGeneratorDemo

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Coplt.Dropping

RSCG – Fluentify

RSCG – Fluentify
 
 

name Fluentify
nuget https://www.nuget.org/packages/Fluentify/
link https://github.com/MooVC/fluentify
author Paul Martins

Generate fluent builder

 

This is how you can use Fluentify .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

	  <PropertyGroup>
        <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
        <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
    </PropertyGroup>

	  <ItemGroup>
	    <PackageReference Include="Fluentify" Version="1.1.0">
	      <PrivateAssets>all</PrivateAssets>
	      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
	    </PackageReference>
	  </ItemGroup>

	  
</Project>


The code that you will use is


using Builder;

var pOld = new Person();
pOld= pOld.WithFirstName("Andrei").WithLastName("Ignat").WithMiddleName("G");

System.Console.WriteLine(pOld.FullName());



namespace Builder;
[Fluentify.Fluentify]
public partial class Person
{
    public string FirstName { get; init; }
    public string? MiddleName { get; init; }
    public string LastName { get; init; }

    public string FullName()
    {
        return FirstName + " " + MiddleName + " "+LastName;
    }
    
}


 

The code that is generated is

#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
#nullable enable
#endif

#pragma warning disable CS8625

namespace Builder
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Fluentify.Internal;

    public static partial class PersonExtensions
    {
        public static global::Builder.Person WithFirstName(
            this global::Builder.Person subject,
            string value)
        {
            subject.ThrowIfNull("subject");

            return new global::Builder.Person
            {
                FirstName = value,
                MiddleName = subject.MiddleName,
                LastName = subject.LastName,
            };
        }
    }
}

#pragma warning restore CS8625

#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
#nullable restore
#endif
#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
#nullable enable
#endif

#pragma warning disable CS8625

namespace Builder
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Fluentify.Internal;

    public static partial class PersonExtensions
    {
        public static global::Builder.Person WithLastName(
            this global::Builder.Person subject,
            string value)
        {
            subject.ThrowIfNull("subject");

            return new global::Builder.Person
            {
                FirstName = subject.FirstName,
                MiddleName = subject.MiddleName,
                LastName = value,
            };
        }
    }
}

#pragma warning restore CS8625

#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
#nullable restore
#endif
#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
#nullable enable
#endif

#pragma warning disable CS8625

namespace Builder
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Fluentify.Internal;

    public static partial class PersonExtensions
    {
        public static global::Builder.Person WithMiddleName(
            this global::Builder.Person subject,
            string? value)
        {
            subject.ThrowIfNull("subject");

            return new global::Builder.Person
            {
                FirstName = subject.FirstName,
                MiddleName = value,
                LastName = subject.LastName,
            };
        }
    }
}

#pragma warning restore CS8625

#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
#nullable restore
#endif
namespace Fluentify
{
    using System;
    using System.Diagnostics.CodeAnalysis;

    [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    internal sealed class DescriptorAttribute
        : Attribute
    {
        public DescriptorAttribute(string value)
        {
            Value = value;
        }

        public string Value { get; }
    }
}
namespace Fluentify
{
    using System;

    [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
    internal sealed class FluentifyAttribute
        : Attribute
    {
    }
}
namespace Fluentify
{
    using System;

    [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    internal sealed class IgnoreAttribute
        : Attribute
    {
    }
}
namespace Fluentify.Internal
{
    using System;

    internal static class Extensions
    {
        public static void ThrowIfNull(this object subject, string paramName)
        {
            if (subject == null)
            {
                throw new ArgumentNullException(paramName);
            }
        }
    }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Fluentify

RSCG – RSCG_ExportDiagram

RSCG – RSCG_ExportDiagram
 
 

name RSCG_ExportDiagram
nuget https://github.com/ignatandrei/RSCG_ExportDiagram
link RSCG_ExportDiagram
author AndreiIgnat

Generating diagram for relation classes within referenced project

 

This is how you can use RSCG_ExportDiagram .

The code that you start with is


<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

	<ItemGroup>
		<PackageReference Include="RSCG_ExportDiagram" Version="2024.810.832" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
	</ItemGroup>
	<ItemGroup>
		<CompilerVisibleProperty Include="RSCG_ExportDiagram_OutputFolder" />
		<CompilerVisibleProperty Include="RSCG_ExportDiagram_Exclude" />
	</ItemGroup>
	<ItemGroup>
	  <ProjectReference Include="..\Person\Person.csproj" />
	</ItemGroup>
	<PropertyGroup>
		<RSCG_ExportDiagram_OutputFolder>obj/GX/</RSCG_ExportDiagram_OutputFolder>
		<RSCG_ExportDiagram_Exclude></RSCG_ExportDiagram_Exclude>
	</PropertyGroup>
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
</Project>


The code that you will use is


using Person;

internal class Program
{
    private static void Main(string[] args)
    {
        PersonData person = new ();
        person.Name = "Andrei Ignat";
        Console.WriteLine(person.Name);
    }
}


namespace Person;

public class PersonData
{
    public string Name { get; set; }
    public int Age { get; set; }
}




 

The code that is generated is


//JSONFolder=obj/GX/
//projectDir=D:\gth\RSCG_Examples\v2\rscg_examples\RSCG_ExportDiagram\src\DiagramDemo\DiagramDemoConsole\
//projectName=DiagramDemoConsole
//excludeData=
file class Program_References_1
{
    public Program_References_1()
{
     

// Method Main has following external references
// Person.PersonData..ctor
//Person.PersonData.Name

}
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/RSCG_ExportDiagram

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.