Example #1
0
 // Resets all settable fields back to default, and sets the ones that are included in the item args
 //  If the parse from the content project string fails, then the field takes on its default value
 public void UpdateFields(BuildEngine engine, BuildEvent evt)
 {
     foreach (var field in Type.Fields)
     {
         var idx = evt.Item.ProcessorArgs.FindIndex(arg => arg.Key == field.ParamName);
         if (idx == -1)
         {
             field.Info.SetValue(Instance, field.DefaultValue);
         }
         else
         {
             if (ConverterCache.Convert(field.FieldType, evt.Item.ProcessorArgs[idx].Value, out object parsed))
             {
                 field.Info.SetValue(Instance, parsed);
             }
             else
             {
                 engine.Logger.EngineError($"The content item '{evt.Item.ItemPath}' specified an invalid value for the parameter" +
                                           $" '{field.ParamName}'.");
                 field.Info.SetValue(Instance, field.DefaultValue);
             }
         }
     }
 }
Example #2
0
        // This is guarenteed to already a valid ContentProcessor type
        public static ProcessorField[] LoadFromType(BuildEngine engine, Type type)
        {
            var valInst = Activator.CreateInstance(type);             // Used to get the default values for all of the fields

            return(type
                   .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                   .Select(f => (field: f, attrib: (PipelineParameterAttribute)f.GetCustomAttribute(ATTRIBUTE_TYPE, false)))
                   .Where(f => f.attrib != null)
                   .Where(f => {
                if (f.field.IsInitOnly)
                {
                    engine.Logger.EngineWarn($"The ContentProcessor type '{type.Name}' cannot have a readonly pipeline parameter ({f.field.Name}).");
                    return false;
                }
                if (!ConverterCache.CanConvert(f.field.FieldType))
                {
                    engine.Logger.EngineWarn($"The ContentProcessor type '{type.Name}' declared the pipeline parameter '{f.field.Name}' with an invalid type.");
                    return false;
                }
                return true;
            })
                   .Select(f => new ProcessorField(f.field, f.attrib, f.field.GetValue(valInst)))
                   .ToArray());
        }