示例#1
0
        private bool StoreProperty(IModeChoiceNode selectedMode, string parameterName, out FieldInfo field, out PropertyInfo property)
        {
            // Search for a field or property that has an attribute with this name
            field    = null;
            property = null;
            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)
                        {
                            property = f;
                            return(true);
                        }
                    }
                }
            }
            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)
                        {
                            field = f;
                            return(true);
                        }
                    }
                }
            }
            if (!IgnoreBadParameters)
            {
                // 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 " + selectedMode.ModeName);
            }
            return(false);
        }
示例#2
0
        protected virtual bool LinkModeParameter(ref string error)
        {
            IModeChoiceNode mode = this.Parent.Mode;

            this.AssignTo = this.Parent.Mode;
            if (mode == null)
            {
                error = "In '" + this.Parent.Name + "' it failed to present a mode for '" + this.Name + "'!";
                return(false);
            }
            var modeType      = mode.GetType();
            var parameterType = typeof(ParameterAttribute);

            foreach (var field in modeType.GetFields())
            {
                var attributes = field.GetCustomAttributes(parameterType, true);
                if (attributes != null)
                {
                    for (int i = 0; i < attributes.Length; i++)
                    {
                        if ((attributes[i] as ParameterAttribute).Name == this.ModeParameterName)
                        {
                            this.Field = field;
                            return(true);
                        }
                    }
                }
            }

            foreach (var field in modeType.GetProperties())
            {
                var attributes = field.GetCustomAttributes(parameterType, true);
                if (attributes != null)
                {
                    for (int i = 0; i < attributes.Length; i++)
                    {
                        if ((attributes[i] as ParameterAttribute).Name == this.ModeParameterName)
                        {
                            this.Property = field;
                            return(true);
                        }
                    }
                }
            }
            error = "We were unable to find a parameter in the mode '" + mode.ModeName + "' called '" + this.ModeParameterName + "'!";
            return(false);
        }
示例#3
0
 private bool StoreProperty(IModeChoiceNode selectedMode, string parameterName, out FieldInfo field, out PropertyInfo property)
 {
     // Search for a field or property that has an attribute with this name
     field = null;
     property = null;
     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 XTMF.ParameterAttribute ) ) != null )
             {
                 // Check to see if this is our parameter
                 if ( parameter.Name == parameterName )
                 {
                     property = f;
                     return true;
                 }
             }
         }
     }
     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 XTMF.ParameterAttribute ) ) != null )
             {
                 // Check to see if this is our parameter
                 if ( parameter.Name == parameterName )
                 {
                     field = f;
                     return true;
                 }
             }
         }
     }
     if ( !IgnoreBadParameters )
     {
         // 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 );
     }
     return false;
 }