Exemplo n.º 1
0
        private string GetVariableName(string modeName, string parameterName)
        {
            ITashaMode selectedMode = null;

            foreach (var mode in AllModes)
            {
                if (mode.ModeName == modeName)
                {
                    selectedMode = mode;
                    break;
                }
            }
            if (selectedMode == null)
            {
                throw new XTMFRuntimeException(this, "We were unable to find a mode with the name " + modeName + " while trying to load the parameters to estimate!");
            }
            // Search for a field or property that has an attribute with this name
            var modeType = selectedMode.GetType();

            foreach (var f in modeType.GetProperties())
            {
                // search the attributes
                var attributes = f.GetCustomAttributes(true);
                foreach (var at in attributes)
                {
                    // if we find an attribute from XTMF
                    ParameterAttribute parameter;
                    if ((parameter = (at as ParameterAttribute)) != null)
                    {
                        // Check to see if this is our parameter
                        if (parameter.Name == parameterName)
                        {
                            return(f.Name);
                        }
                    }
                }
            }
            foreach (var f in modeType.GetFields())
            {
                // search the attributes
                var attributes = f.GetCustomAttributes(true);
                foreach (var at in attributes)
                {
                    // if we find an attribute from XTMF
                    ParameterAttribute parameter;
                    if ((parameter = (at as ParameterAttribute)) != null)
                    {
                        // Check to see if this is our parameter
                        if (parameter.Name == parameterName)
                        {
                            return(f.Name);
                        }
                    }
                }
            }
            // If we get here then we did not find it!
            throw new XTMFRuntimeException(this, "We were unable to find a parameter with the name \"" + parameterName + "\" in the mode " + modeName);
        }
        private void AssignParameter(ITashaMode mode, string parameter, float value)
        {
            parameter = GetVariableName(mode, parameter);
            Type modeType  = mode.GetType();
            var  fieldInfo = modeType.GetField(parameter);

            if (fieldInfo != null)
            {
                fieldInfo.SetValue(mode, value);
                return;
            }
            var propertyInfo = modeType.GetProperty(parameter);

            if (propertyInfo != null)
            {
                propertyInfo.SetValue(mode, value, null);
            }
        }
Exemplo n.º 3
0
 private string GetVariableName(ITashaMode selectedMode, string parameterName)
 {
     // Search for a field or property that has an attribute with this name
     var modeType = selectedMode.GetType();
     foreach(var f in modeType.GetProperties())
     {
         // search the attributes
         var attributes = f.GetCustomAttributes(true);
         foreach(var at in attributes)
         {
             // if we find an attribute from XTMF
             ParameterAttribute parameter;
             if((parameter = ((at as ParameterAttribute))) != null)
             {
                 // Check to see if this is our parameter
                 if(parameter.Name == parameterName)
                 {
                     return f.Name;
                 }
             }
         }
     }
     foreach(var f in modeType.GetFields())
     {
         // search the attributes
         var attributes = f.GetCustomAttributes(true);
         foreach(var at in attributes)
         {
             // if we find an attribute from XTMF
             ParameterAttribute parameter;
             if((parameter = ((at as ParameterAttribute))) != null)
             {
                 // Check to see if this is our parameter
                 if(parameter.Name == parameterName)
                 {
                     return f.Name;
                 }
             }
         }
     }
     // If we get here then we did not find it!
     throw new XTMFRuntimeException("We were unable to find a parameter with the name \"" + parameterName + "\" in the mode " + selectedMode.ModeName);
 }