Alex Frost
Alex Frost
CC#
Created by Alex Frost on 8/22/2023 in #help
❔ Change datatype during program execution
I have following two properties: private ContextType ExportContext = 0; private List<T> SelectedItems { get; set; } = new(); During execution, value of ContextType can be changed by user only if SelectedItems is empty. Based on value of ExportContext, I want to change the datatype T. Is that possible?
10 replies
CC#
Created by Alex Frost on 8/9/2023 in #help
❔ Get list of indices from a List
I have a result set called "result". I want to use Linq to get a list of distinct items by name and their indices in the source resultset. How can I accomplish that?
27 replies
CC#
Created by Alex Frost on 4/13/2023 in #help
❔ Delayed call to a function
I am writing search in Blazor and the search needs to happen without enter or tab press. What I want is for a timer to be incremented on each key-press and once typing stops and delay is achieved, it should call the function. Few of the methods I tried call the search many times.
5 replies
CC#
Created by Alex Frost on 2/28/2023 in #help
❔ Adding OCR text to PDF file
I have PDF files with scanned pages. I want to keep source image without resizing it, performing OCR and adding OCR text to the file. What I have for now is, I use PdfSplitter which converts pages to images, upscaling them, then tesseract to OCR the images and construct a PDF file. Due to upscaling, the resulting file gains significant size and if OCR is performed multiple times due to un-desired results, the file keeps gaining size.
2 replies
CC#
Created by Alex Frost on 11/1/2022 in #help
Help with Implicit Explicit operators
This is my operator definition
public static implicit operator EventViewModel(Entry e)
{
EventViewModel viewModel = new EventViewModel();
viewModel.Id = e.Id;
viewModel.Title = e.Title;
viewModel.StartDate = e.DateStart;
viewModel.EndDate = e.DateEnd;
return viewModel;
}
public static implicit operator EventViewModel(Entry e)
{
EventViewModel viewModel = new EventViewModel();
viewModel.Id = e.Id;
viewModel.Title = e.Title;
viewModel.StartDate = e.DateStart;
viewModel.EndDate = e.DateEnd;
return viewModel;
}
I've not been able to find the exacts. With this definition, will it convert from Entry to ViewModel or ViewModel to Entry? Because, with the said implementation, following conversion doesn't work: EventData = Context.Entries.Where(e => e.UserId == UserId); The error is Can't convert from IQueryable<Entry> to IQueryable<ViewModel>
12 replies
CC#
Created by Alex Frost on 10/11/2022 in #help
Pass DateTime.Add function as parameter
I have a switch statement that will call a generation function so I don't have to loop for every scenario:
switch (E.RepMode)
{
case "daily":
repeats.Add(GenerateRepeats(entry.DateStart, entry.DateEnd, 1, DateTime.AddDays));
break;
case "weekly":
break;
case "monthly":
break;
case "yearly":
break;
}
switch (E.RepMode)
{
case "daily":
repeats.Add(GenerateRepeats(entry.DateStart, entry.DateEnd, 1, DateTime.AddDays));
break;
case "weekly":
break;
case "monthly":
break;
case "yearly":
break;
}
The function needs to be something like this:
public List<EntryRepeat> GenerateRepeats(DateTime start, DateTime end, int interval, Func<double, DateTime> f)
{
do
{

}
while (true);
}
public List<EntryRepeat> GenerateRepeats(DateTime start, DateTime end, int interval, Func<double, DateTime> f)
{
do
{

}
while (true);
}
However I'm not able to pass the function being non-static. Is there a way to achieve this or a better approach?
8 replies