private static void Main(string[] args) { // verify that things work OK without reflection access var permission = new ReflectionPermission(ReflectionPermissionFlag.AllFlags); permission.Deny(); Console.WriteLine("Direct access"); TestDirect(1, false); // for JIT etc TestDirect(Cycles, true); Console.WriteLine(); string typeName = typeof(HyperTypeDescriptionProvider).Name; Console.WriteLine("Without " + typeName); RunTests(1, 1, false); // for JIT etc RunTests(MetaCycles, Cycles, true); HyperTypeDescriptionProvider.Add(typeof(MyEntity)); Console.WriteLine(); Console.WriteLine("With " + typeName); RunTests(1, 1, false); // for Emit, JIT etc RunTests(MetaCycles, Cycles, true); Console.ReadLine(); }
static void Main() { HyperTypeDescriptionProvider.Add(typeof(Person)); var properties = new Dictionary<string, object> { { "Id", 10 }, { "Name", "Fred Flintstone" } }; Person person = new Person(); DynamicUpdate(person, properties); Console.WriteLine("Id: {0}; Name: {1}", person.Id, person.Name); Console.ReadKey(); }
public void GlobalSetupAttribute() { genarator = new FakeGenarator(); sampleRecords = Enumerable.Range(0, Program.iterations).Select(genarator.Generate).ToArray(); if (useHyperTypeDescriptionProvider) { HyperTypeDescriptionProvider.Add(typeof(FixedSampleRecord)); } }
private List <string> DumpToLabels(object inst, Type type) { List <StringBuilder> builders = new List <StringBuilder>(); builders.Add(new StringBuilder()); int row = 0; int column = 0; int rows = this.Height / 12 - 6; // Make it go FAST HyperTypeDescriptionProvider.Add(type); PropertyDescriptorCollection PropertyDescriptors = TypeDescriptor.GetProperties(type); PropertyInfo[] pic = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo pi in pic) { PropertyDescriptor fi = PropertyDescriptors[pi.Name]; object value = fi.GetValue(inst); string txt = ""; if (fi.PropertyType == typeof(double)) { txt = string.Format("{0} = {1} ", pi.Name, Math.Round((double)value, 3)); } else if (fi.PropertyType == typeof(float)) { txt = string.Format("{0} = {1} ", pi.Name, Math.Round((float)value, 3)); } else if (value != null) { txt = string.Format("{0} = {1} ", pi.Name, value.ToString()); } builders[column].AppendLine(txt); if (txt.Length > 30) { row++; // double rows } row++; // Go to next side. if (row == rows) { builders.Add(new StringBuilder()); column++; row = 0; } } return(builders.Select(x => x.ToString()).ToList()); }
public void BigDataWriteOperationShouldBeQuickWithReflectionMagic() { HyperTypeDescriptionProvider.Add(typeof(FixedSampleRecord)); BigDataWriteOperationShouldBeQuick(); }
public TelemetryLoggerSubscribedInstance(Type type, object instance) { this.type = type; this.instance = instance; RunFrequency = 100.0; HyperTypeDescriptionProvider.Add(type); Events = new Dictionary <string, List <List <string> > >(); LogOnChange = new Dictionary <string, bool>(); LogOnChangePreviousValue = new Dictionary <string, object>(); Mapping = new Dictionary <string, int>(); Frequencies = new Dictionary <string, double>(); FrequencyCounter = new Dictionary <string, int>(); // Fill things. int indexer = 0; double Frequency; PropertyDescriptors = TypeDescriptor.GetProperties(type); PropertyInfo[] pic = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo pi in pic) { PropertyDescriptor fi = PropertyDescriptors[pi.Name]; if (fi == null || fi.Attributes.Contains(new Unloggable())) { continue; } // ---------- Unloggable ---------- object[] attrs = pi.GetCustomAttributes(typeof(Unloggable), false); if (attrs.Length == 1)// is unloggable? { continue; } // ---------- Frequency ---------- attrs = pi.GetCustomAttributes(typeof(Loggable), false); if (attrs.Length == 1) { Frequency = ((Loggable)attrs[0]).Freqency; } else { Frequency = 100.0; // 100Hz normal } Frequencies.Add(fi.Name, Frequency); FrequencyCounter.Add(fi.Name, 0); // ---------- Log on change ---------- attrs = pi.GetCustomAttributes(typeof(LogOnChange), false); LogOnChange.Add(fi.Name, ((attrs.Length == 1) ? true : false)); LogOnChangePreviousValue.Add(fi.Name, null); // ---------- Events ---------- attrs = pi.GetCustomAttributes(typeof(LogOnEvent), false); Events.Add(fi.Name, new List <List <string> >()); if (attrs.Length > 0) { foreach (LogOnEvent logEvent in attrs) { Events[fi.Name].Add(logEvent.Events); } } // ---------- Mapping ---------- indexer++; Mapping.Add(fi.Name, indexer); } }