MMLib documentation

MMLib.Extensions

MMLib.Extensions is library, which contains extensions for standard .NET types. When you want use it, you must use using MMLib.Extensions; and use the concrete extension.
Example:
using MMLib.Extensions;

public void ExtensionsExample()
{
    string target = "aácčeéií";
    Assert.AreEqual("aacceeii", target.RemoveDiacritics());

    target = "123,354";
    Assert.IsTrue(target.IsNumber());

    target = "Very long sentence";
    Assert.AreEqual("Very long", target.Truncate(9));
} 

StringExtensions methods: MMLib.Extensions.StringExtensions
DateTimeExtensions methods: MMLib.Extensions.DateTimeExtensions
ObjectExtensions methods: MMLib.Extensions.ObjectExtensions

MMLib.RapidPrototyping

MMLib.RapidPrototyping nowadays contains helpfull random generators for prototyping new functions. Contains WordGenerator, PersonGenerator, LoremIpsumGenerator. It's easy to use it. You just define using, create instance and call Next method.
Example:
using MMLib.RapidPrototyping.Generators;

public void WordGeneratorExample()
{
    WordGenerator generator = new WordGenerator();
    var randomWord = generator.Next();

    Console.WriteLine(randomWord);
} 


Generators use own resources as repository. All words, names, lorem ipsum sentences are complied in the assembly. So it's easy to use it.
If you need your custom repository (you have own word's database, you want use special terminology, ...) you have options.
You can create yours custom repository class.
Example:
using MMLib.RapidPrototyping.Generators.Repositories;

public class ITWordRepository : IWordRepository
{
    private IList<string> _words = new List<string>();        
    public int Count
    {
        get { return _words.Count; }
    }

    public string this[int index]
    {
        get { return _words[index]; }
    }

    public ITWordRepository()
    {
        _words.Add("Computer");
        _words.Add("Mouse");
        _words.Add("Monitor");
        _words.Add("KeyBoard");
        _words.Add("Visual");
        _words.Add("Studio");
        _words.Add("Microsoft");
        _words.Add("Apple");
        _words.Add("Google");
        _words.Add("Facebook");
        _words.Add("Android");
    }
}


Now, you have to use it. You have two options how you can use it.
1. Directly through constructor
using MMLib.RapidPrototyping.Generators.Repositories;

public void WordGeneratorExample()
{
    WordGenerator generator = new WordGenerator(new ITWordRepository());
    var randomWord = generator.Next();

    Console.WriteLine(randomWord);
} 


2. With application config file
RapidPrototyping library use Unity as dependency injection container. Generators take repository from this container. So you can configurate Unity container in your application config file.
Example:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
  </configSections>
  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <container>
      <register type="MMLib.RapidPrototyping.Generators.Repositories.IWordRepository, MMLib.RapidPrototyping"
                mapTo="GeneratorsExtendedTest.Repositories.ITWordRepository, GeneratorsExtendedTest"  >
        <lifetime type="singleton" />
      </register>      
    </container>
  </unity>
</configuration>


You can use these principles for all generators (Word/Person/LoremIpsum)
You can dowload these examples here. https://mmlib.codeplex.com/releases/view/116172

Remarks
Every functionalities are covered by unit tests.
I use Code Contract from Microsoft to checking input arguments, if you want see this contract in popup comments use Code Contracts Editor Extensions VS2012 extension.

Last edited Jun 8, 2014 at 12:08 PM by MinoMartiniak, version 28