0

I have a model :

public class Message
{
    public string CustomerName { get; set; }
    public DateTime Date { get; set; }
    public string RegistrationCode { get; set; }
}

I want get its properties dynamically, in the previous version of .Net we do it by : obj.GetType().GetProperties(); but in .Net Core we haven't .GetProperties(), How can i do it?

Christos
  • 53,228
  • 8
  • 76
  • 108
pmn
  • 2,176
  • 6
  • 29
  • 56

1 Answers1

0

You have probably missed to add the following using statement:

using System.Reflection;

I tried to run the following console application (I don't think that you will notice any difference in a asp.net core project):

using System;
using System.Reflection;

namespace ConsoleApp1
{
    public class Message
    {
        public string CustomerName { get; set; }
        public DateTime Date { get; set; }
        public string RegistrationCode { get; set; }
    }

    public class Program
    {
        public static void Main(string[] args)
        {
            var obj = new Message();
            var properties = obj.GetType().GetProperties();
            Console.ReadKey();
        }
    }
}

and I din't notice any issue. Below is the project.json for reference:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.1"
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

Are you sure that you use the latest .net core version?

Christos
  • 53,228
  • 8
  • 76
  • 108