Download Logo

Seed SQLite

Required NuGet Packages Create .ipynb file 1 2 3 #r "nuget: Faker.Net, 2.0.163" #r "nuget:SkiaSharp, 3.116.1" #r "nuget: System.Data.SQLite.Core, 1.0.119" Importing namespace 1 2 3 4 5 6 7 using Faker; using System.IO; using SkiaSharp; using System; using System.Collections.Generic; using System.Reflection; using System.Data.SQLite; Create Class 1 2 3 4 5 6 7 8 9 10 11 public class Book { public int Id { get; set; } public string Title { get; set; } public string Author { get; set; } public byte[] Image { get; set; } public decimal Price { get; set; } public string Description { get; set; } public DateTime PublishDate { get; set; } public string Category { get; set; } } Bunch of Color for random background color 1 2 3 4 5 6 7 8 9 10 11 12 var listOfColor = new List<SKColor> { SKColor.Parse("#86B6F6"), SKColor.Parse("#176B87"), SKColor.Parse("#00A9FF"), SKColor.Parse("#FF90BC"), SKColor.Parse("#8ACDD7"), SKColor.Parse("#F2AFEF"), SKColor.Parse("#C499F3"), SKColor.Parse("#33186B"), }; Sqlite Database File Location 1 var connectionString = @"Data Source=C:\Users\91746\source\repos\Shopping\Shopping\BookStore.db"; This will Generate Data for Cover Image Dynamically 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 byte[] Generate<T>(T book) { int width = 480; int height = 540; int marginY = -10; int marginX = -10; string mainText =Faker.Name.First(); //book.Title; string subText = Faker.Name.Last(); string backGroundColor =listOfColor[Faker.RandomNumber.Next(0,listOfColor.Count()-1)].ToString(); string textColor = "#ffffff"; string boderColor = "#ffffff"; SKBitmap bmp = new(width, height); SKCanvas canvas = new(bmp); canvas.Clear(SKColor.Parse(backGroundColor)); using (var paint = new SKPaint()) { paint.TextSize = width/ 10.0f; paint.IsAntialias = true; paint.Color = SKColor.Parse(textColor); paint.IsStroke = false; paint.StrokeWidth = 3; paint.TextAlign = SKTextAlign.Center; canvas.DrawText(mainText, width / 2f, height / 2f, paint); paint.TextSize = width/ 25.0f; paint.TextAlign = SKTextAlign.Right; canvas.DrawText(subText, width+marginX, height+marginY, paint); paint.TextSize = width/ 20.0f; paint.IsStroke = true; paint.TextAlign = SKTextAlign.Center; paint.Color = SKColor.Parse(textColor); } //SKFileWStream fs = new($"Images/{book.Title}.jpg"); //bmp.Encode(fs, SKEncodedImageFormat.Jpeg, quality: 50); bmp.Encode(SKEncodedImageFormat.Jpeg,100); using (MemoryStream ms = new MemoryStream()) { bmp.Encode(ms, SKEncodedImageFormat.Jpeg, 100); return ms.ToArray(); } return bmp.Bytes; } Using Reflection For Auto filling Data To Proprties 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 T GetObjectOf<T>() { Type objectType = typeof(T); object objectObject = Activator.CreateInstance(objectType); // Get the properties of the Book class PropertyInfo[] properties = objectType.GetProperties(); // Use Faker.NET to populate the properties dynamically foreach (var property in properties) { // Skip the 'Id' property as it's usually auto-generated if (property.Name == "Id") continue; // Create fake data based on the property type if (property.PropertyType == typeof(string)) { property.SetValue(objectObject, Faker.Name.FullName()); } else if (property.PropertyType == typeof(int)) { // Assign a random integer property.SetValue(objectObject, Faker.RandomNumber.Next()); } else if (property.PropertyType == typeof(decimal)) { // Assign a random decimal value property.SetValue(objectObject, (decimal)(Faker.RandomNumber.Next(01,1000) )); } else if (property.PropertyType == typeof(DateTime)) { // Assign a random past date property.SetValue(objectObject, DateTime.Now.AddMonths(Faker.RandomNumber.Next(1,100))); } else if (property.PropertyType == typeof(byte[])) { // Assign a random byte array (representing an image or file) property.SetValue(objectObject, Generate((T)objectObject)); } else if (property.PropertyType == typeof(System.Enum)) { // For enum types, assign a random enum value if the property is of enum type Array enumValues = property.PropertyType.GetEnumValues(); var randomEnumValue = enumValues.GetValue(Faker.RandomNumber.Next(0, enumValues.Length)); property.SetValue(objectObject, randomEnumValue); } } return (T)objectObject; } Generate Bunch Of Book Will bw used to insert to database 1 2 3 4 5 6 7 8 9 10 List<T> GeBook<T>() { var ls = new List<T>(); for(var i=0;i<50;i++) { var newBook = GetObjectOf<T>(); ls.Add(newBook); } return ls; } Dynamically Creating SqlQuery string Using Reflection 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 public void InsertBook<T>(T entity, string queryString) { string insertQuery = queryString; try { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { conn.Open(); using (SQLiteCommand cmd = new SQLiteCommand(insertQuery, conn)) { Type type = typeof(T); // Get all properties of the Book class using Reflection PropertyInfo[] properties = type.GetProperties(); foreach (var property in properties) { // Get the name of the property string propertyName = property.Name; object propertyValue = property.GetValue(entity); cmd.Parameters.AddWithValue($"@{propertyName}", propertyValue); } var num = cmd.ExecuteNonQuery(); } } catch(Exception ex) { Console.WriteLine(ex.Message); } } } catch(Exception ex) { Console.WriteLine(ex.Message); } } Here data is inserted to database 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 string InsertCommandStringGenerator<T>() { Type bookType = typeof(T); // Get all the properties of the Book class PropertyInfo[] properties = bookType.GetProperties(); // Initialize StringBuilder to construct the SQL query StringBuilder insertQuery = new StringBuilder(); // Start building the SQL query insertQuery.AppendLine("INSERT INTO Books ("); // Loop through the properties to add column names for (int i = 0; i < properties.Length; i++) { if(properties[i].Name.ToLower()=="id") continue; insertQuery.Append(properties[i].Name); if (i < properties.Length - 1) { insertQuery.Append(", "); } } insertQuery.AppendLine(") VALUES ("); // Loop through the properties again to add parameter placeholders for (int i = 0; i < properties.Length; i++) { if(properties[i].Name.ToLower()=="id") continue; insertQuery.Append("@"); insertQuery.Append(properties[i].Name); if (i < properties.Length - 1) { insertQuery.Append(", "); } } insertQuery.AppendLine(");"); return insertQuery.ToString(); } Final Command To populate all above 1 2 3 4 5 var queryString = InsertCommandStringGenerator<Book>(); foreach(var item in GeBook<Book>()) { InsertBook(item,queryString); }

