Bailey
reflection good course
Hello,
This is not a request for help with code. I already have used reflection to make several programs like a serialiser and deserialiser based on excel input / output. However it did take me a day or so to get it working because list objects cannot be cast to list. They need to be cast to IList. IList has some other issues.
Now I'm searching for a good course on reflection which also goes deep into the reflection and how to handle the objects.
The microsoft pages aren't very clear at least for me.
20 replies
Reflection and customclass in list properties c#
Hello,
I am trying to solve the folowing. I got a list<person> I want to use reflection to get the list and walk through the properties.
I have put some fictional code in this. The problem is with the list. How to solve this so that I can use the for or foreach loop to go to the next level the custom class properties.
namespace reflection
{
internal class Program
{
// just sample
static void Main(string[] args)
{
List<Person> list = new List<Person>();
list.Add(new Person() { Age= 2, Name="a"});
list.Add(new Person() { Age = 3, Name = "b" });
var analyse = new analyse();
analyse.analyseThis(list);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace reflection
{
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace reflection
{
public class analyse
{
public void analyseThis(object test)
{
var data = test.GetType().GenericTypeArguments[0];
// how to get this working
foreach (var customClass in test.GetType().)
{
// below works for clASS.
Type type = customClass.GetType();
PropertyInfo[] propertyInfos = customClass.GetType().GetProperties();
// here the code
}
}
}
}
18 replies
Multipart dataresponse compatible with swagger.
Hello,
I'm searching for a way to define a multipart dataresponse,
The following controller code accepts multipart formdata.
In the code the fromForm icm with the model that it can receive multipart data.
However, I'm searching how to define this part: [ProducesResponseType(typeof(testResponseModel), StatusCodes.Status200OK)]
So My response can also send multipart data, and swagger will accept it.
To be honest, I do not think it is a standard and is not supported by the defaults
I can define in the testResponseModel to add IFormFile, but swagger does not see it as a multipartform while using FromForm (see request, it is multipart).
Does anyOne know a sollution to respond as a multipart form data where there the metadata and file are multipart
[HttpPost(Name = "SaveFile")]
[ProducesResponseType(typeof(testResponseModel), StatusCodes.Status200OK)]
public async Task<testResponseModel> StoreAsynchronous([FromForm] SaveFileModel request)
{
try
{
return null;
}
catch (Exception ex)
{
throw;
}
}
1 replies
✅ Theoretical question. MediatR and DTO and onion structure
Hello,
THe following is just theoretical and I do not need any code
In the programming world, transferring the received object from the api to other parts of the programm for processing is seen as bad practise.
Keeping this in mind, then we should map the received data (could use automapper).
However if I use the onion structure in combination with Mediatr, there is a mapping done automaticly. The reason why I think this is because MediatR (if I'm correct) uses reflection and generic types. This means that there already is a mapping (indirect).
Now I think about using this structure without the mappings.
ps. If I would use n-tier structure the mapping would go to the same properties in the object only from the contract to the dto.
My question what are you're thoughts on this.
16 replies
✅ Entityframework for framework 4.8 instead of .net / core
Hello,
I'm trying to use EF with framework 4.8. There is a version 6.4.4.
When using this, I cant find a lot of options which are available in .net 6 version of EF.
I'm searching for an equivalent of these options. Possible they do not exist.
In this case I'm talking about the following:
override to attach to a config:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration<ProductModel>(new ProductConfiguration());
// etc
The configuration option:
public class ProductConfiguration : IEntityTypeConfiguration<ProductModel>
{
public void Configure(EntityTypeBuilder<ProductModel> builder)
{
builder.ToTable("Products");
builder.HasKey(p => p.ProductId);
builder.Property(p => p.ProductId)
.HasColumnName("ProductId")
.HasColumnType("uniqueidentifier")
.IsRequired();
// etc
22 replies
✅ Running in the microsoft cloud
Hello,
I have to create a service which can run on the cloud (specs are not everything).
So I thought, cot net 8 is compatible and using mediatr pattern for aa service is also OK.
However there are possible things I didnt think of like (I do not know the real name) serive on demand which starts a program only when there is a request.
Has someone any advice ?
Like some short manual or something
43 replies
using serilog (c#) in a vb.net
Hello,
I have an old application which is written in vb.net.
I'm searching for a sollution to use serilog.
On internet I found 1 entry which says I have to add serilog to the global.asax of vb.net.
In the global asax we need to add serilogger confioguration.
My problem is that I cant use Log.Information in the program itself.
Does anyone know a sollution. Im not a vb programmer
27 replies
❔ c# .net6 cryptograpy example
Hello.
I'm searching for an example for encryption.
I already looked at: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.aes?view=net-6.0
I copied the example and I can overwrite the aeskey. However I can only use exactly 32 characters more or less are not allowed.
ofcourse I kan add or remove characters to get to exactly 32. But I search for a good example where you can add any password /. key
Hope some can help
7 replies
❔ nuget doesnt work anymore. I
Hi,
I checked the settings and it seems good.
https://api.nuget.org/v3/index.json
I get the following error:
The underlying connection was closed: An unexpected error occurred on a send.
Unable to write data to the transport connection:
but the strange thing is the url:
[nuget.org] Failed to retrieve metadata from source 'https://azuresearch-ussc.nuget.org
last part of the error:
An error occurred while sending the request.
The underlying connection was closed: An unexpected error occurred on a send.
Unable to read data from the transport connection:
going with IE to the json no problem does anyone know a sollution ?
22 replies
❔ Searching for good multiTask Example in List<task>
Hello,
I'm seeking a good example of a multitask async
I hope to clearify my question with the code.
I'm trying to start multiple tasks which are defined in a list. Every time I try, I get stuck.
I also want to be able to limit the amount of tasks.
I hope someone has a simple example.
Best Regards
Code:
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
// create objects to start a scoped task
List<DiffentClass> diffentClasses = new List<DiffentClass>();
for (int i = 0; i < 10; i++)
diffentClasses.Add(new DiffentClass());
foreach (var diffentClass in diffentClasses)
{
// begin task
}
// Wait to finisch and merge ... } } } the task should be directed to: namespace OtherProjectApp { public class DiffentClass { public async Task<string> PlaceHolder(string LotsOfDate, int taskNumber) { for (int i = 0; i < 10000; i++) { Thread.Sleep(1000); await Console.Out.WriteLineAsync($"placeholder {taskNumber.ToString()}" ); } return "ready"; } } }
// Wait to finisch and merge ... } } } the task should be directed to: namespace OtherProjectApp { public class DiffentClass { public async Task<string> PlaceHolder(string LotsOfDate, int taskNumber) { for (int i = 0; i < 10000; i++) { Thread.Sleep(1000); await Console.Out.WriteLineAsync($"placeholder {taskNumber.ToString()}" ); } return "ready"; } } }
11 replies
❔ openid connect oauth2
Hello,
Does anyone have a good example of oauth2 implementation with openId.
Where the oauth token has to be validated against an endpoint
Like (found this somewhere):
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.Authority = "https://aUTHORITY";
options.ClientId = "platformnet6";
options.ClientSecret = "123456789"; // need 1 without client secret
options.ResponseType = "code";
options.CallbackPath = "/signin-oidc";
options.SaveTokens = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = false,
SignatureValidator = delegate(string token, TokenValidationParameters validationParameters)
{
var jwt = new JwtSecurityToken(token);
return jwt;
},
};
});
5 replies