コード例 #1
0
        public PropertyMetadata MapUp(BaseProperty model)
        {
            PropertyMetadata propertyModel = new PropertyMetadata();

            propertyModel.Name = model.Name;
            Type         type         = model.GetType();
            PropertyInfo typeProperty = type.GetProperty("Type",
                                                         BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            BaseType typeModel = (BaseType)typeProperty?.GetValue(model);

            if (typeModel != null)
            {
                propertyModel.Type = TypeMapper.EmitType(typeModel);
            }

            return(propertyModel);
        }
コード例 #2
0
        public T GetPropertyByName <T>(string name, int index = 0)
        {
            BaseProperty prop = GetBasePropertyByName(name, index);

            if (prop == null)
            {
                return(default(T));
            }
            try
            {
                return((T)Convert.ChangeType(prop, typeof(T)));
            } catch (Exception ex)
            {
                string err = $"ERROR READING: Tried to read {prop.GetType().FullName} as {typeof(T).FullName} with name {name}:{index}!";
                Console.WriteLine(err);
                throw new Exception(err);
            }
        }
コード例 #3
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        protected virtual string GenerateResponseFileSwitches(CommandLineBuilder builder = default, HashSet <string> propertiesToIgnore = null)
        {
            builder ??= new CommandLineBuilder();

            propertiesToIgnore ??= new HashSet <string>();

            //
            // Generate a XAML rule based on [Switch...] attributes and any specified properties file.
            //

            Rule rule = new Rule();

            var parser = new CommandLineGenerator();

            if (SwitchAttributes?.Count > 0)
            {
                var attributeBasedProperties = SwitchAttributes.Select(attr => attr.Value.GetProperty());

                foreach (var property in attributeBasedProperties)
                {
                    rule.Properties.Add(property);

                    Log.LogMessage($"[{ToolName}] Added property from {GetType().Name}: {property.Name} | {property.GetType().Name}");
                }
            }

            if (PropertiesFile != null)
            {
                var xamlFileRule = CommandLineGenerator.LoadXamlRule(PropertiesFile);

                rule.Properties.AddRange(xamlFileRule.Properties);
            }

            //
            // Evaluate parameter types and values for each of those attributed with a [ToolSwitch...] variant.
            //

            var propertyValues = new Dictionary <string, object>();

            try
            {
                foreach (var attribute in SwitchAttributes)
                {
                    string name = attribute.Key;

                    BaseProperty property = attribute.Value.GetProperty();

                    object value = attribute.Value.GetValue();

                    propertyValues.Add(name, value);

                    Log.LogMessage($"[{ToolName}] Property from {GetType().Name}: {name} | {property.GetType().Name} | {(value == null ? "(null)" : $"{value} ({value.GetType()})")}");
                }

                if (OutOfDateInputFiles?.Length > 0)
                {
                    GenerateSwitchesForTaskItem(ref propertyValues, OutOfDateInputFiles[0], rule, propertiesToIgnore);
                }

                //
                // Validate required parameters are present.
                //

                foreach (var prop in rule.Properties)
                {
                    if (prop.IsRequired && !propertyValues.ContainsKey(prop.Name))
                    {
                        Log.LogError($"[{GetType().Name}] Required parameter {prop.Name} has no assigned property value.");
                    }
                }

                string commandLine = parser.GenerateCommandLine(rule, propertyValues, propertiesToIgnore);

                builder.AppendTextUnquoted(commandLine);
            }