January 1, 2025 · 5 min · 937 words · PrashantUnity
Download Logo

Spot-check: are you ready?

Q1. What is C#? What is the difference between C# and .NET? C# (C-Sharp) is a modern, object-oriented programming language developed by Microsoft. It is part of the .NET framework and is used for developing a wide range of applications, from web and mobile apps to desktop applications. .NET is a framework developed by Microsoft that provides a comprehensive platform for building and running applications. It includes a runtime environment (CLR), a large class library, and support for various programming languages, including C#, VB.NET, and F#. ...

August 3, 2024 · 127 min · 26990 words · PrashantUnity
Download Logo

YouTube API updates

YouTube Data API Sample in .NET Interactive Notebooks This sample demonstrates how to use the YouTube Data API to update video metadata (title, description, tags, etc.) in bulk using .NET Interactive Notebooks. It covers OAuth2 authentication, fetching uploaded videos, generating new metadata using an AI model, and updating the videos via the API. Get Gemini API Key Google Cloud Console for creating secret credentials 1 2 #r "nuget: Google.Apis.YouTube.v3" #r "nuget: Google.Apis.Auth" This cell loads the NuGet package references required to use the YouTube Data API and Google authentication in a polyglot/.NET Interactive notebook. ...

December 23, 2025 · 5 min · 978 words · PrashantUnity
Download Logo

QR codes in .NET

Generate QR Code in .NET Applications This comprehensive guide demonstrates how to create beautiful, customizable QR codes in .NET applications. We’ll build a QR code generator with advanced features including: Gradient coloring - Apply color gradients to QR code modules Rounded dots - Replace standard squares with rounded circles for a modern look Center logo - Embed logos with automatic sizing and contrast enhancement Footer text - Add descriptive text below the QR code UPI payment integration - Generate UPI URIs for Indian payment systems High error correction - Ensure QR codes remain scannable even with partial obstruction Base64 encoding - Easy embedding in web applications and documents Prerequisites You’ll need: ...

November 16, 2025 · 11 min · 2319 words · PrashantUnity
Download Logo

Auto carousel in MAUI

