Contents tagged with Reflectoin

  • 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