SGScript.IObjectBase.FindParserForType C# (CSharp) Method

FindParserForType() public static method

public static FindParserForType ( Type type, string typeType = null, string methodName = null ) : MethodInfo
type System.Type
typeType string
methodName string
return System.Reflection.MethodInfo
        public static MethodInfo FindParserForType( Type type, string typeType = null, string methodName = null )
        {
            foreach( MethodInfo method in typeof(Context).GetMethods() )
            {
                if( method.Name != "ParseVar" )
                    continue;
                ParameterInfo[] prms = method.GetParameters();

                // expected signature: public void ParseVar( out T value, Variable var );
                if( prms.Length != 2 || prms[0].IsOut == false || prms[0].ParameterType.IsByRef == false || prms[1].ParameterType != typeof(Variable) )
                    continue; // unrecognized signature

                // ParameterType is T&
                Type paramType = prms[0].ParameterType.GetElementType();
                if( paramType != type && !type.IsSubclassOf( paramType ) )
                    continue; // type does not match
            //	Console.WriteLine(type +" > " + paramType);

                // a good conversion method has been found
                return method;
            }
            if( typeType != null && methodName != null )
                throw new SGSException( RC.ENOTFND, string.Format( "Could not find a Context.ParseVar method for '{2}' {1} type={0}", type, typeType, methodName ) );
            return null;
        }