## 1. Create the Reusable Component Files 🧱 First, add a new item to your project. Choose the .NET MAUI ContentView (XAML) template. Name it something descriptive, like FeaturedCarouselView.xaml. ## 2. UI code sample of the ContentView FeaturedCarouselView.xaml: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 <?xml version="1.0" encoding="utf-8" ?> <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:YourMauiProjectName" x:Class="YourMauiProjectName.FeaturedCarouselView"> <ContentView.Resources> <ResourceDictionary> <Color x:Key="CardBackgroundColor">#F9FAFB</Color> <Color x:Key="ForegroundColor">#111827</Color> <Color x:Key="MutedForegroundColor">#6B7280</Color> <Color x:Key="BorderColor">#E5E7EB</Color> <Color x:Key="PrimaryColor">#4A90E2</Color> <Style x:Key="CardBorderStyle" TargetType="Border"> <Setter Property="Stroke" Value="{StaticResource BorderColor}" /> <Setter Property="StrokeThickness" Value="1" /> <Setter Property="BackgroundColor" Value="{StaticResource PageBackgroundColor}" /> <Setter Property="StrokeShape" Value="RoundRectangle 8" /> <Setter Property="Padding" Value="0" /> <Setter Property="Shadow"> <Shadow Brush="Black" Offset="2,2" Radius="5" Opacity="0.1" /> </Setter> </Style> <Style x:Key="PrimaryButtonStyle" TargetType="Button"> <Setter Property="BackgroundColor" Value="{StaticResource PrimaryColor}" /> <Setter Property="TextColor" Value="{StaticResource PrimaryTextColor}" /> <Setter Property="FontAttributes" Value="Bold" /> <Setter Property="HeightRequest" Value="48" /> <Setter Property="CornerRadius" Value="8" /> <Setter Property="Padding" Value="24,0" /> </Style> </ResourceDictionary> </ContentView.Resources> <VerticalStackLayout Spacing="16" BackgroundColor="{StaticResource CardBackgroundColor}"> <CarouselView x:Name="FeaturedCarousel" IndicatorView="FeaturedIndicator" HeightRequest="500"> <CarouselView.ItemTemplate> <DataTemplate x:DataType="local:CarouselItem"> <VerticalStackLayout Padding="16,0" Spacing="24"> <Border Style="{StaticResource CardBorderStyle}" StrokeShape="RoundRectangle 12" HeightRequest="300"> <Image Source="{Binding ImageUrl}" Aspect="AspectFill" /> </Border> <VerticalStackLayout Spacing="16" HorizontalOptions="Center" Padding="16,0"> <Label Text="{Binding Title}" TextColor="{StaticResource ForegroundColor}" FontSize="24" FontAttributes="Bold" HorizontalTextAlignment="Center" /> <Label Text="{Binding Description}" TextColor="{StaticResource MutedForegroundColor}" FontSize="16" HorizontalTextAlignment="Center" /> <Button Text="Discover More →" Style="{StaticResource PrimaryButtonStyle}" HorizontalOptions="Center" /> </VerticalStackLayout> </VerticalStackLayout> </DataTemplate> </CarouselView.ItemTemplate> </CarouselView> <IndicatorView x:Name="FeaturedIndicator" IndicatorColor="{StaticResource BorderColor}" SelectedIndicatorColor="{StaticResource PrimaryColor}" HorizontalOptions="Center" Margin="0,0,0,16"/> </VerticalStackLayout> </ContentView> ## 3. Logic to the Component’s Code-Behind Important: We use the Loaded and Unloaded events to start and stop the timer. ...

June 23, 2025 · 3 min · 523 words · PrashantUnity
Download Logo

Entry without underline

