T4MVC Keeps Generating Duplicate T4MVC.cs File (T4MVC1.cs)

Reference: Stack Overflow

Here’s the steps I do to fix it:

  • Delete T4MVC1.cs file.
  • Unload your project.
  • Edit the .csproj file.
  • Check the following tag:
    <Compile Include="T4MVC.cs">

    Make sure there’s only one of these and it’s T4MVC.cs. Remove T4MVC1.cs block if you have it.

  • Check the following tag:
    <None Include="">

    Make sure the is T4MVC.cs. If not, edit it to be T4MVC.cs.

  • Save the .csproj file.
  • Reload the project.
  • Rebuild
  • Make sure to check in that code so won’t cause any trouble in the future.


Leave a comment

Posted by on November 3, 2017 in General


C# Bit Shorthand

1 << 0; // Result is 1
1 << 1; // Result is 2
1 << 2; // Result is 4
1 << 3; // Result is 8

The way this works is, the binary value of first operand (the left) is shifted by number of bits of the second operand. Something like this:

1 is 00001 in binary which is 1 << 0
2 is 00010 in binary which is 1 << 1
3 is 00100 in binary which is 1 << 2
So on, so forth.

Another way to look at it is "adding X zero in the first operand's binary, where X is second operand.".

The kicker is that, second operand is only the first 5 bits (low-order five bits), means 00000 to 11111 (which is 31)

Reference: MSDN << Operator

Leave a comment

Posted by on October 28, 2017 in General



Change Azure Storage Emulator Database

By default, it’s going to: (localdb)\mssqllocaldb or other local database depends on SQL / SDK version installed. Check this link for more local database instances.

To change to use SQL instance:

The command:

C:\> AzureStorageEmulator.exe init /server <SQLServerInstance>


C:\> AzureStorageEmulator.exe init /server .\

Microsoft Azure

Leave a comment

Posted by on October 24, 2017 in General


Indexer-Supported Collection in C#

Indexer is a faster way to search a list / collection in C#, no looping is necessary.

Classes that support indexer:

  • Array []
  • List<T>
  • Dictionary<Key, Value>
  • ILookup<Key, Value>

Classes that don’t support indexer:

  • IEnumerable<T>
  • HashSet<T>
  • ICollection<T>

For classes that don’t support indexer, there’s ElementAt LINQ extension method.

Leave a comment

Posted by on September 28, 2017 in General


Tags: , ,

Why Must Extension Methods Be Declared in a Static Class?

Some possible answers:

  • The purpose of Extension Methods is to make LINQ work and LINQ only needs extension methods to be in a static, non-generic, non-nested class.
  • Easier for compiler to work with. Compiler and VS’s Intellisense can easily locate the methods.
  • Grouping the helper methods together.


Leave a comment

Posted by on September 20, 2017 in General


Tags: ,

Mocking Generic Method with NSubstitute

The generic method:

public interface ICacheService
    T Get<T>(string id);

User object in NSubstitute to mock the generic method.

private ICacheService MockICacheService()
    var service = Substitute.For<ICacheService>();

    // Return Models
    object returnForAny = null;

    // Mock

    return service;

Leave a comment

Posted by on September 13, 2017 in General


Tags: ,

Azure Storage Blob Listing Query with Search Pattern

Azure Storage blob is not behaving like files and folders in your local computer, albeit looking like one. So, there’s no support for search pattern, such as *.txt

The solution is to write your own search pattern.


public static String WildCardToRegular(String value) {
    return "^" + Regex.Escape(value).Replace("\\*", ".*") + "$";

Then, using it in Listing the blob:

var blobList = await container.ListBlobsSegmentedAsync(blobFilePath, true, BlobListingDetails.None, 1000, token, null, null);
var items = blobList.Results.Select(x => x as CloudBlockBlob);

// Filter items by search pattern, if specify
if (!string.IsNullOrEmpty(searchPattern))
    items = items.Select(i =>
        var filename = Path.GetFileName(i.Name);
        if (Regex.IsMatch(filename, WildCardToRegular(searchPattern), RegexOptions.IgnoreCase))
            return i;
	return null;

Leave a comment

Posted by on September 9, 2017 in General


Tags: ,

%d bloggers like this: