결국 arguments의 length 속성을 이용한다.

val: function( value ) {

var hooks, ret, isFunction,

elem = this[0];


if ( !arguments.length ) {

if ( elem ) {

hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];


if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {

return ret;

}


ret = elem.value;


return typeof ret === "string" ?

// handle most common string cases

ret.replace(rreturn, "") :

// handle cases where value is null/undef or number

ret == null ? "" : ret;

}


return;

}


isFunction = jQuery.isFunction( value );


return this.each(function( i ) {

var self = jQuery(this), val;


if ( this.nodeType !== 1 ) {

return;

}


if ( isFunction ) {

val = value.call( this, i, self.val() );

} else {

val = value;

}


// Treat null/undefined as ""; convert numbers to string

if ( val == null ) {

val = "";

} else if ( typeof val === "number" ) {

val += "";

} else if ( jQuery.isArray( val ) ) {

val = jQuery.map(val, function ( value ) {

return value == null ? "" : value + "";

});

}


hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];


// If set returns undefined, fall back to normal setting

if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {

this.value = val;

}

});

}


posted by 뚱2
해당 오프젝트의 타입을 확인하고 메소드가 존재하고 파라미터가 일치한다면
호출해 준다.

// class
public class MyObject
{
    pub int Connect()
    {
        // 접속 ...
    }
    public void GetLastError(out int errorCode, out string errorMessage)
    {
        // 내부 코드들 ...
    }
}


    // ErrorUtil
    public class ErrorUtil
    {
        private static readonly string methodName = "GetLastError";
        private static int errorCode = 0;
        private static string errorMessage = "";

        public static int ErrorCode
        {
            get { return errorCode; }
        }

        public static string ErrorMessage
        {
            get { return errorMessage; }
        }

        public static bool GetLastError(object obj)
        {
            try
            {
                Type t = obj.GetType();
                MethodInfo info = t.GetMethod(
                    ErrorUtil.methodName,
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                    null,
                    new[] 
                    {
                        typeof(int).MakeByRefType(),
                        typeof(string).MakeByRefType()
                    },
                    null
                );

                if (info != null)
                {
                    object[] parameters = new object[2];
                    info.Invoke(obj, parameters);

                    errorCode = (int)parameters[0];
                    errorMessage = (string)parameters[1];
                    return true;
                }
                else
                {
                    errorMessage = String.Format("{0} 메소드를 찾을수 없거나, 파라미터가 정확하지 않습니다.", ErrorUtil.methodName);
                    return false;
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
                return false;
            }
        }
    }


// 사용예
    MyObject oCommpany = new MyObject();
    int retCode = oCompany.Connect();
    if (retCode != 0)
    {
           ErrorUtil.GetLastError(oCompany);
           MessageBox.Show(ErrorUtil.ErrorMessage);
    }


'.Net > C#' 카테고리의 다른 글

[C#] log4net  (0) 2012.04.03
[C#] vshosting.exe 가 뭘까요?  (0) 2012.03.26
[즐겨찾기] C# TreeView MultiSelect  (0) 2012.03.15
[C#] internal 지정자  (0) 2012.03.12
[즐겨찾기] 무료서적 Inside C# 2nd  (0) 2012.03.10
posted by 뚱2