public class MyClass { public static Func<string, string> GetConfigValue = s => ConfigurationManager.AppSettings[s]; //… Normal use: string connectionString = MyClass.GetConfigValue(“myConfigValue”); Custom (e.g. Unit Testing) use: MyClass.GetConfigValue = s => s == “myConfigValue” ? “Hi”, “string.Empty”; The simplest form of configurable Dependency Injection Read more →
Month: July 2013
String to byte[]
public static byte[] ToByteArray(this string str) { UTF8Encoding encoding = new UTF8Encoding(); return encoding.GetBytes(str); } Read more →
VSTemplate
Template Parameters codeproject What a palaver you have to go through to get nested items from a VSTemplate. Read more →
How to make a custom dependent file in Visual Studio.
From this: To this: Open the .proj file Find the XML that defines these files <Compile Include=”Models\Context.cs” /> <Compile Include=”Models\Client.cs” /> <Compile Include=”Models\Image.cs” /> <Compile Include=”Models\Office.cs” /> <Compile Include=”Models\Policy.cs” /> and add DependentUpon tags <Compile Include=”Models\Context.cs” /> <Compile Include=”Models\Client.cs”> <DependentUpon>Context.cs</DependentUpon> </Compile> <Compile Include=”Models\Image.cs”> <DependentUpon>Context.cs</DependentUpon> </Compile> <Compile Include=”Models\Office.cs”> <DependentUpon>Context.cs</DependentUpon> </Compile> <Compile Include=”Models\Policy.cs”> <DependentUpon>Context.cs</DependentUpon> </Compile> Read more →