Esempio n. 1
0
        private static Tuple <List <Operation>, List <Field> > FakeSpec()
        {
            var operations = new List <Operation>();
            var fields     = new List <Field>();

            IReadOnlyDictionary <MacroOperationType, Tuple <ProtocolVersion, Type> > types = MacroOpManager.FindAll();

            foreach (var t in types)
            {
                MacroOperationType id = t.Key;
                Type type             = t.Value.Item2;

                IEnumerable <PropertyInfo> props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(prop => prop.GetCustomAttribute <NoSerializeAttribute>() == null);

                var opFields = new List <OperationField>();
                foreach (PropertyInfo prop in props)
                {
                    var fieldAttr = prop.GetCustomAttribute <MacroFieldAttribute>();
                    if (fieldAttr == null)
                    {
                        continue;
                    }


                    Tuple <string, bool> mappedType = TypeMappings.MapTypeFull(prop.PropertyType);
                    fields.Add(new Field(fieldAttr.Id, fieldAttr.Name, mappedType.Item1, mappedType.Item2, prop.PropertyType.GetCustomAttributes <FlagsAttribute>().Any() || prop.PropertyType.GetCustomAttributes <XmlAsStringAttribute>().Any()));

                    opFields.Add(new OperationField(fieldAttr.Id, fieldAttr.Name, prop.Name, prop.PropertyType.ToString()));
                }

                operations.Add(new Operation(id.ToString(), type.FullName, opFields, type.GetCustomAttributes <NoMacroFieldsAttribute>().Any()));
            }

            fields     = fields.Distinct().OrderBy(f => f.Id).ToList();
            operations = operations.OrderBy(o => o.Id).ToList();

            var res = new List <Field>();

            foreach (IGrouping <string, Field> grp in fields.GroupBy(f => f.Id))
            {
                FieldEntry[] newTypes = grp.SelectMany(g => g.Entries).ToArray();
                Field        f        = grp.First();
                res.Add(new Field(f.Id, newTypes, f.EnumAsString, f.IsEnum));
            }

            return(Tuple.Create(operations, res));
        }
Esempio n. 2
0
 private static T GetDefaultForField <T>(DeviceProfile profile, MacroOperationType op, MacroFieldSpec field)
 {
     return((T)AvailabilityChecker.GetMaxForProperty(profile, string.Format("{0}.{1}", op.ToString(), field.Name)));
 }