ایجاد Collapsing Logo Effect
معرفی سایت VSCodeThemes
Announcing VSCodeThemes
Preview themes from the VSCode marketplace.
About 5 months ago I posted a side project to r/vscode that got relatively popular, and since then I’ve been working on making it useful.
ایجاد فایل PDF در #C
The PDF File Writer C# class library PdfFileWriter allows you to create PDF files directly from your .net application.
Most TrueType fonts such as Arial supports character values greater than 255. The PDF File Library allows you to perform a substitution. You can use any Unicode character and map it into the available one byte range.
پیاده سازی UnitOfWork به وسیله MEF
کلاس کانتکسهای من
public class VegaContext : DbContext, IUnitOfWork, IDbContext { #region Constructors (2) /// <summary> /// Initializes the <see cref="VegaContext" /> class. /// </summary> static VegaContext() { Database.SetInitializer<VegaContext>(null); } /// <summary> /// Initializes a new instance of the <see cref="VegaContext" /> class. /// </summary> public VegaContext() : base("LocalSqlServer") { } #endregion Constructors #region Properties (2) /// <summary> /// Gets or sets the languages. /// </summary> /// <value> /// The languages. /// </value> public DbSet<Language> Languages { get; set; } /// <summary> /// Gets or sets the resources. /// </summary> /// <value> /// The resources. /// </value> public DbSet<Resource> Resources { get; set; } #endregion Properties #region Methods (2) // Public Methods (1) /// <summary> /// Setups the specified model builder. /// </summary> /// <param name="modelBuilder">The model builder.</param> public void Setup(DbModelBuilder modelBuilder) { //todo modelBuilder.Configurations.Add(new ResourceMap()); modelBuilder.Configurations.Add(new LanguageMap()); modelBuilder.Entity<Resource>().ToTable("Vega_Languages_Resources"); modelBuilder.Entity<Language>().ToTable("Vega_Languages_Languages"); //base.OnModelCreating(modelBuilder); } // Protected Methods (1) /// <summary> /// This method is called when the model for a derived context has been initialized, but /// before the model has been locked down and used to initialize the context. The default /// implementation of this method does nothing, but it can be overridden in a derived class /// such that the model can be further configured before it is locked down. /// </summary> /// <param name="modelBuilder">The builder that defines the model for the context being created.</param> /// <remarks> /// Typically, this method is called only once when the first instance of a derived context /// is created. The model for that context is then cached and is for all further instances of /// the context in the app domain. This caching can be disabled by setting the ModelCaching /// property on the given ModelBuidler, but note that this can seriously degrade performance. /// More control over caching is provided through use of the DbModelBuilder and DbContextFactory /// classes directly. /// </remarks> protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new ResourceMap()); modelBuilder.Configurations.Add(new LanguageMap()); modelBuilder.Entity<Resource>().ToTable("Vega_Languages_Resources"); modelBuilder.Entity<Language>().ToTable("Vega_Languages_Languages"); base.OnModelCreating(modelBuilder); } #endregion Methods #region IUnitOfWork Members /// <summary> /// Sets this instance. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <returns></returns> public new IDbSet<TEntity> Set<TEntity>() where TEntity : class { return base.Set<TEntity>(); } #endregion }
در طرف دیگر برای لود کردن کلاس زیر نوشتم
public class LoadContexts { public LoadContexts() { var directoryPath = HttpRuntime.BinDirectory;//AppDomain.CurrentDomain.BaseDirectory; //"Dll folder path"; var directoryCatalog = new DirectoryCatalog(directoryPath, "*.dll"); var aggregateCatalog = new AggregateCatalog(); aggregateCatalog.Catalogs.Add(directoryCatalog); var container = new CompositionContainer(aggregateCatalog); container.ComposeParts(this); } //[Import] //public IPlugin Plugin { get; set; } [ImportMany] public IEnumerable<IDbContext> Contexts { get; set; } }
public class MainContext : DbContext, IUnitOfWork { public MainContext() : base("LocalSqlServer") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); var contextList = new LoadContexts(); //ObjectFactory.GetAllInstances<IDbContext>(); foreach (var context in contextList.Contexts) context.Setup(modelBuilder); Database.SetInitializer(new MigrateDatabaseToLatestVersion<MainContext, Configuration>()); //Database.SetInitializer(new DropCreateDatabaseAlways<MainContext>()); } /// <summary> /// Sets this instance. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <returns></returns> public IDbSet<TEntity> Set<TEntity>() where TEntity : class { return base.Set<TEntity>(); } }
enum USState {...} var AreaCodeUSState = new Dictionary<string, USState> { {"408", USState.California}, {"701", USState.NorthDakota}, ... };
اکنون در C# 6.0 ما میتوانیم از Index Initializer استفاده کنیم:
enum USState {...} var AreaCodeUSState = new Dictionary<string, USState> { ["408"] = USState.California, ["701"] = USState.NorthDakota, ... };
شبه کد مثال بالا به صورت زیر میشود:
Collection Initializer
create a Dictionary<string, USState> add to new Dictionary the following items: "408", USState.California "701", USState.NorthDakota
create a Dictionary<string, USState> then using AreaCodeUSState's default Indexed property set the Value of Key "408" to USState.California set the Value of Key "701" to USState.NorthDakota
Collection Initializer
enum USState {...} var AreaCodeUSState = new Dictionary<string, USState> { { "408", USState.Confusion}, { "701", USState.NorthDakota }, { "408", USState.California}, ... }; Console.WriteLine( AreaCodeUSState.Where(x => x.Key == "408").FirstOrDefault().Value );
enum USState {...} var AreaCodeUSState = new Dictionary<string, USState> { ["408"] = USState.Confusion, ["701"] = USState.NorthDakota, ["408"] = USState.California, ... }; Console.WriteLine( AreaCodeUSState2.Where(x => x.Key == "408").FirstOrDefault().Value ); // output = California
اما در زمان اجرا، Index Initializer به صورت کامل و بدون خطا این کار را انجام میدهد و در کلید "408" مقدار USState.Confusion قرار میگیرد. سپس "701" مقدار USState.NorthDakota و بعد از استفادهی مجدد از کلید "408" مقدار USState.California جایگزین مقدار قبلی میشود.
var fibonaccis = new List<int> { [0] = 1, [1] = 2, [3] = 5, [5] = 13 }
تلاش برای تخصیص مقدار 1 با کلید 0 به <List<int، سبب بروز استثناء ArguementOutOfRangeException می شود. وقتی (List<T>.Add(item فراخوانی میشود اندازهی لیست یک واحد افزایش مییابد. بنابراین باید دقت داشت که Index Initializer از ()Add. استفاده نمیکند؛ در عوض با استفاده از خصوصیت اندیس پیش فرض، مقداری را برای یک کلید تعیین میکند.
برای چنین حالتی بهتر است از همان روش قدیمی Collection Initializer استفاده کنیم:
var fibonaccis = new List<int>() { 1, 3, 5, 13 };
Overlay is a browser extension that helps developers evaluate open source packages before picking them. It gathers data from various sources, such as Snyk Advisor, Debricked, Socket.dev, and Deps.dev, and displays them on the package pages of popular registries like npm, PyPI, and Go.
آغاز کار با git در ویژوال استدیو
In this episode, Robert is joined by Paul Litwin, who shows us how to get started with Git in under an hour. Git is a free, open source and quite popular distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Starting with the command line and ending up in both VS Code and Visual Studio, Paul takes us on a tour of the how you can use Git to manage your source code.