Time for action – creating a default value API
Follow the given steps:
- Create a Class Library project and call it
DefaultValues
. - Change the default name
Class1
and rename it toDefaultValueMap
. - Add the following code in the class:
public static class DefaultValueMap { public static Dictionary<string, object> DefaultValueMapping = null; /// <summary> /// Allows to add new default value at runtime. /// </summary> /// <param name="fullTypeName">Fully Qualified name of the object for which the default value is being set</param> /// <param name="value">The default value</param> public static void AddDefaultValue(string fullTypeName, object value) { if(!DefaultValueMapping.ContainsKey(fullTypeName)) DefaultValueMapping.Add(fullTypeName, value); } /// <summary> ...
Get .NET 4.0 Generics now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.