I have SharePoint VisualWebPart where i try to reflect properties from instance object, but PropertyInfo array is empty, when i try the same on class its ok and i have all properties, all members are properties, not just fileds, all public. I tested it at home with console project and everything was fine, but at SharePoint it's not working. Here is example. What is the reason of that behavior?
class Program
{
public class Act
{
public string ID { get; set; }
public string Title {get;set;}
public string DestroyData {get;set;}
public string Count { get; set; }
}
static void Main(string[] args)
{
Act act = new Act();
Console.Write(act.GetType().GetProperties().Aggregate(new StringBuilder("Instance Properties - "), (s,c) => s.AppendFormat("{0}, ",c.Name) )); // <--- this is empty
Console.WriteLine();
Console.Write(typeof(Act).GetProperties().Aggregate(new StringBuilder("Class Properties - "), (s, c) => s.AppendFormat("{0}, ", c.Name))); // but this have all properties
Console.WriteLine();
Console.Write("act.GetType() == typeof(Act) - {0}", act.GetType() == typeof(Act)); // thats true
Console.ReadKey();
}
}
Aucun commentaire:
Enregistrer un commentaire