Rhino.WrapFactory.Wrap C# (CSharp) Method

Wrap() public method

Wrap the object.
Wrap the object.

The value returned must be one of

  • java.lang.Boolean
  • java.lang.String
  • java.lang.Number
  • org.mozilla.javascript.Scriptable objects
  • The value returned by Context.getUndefinedValue()
  • null
public Wrap ( Context cx, Scriptable scope, object obj, Type staticType ) : object
cx Context the current Context for this thread
scope Scriptable the scope of the executing script
obj object the object to be wrapped. Note it can be null.
staticType System.Type /// type hint. If security restrictions prevent to wrap /// object based on its class, staticType will be used instead. ///
return object
		public virtual object Wrap(Context cx, Scriptable scope, object obj, Type staticType)
		{
			if (obj == null || obj == Undefined.instance || obj is Scriptable)
			{
				return obj;
			}
			if (staticType != null && staticType.IsPrimitive)
			{
				if (staticType == typeof(void))
				{
					return Undefined.instance;
				}
				if (staticType == typeof(char))
				{
					return Sharpen.Extensions.ValueOf(((char)obj));
				}
				return obj;
			}
			if (!IsJavaPrimitiveWrap())
			{
				if (obj is string || obj is Number || obj is bool)
				{
					return obj;
				}
				else
				{
					if (obj is char)
					{
						return ((char)obj).ToString();
					}
				}
			}
			Type cls = obj.GetType();
			if (cls.IsArray)
			{
				return NativeJavaArray.Wrap(scope, obj);
			}
			return WrapAsJavaObject(cx, scope, obj, staticType);
		}