How to get fields and their values from a static class in referenced assembly

Using reflection, you will need to look for fields; these are not properties. As you can see from the following code, it looks for public static members: class Program { static void Main(string[] args) { Type t = typeof(A7); FieldInfo[] fields = t.GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo fi in fields) { Console.WriteLine(fi.Name); Console.WriteLine(fi.GetValue(null).ToString()); } Console.Read(); … Read more

Type conversion issue when setting property through reflection

Check full article : How to set value of a property using Reflection? full code if you are setting value for nullable type public static void SetValue(object inputObject, string propertyName, object propertyVal) { //find out the type Type type = inputObject.GetType(); //get the property information based on the type System.Reflection.PropertyInfo propertyInfo = type.GetProperty(propertyName); //find the … Read more

How to access unexported struct fields

If the struct is addressable, you can use unsafe.Pointer to access the field (read or write) it, like this: rs := reflect.ValueOf(&MyStruct).Elem() rf := rs.Field(n) // rf can’t be read or set. rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem() // Now rf can be read and set. See full example on the playground. This use of unsafe.Pointer is … Read more

What’s wrong with this reflection code? GetFields() is returning an empty array

The parameterless GetFields() returns public fields. If you want non-public ones, use: cc.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic); or whatever appropriate combination you want – but you do need to specify at least one of Instance and Static, otherwise it won’t find either. You can specify both, and indeed public fields as well, to get everything: cc.GetType().GetFields(BindingFlags.Instance | … Read more

Is there a way to get a type’s alias through reflection?

Nope – just create a Dictionary<Type,string> to map all of the types to their aliases. It’s a fixed set, so it’s not hard to do: private static readonly Dictionary<Type, string> Aliases = new Dictionary<Type, string>() { { typeof(byte), “byte” }, { typeof(sbyte), “sbyte” }, { typeof(short), “short” }, { typeof(ushort), “ushort” }, { typeof(int), “int” … Read more

Compile-time reflection in C++1z? [closed]

Reflection use cases are outlined in N3814: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3814.html The general view is that we will do it as an extension of the Type Traits library as exemplified by N3815: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3815.html There are two parts to reflection. The first is introspection. Taking an entity and querying constant values about it. The second is reification, which is … Read more

Create an Expression using reflection

The code to create the expression dynamically would be like this: ParameterExpression parameter = Expression.Parameter(typeof (GoalsModelUnitOfWork), “i”); MemberExpression property = Expression.Property(parameter, “AcademicCycles”); var queryableType = typeof (IQueryable<>).MakeGenericType(typeof (AcademicCycle)); var delegateType = typeof (Func<,>).MakeGenericType(typeof (GoalsModelUnitOfWork), queryableType); var yourExpression = Expression.Lambda(delegateType, property, parameter); The result will have the desired type, but the problem is that the return … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)