Archives

Archives / 2017 / July
  • Different types of views

    Hello everybody,

    today I want to write few words about different kinds of Views in .Net core.

    So, if you decide somehow to create new view you can see something like this:

    and now question. What is the difference between MVC View Page, MVC View Layout Page, MVC View Start Page and MVC View Imports page?

    So, if to draw the lines then following can be said. 

    MVC View Page is fitting for displaying different models.

    MVC View Layout Page is inteded as View that has @RenderBody() statement. RenderBody will be placeholder where MVC View Page will be rendered. 

    MVC View Start Page is used as mediator between MVC View Page and MVC View Layout page.

    The last puzzling view is MVC View … more

  • How to check if type in Assembly implements particular Interface

    Hello everybody,

    today I want to give sample of reading available types from dll .net assembly, check if at least one of them implements interface, and if implements then to create instance of that type and return it. 

    So, imagine you have such interface declaration in your code:

    public interface ILogger

        {

            /// <summary>

            /// Convert <see cref="LoggerMessage"/> to string based on the formats specified.

            /// </summary>

            /// <param name="message">The message to be converted.</param>

            /// <returns>Converted <paramref name="message"/>.</returns>

            LoggerMessage Handle(LoggerMessage message);

            bool Handlable(LoggerMessage message); … more

  • Concurent collections of C#

    Hello everybody,

    today I want to write few words about Concurent collections in C#. First of all  I want to point there there are only four of them:

    ConcurrentDictionary

    ConcurrentQueue

    ConcurrentStack

    ConcurrentBag

    BlockingCollection

    Partitioner

    EnumerablePartitionerOptions

    IProducerConsumerCollection

    OrderablePartitioner

    Not very impressive set of collections if to compare with diversity of other collections in .Net.

    Also keep in mind that ConcurrentQueue, ConcurrentStack and ConcurrentBag are not suitable for a lot of purposes. For example those last three do not allow direct access to any element in the collection which makes them unfitting for many goals. In practical … more

  • Features of System.Reflection

    Hello everybody,

    today I want to document few features of System.Reflection namespace.

    It has following important types:

    Type ( with methods GetType, GetMemberInfo, GetPropertyInfo, GetFieldInfo ), Activator ( with method CreateInstance ), Assembly ( Load, LoadFrom, GetTypes, GetName, GetFiles ), ILGenerator ( Emit ).

    Some code fragments for reflection

    var lst = new List<double>();

    Type listType = typeof(List<double>);

    Type[] pars = {typeof(double)};

    MethodInfo addMeth = listType.GetMethod("Add", pars);

    addMethod.Invoke(lst, new object[] {8.3});

    Create an isntace of type:

    public static Type GetType(string typeName)

    public static object CreateInstance(Type type)

    How to work with … more

  • New feature of C# that I've discovered

    Hello everybody,

    today I want to describe one new feature of C# that I discovered today. At MSDN it is named Type pattern. It looks like this:

    expr is type varname

    such code gives you to shorter your code.

    Take a look at the following code:

    using System;

    public class Student : IComparable

    {

    public String Course { get; set; }

    public int Id { get; set; }

    public int CompareTo(Object o)

    {

    if (o is Student)

    {

    e = o as Student; if(e == null) { throw new ArgumentException("some explanatory error message"); } return Course.CompareTo(e.Course);

    }

    throw … more