Create Custom Entry Control 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 namespace WaterReminder.CFDControl; public class CfdEntry :Entry { protected override void OnHandlerChanged() { base.OnHandlerChanged(); SetBorderlessBackground(); } protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) { base.OnPropertyChanged(propertyName); if (propertyName == nameof(BackgroundColor)) { SetBorderlessBackground(); } } private void SetBorderlessBackground() { #if ANDROID if (Handler is IEntryHandler entryHandler) { if (BackgroundColor == null) { entryHandler.PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToPlatform()); } else { entryHandler.PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(BackgroundColor.ToPlatform()); } } #endif } } Step uses Import Name Spaces. in Xaml and so on … ...

June 19, 2025 · 2 min · 253 words · PrashantUnity
Download Logo

Floating action button

Code Snippet 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <AbsoluteLayout> <Grid AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" > <Grid> <Border StrokeShape="RoundRectangle 30" HeightRequest="60" WidthRequest="60" BackgroundColor="Black" AbsoluteLayout.LayoutBounds="1, 1, AutoSize, AutoSize" AbsoluteLayout.LayoutFlags="PositionProportional" TranslationX="-30" TranslationY="-30" > <Border.GestureRecognizers> <TapGestureRecognizer Tapped="AddButton_Clicked" /> </Border.GestureRecognizers> <Label Text="➕" TextColor="White" VerticalOptions="Center" HorizontalOptions="Center" FontSize="25"/> </Border> </AbsoluteLayout>

June 19, 2025 · 1 min · 60 words · PrashantUnity
Download Logo

SQLite in MAUI

Implementation Steps Install/ Add Microsoft.EntityFrameworkCore.Sqlite to Project 1 <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.7" /> Register App db Context before var app = builder.Build(); in MauiProgram.cs 1 2 3 var dbPath = Path.Combine(FileSystem.AppDataDirectory, "waterreminder.db3"); builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlite($"Filename={dbPath}")); Just Before app run add this Command 1 2 3 4 5 6 7 8 // Initialize the database using (var scope = app.Services.CreateScope()) { var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>(); dbContext.Database.EnsureCreated(); } return app; Create Add Db Context 1 2 3 4 5 6 namespace WaterReminder.Data; public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options) { public DbSet<Reminder> Reminders { get; set; } } Below is service or uses 1 2 3 4 5 6 7 8 9 10 11 public class ReminderService : IReminderService { private readonly AppDbContext _context; public ReminderService(AppDbContext context) { _context = context; } public Task<List<Reminder>> GetRemindersAsync() => _context.Reminders.ToListAsync(); }

June 19, 2025 · 1 min · 134 words · PrashantUnity
Download Logo

Giscus in Blazor

Giscus Script Configuration Be sure To Change Parameter value Based on you Generation from here https://giscus.app/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <script src="https://giscus.app/client.js" data-repo="PrashantUnity/GettingStarted" data-repo-id="R_kgDOKzC5Hw" data-category="General" data-category-id="DIC_kwDOKzC5H84CdPDh" data-mapping="specific" data-term=" GettingStarted Discussions" data-strict="0" data-reactions-enabled="1" data-emit-metadata="0" data-input-position="top" data-theme="light" data-lang="en" data-loading="lazy" crossorigin="anonymous" async> </script> Above Code is Coverted to be usable in Blazor 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 @using Microsoft.AspNetCore.Components @if (Script != null) { <div> @Script </div> } @code { #region Parameter // change only commented section [Parameter] public string InputPosition { get; set; } = "top"; [Parameter] public string Term { get; set; } = "GettingStarted Discussions"; // name anything it will create one one discussion based on name [Parameter] public string Repo { get; set; } = "PrashantUnity/GettingStarted"; // your repository name [Parameter] public string RepoId { get; set; } = "R_kgDOKzC5Hw"; // this is generated by giscus website only one time creation required for one repo #endregion public string Category { get; set; } = "General"; public string CategoryId { get; set; } = "DIC_kwDOKzC5H84CdPDh"; // this is generateeed by giscus website only one time creation required for one repo public string Mapping { get; set; } = "specific"; public bool ReactionsEnabled { get; set; } = true; public string Theme { get; set; } = "light"; public string Language { get; set; } = "en"; public string Loading { get; set; } = "lazy"; public string EmitMetadata { get; set; } = "0"; public string Strict { get; set; } = "0"; private RenderFragment Script { get; set; } protected override void OnParametersSet() { Script = new RenderFragment(b => { b.OpenElement(0, "script"); b.AddMultipleAttributes(1, new List<KeyValuePair<string, object>>() { new KeyValuePair<string, object>("src", "https://giscus.app/client.js"), new KeyValuePair<string, object>("data-repo", Repo), new KeyValuePair<string, object>("data-repo-id", RepoId), new KeyValuePair<string, object>("data-category", Category), new KeyValuePair<string, object>("data-category-id", CategoryId), new KeyValuePair<string, object>("data-mapping", Mapping), new KeyValuePair<string, object>("data-term", Term), new KeyValuePair<string, object>("data-strict", Strict), new KeyValuePair<string, object>("data-reactions-enabled", ReactionsEnabled ? "1" : "0"), new KeyValuePair<string, object>("data-emit-metadata", EmitMetadata), new KeyValuePair<string, object>("data-input-position", InputPosition), new KeyValuePair<string, object>("data-theme", Theme), new KeyValuePair<string, object>("data-lang", Language), new KeyValuePair<string, object>("data-loading", Loading), new KeyValuePair<string, object>("crossorigin", "anonymous"), new KeyValuePair<string, object>("async", true), }); b.CloseElement(); }); } } Uses 1 <GiscusIntegration />

July 12, 2024 · 2 min · 417 words · PrashantUnity
Download Logo

Java interview prep

Collections Framework Deep Dive 1️⃣ Why does HashMap allow one null key but Hashtable doesn’t? Short Answer: HashMap was designed for modern multi-threaded applications with null-safe design; Hashtable predates this and was optimized for thread-safety by rejecting nulls outright. Detailed Explanation: Hashtable uses the hashCode() method on every key. If you pass null, it throws a NullPointerException immediately—no comparison, no storage. This is intentional: it forces you to know your data upfront. ...

November 12, 2025 · 38 min · 7889 words · Aayush Bhardwaj