コード例 #1
0
 public XSSFColor UnwrapColor(JsValue value)
 {
     if (value.Is <ColorInstance>())
     {
         return(value.As <ColorInstance>().ToColor());
     }
     return(UnwrapColor(Color.Construct(new[] { value })));
 }
コード例 #2
0
ファイル: Cell.cs プロジェクト: windygu/wastedge-querier
        public void SetComment(JsValue value)
        {
            Cell.CellComment = null;

            if (value.Is <CommentInstance>())
            {
                Cell.CellComment = value.As <CommentInstance>().Comment;
            }
            else
            {
                string str = value.ConvertToString();
                if (str != null)
                {
                    var comment = (XSSFComment)((XSSFSheet)Cell.Row.Sheet).CreateComment();
                    comment.String   = new XSSFRichTextString(str);
                    Cell.CellComment = comment;
                }
            }
        }
コード例 #3
0
ファイル: JsonSerializer.cs プロジェクト: Willy-Kimura/jint
        public JsValue Serialize(JsValue value, JsValue replacer, JsValue space)
        {
            _stack = new Stack<object>();

            // for JSON.stringify(), any function passed as the first argument will return undefined
            // if the replacer is not defined. The function is not called either.
            if (value.Is<ICallable>() && replacer == Undefined.Instance) 
            {
                return Undefined.Instance;
            }

            if (replacer.IsObject())
            {
                if (replacer.Is<ICallable>())
                {
                    _replacerFunction = replacer;
                }
                else
                {
                    var replacerObj = replacer.AsObject();
                    if (replacerObj.Class == "Array")
                    {
                        _propertyList = new List<string>();
                    }

                    foreach (var property in replacerObj.GetOwnProperties().Select(x => x.Value))
                    {
                        JsValue v = _engine.GetValue(property);
                        string item = null;
                        if (v.IsString())
                        {
                            item = v.AsString();
                        }
                        else if (v.IsNumber())
                        {
                            item = TypeConverter.ToString(v);
                        }
                        else if (v.IsObject())
                        {
                            var propertyObj = v.AsObject();
                            if (propertyObj.Class == "String" || propertyObj.Class == "Number")
                            {
                                item = TypeConverter.ToString(v);
                            }
                        }

                        if (item != null && !_propertyList.Contains(item))
                        {
                            _propertyList.Add(item);
                        }

                    }
                }
            }

            if (space.IsObject())
            {
                var spaceObj = space.AsObject();
                if (spaceObj.Class == "Number")
                {
                    space = TypeConverter.ToNumber(spaceObj);
                }
                else if (spaceObj.Class == "String")
                {
                    space = TypeConverter.ToString(spaceObj);
                }
            }

            // defining the gap
            if (space.IsNumber())
            {
                if (space.AsNumber() > 0) {
                    _gap = new System.String(' ', (int)System.Math.Min(10, space.AsNumber()));
                }
                else 
                {
                    _gap = string.Empty;
                }
            }
            else if (space.IsString())
            {
                var stringSpace = space.AsString();
                _gap = stringSpace.Length <= 10 ? stringSpace : stringSpace.Substring(0, 10);
            }
            else
            {
                _gap = string.Empty;
            }

            var wrapper = _engine.Object.Construct(Arguments.Empty);
            wrapper.DefineOwnProperty("", new PropertyDescriptor(value, true, true, true), false);

            return Str("", wrapper);
        }
コード例 #4
0
 public bool IsPropertyReference()
 {
     // http://www.ecma-international.org/ecma-262/5.1/#sec-8.7
     return((_baseValue.IsObject() && !_baseValue.Is <EnvironmentRecord>()) || HasPrimitiveBase());
 }
コード例 #5
0
        public JsValue Serialize(JsValue value, JsValue replacer, JsValue space)
        {
            _stack = new Stack <object>();

            // for JSON.stringify(), any function passed as the first argument will return undefined
            // if the replacer is not defined. The function is not called either.
            if (value.Is <ICallable>() && replacer == Undefined.Instance)
            {
                return(Undefined.Instance);
            }

            if (replacer.IsObject())
            {
                if (replacer.Is <ICallable>())
                {
                    _replacerFunction = replacer;
                }
                else
                {
                    var replacerObj = replacer.AsObject();
                    if (replacerObj.Class == "Array")
                    {
                        _propertyList = new List <string>();
                    }

                    foreach (var property in replacerObj.GetOwnProperties().Select(x => x.Value))
                    {
                        JsValue v    = _engine.GetValue(property);
                        string  item = null;
                        if (v.IsString())
                        {
                            item = v.AsString();
                        }
                        else if (v.IsNumber())
                        {
                            item = TypeConverter.ToString(v);
                        }
                        else if (v.IsObject())
                        {
                            var propertyObj = v.AsObject();
                            if (propertyObj.Class == "String" || propertyObj.Class == "Number")
                            {
                                item = TypeConverter.ToString(v);
                            }
                        }

                        if (item != null && !_propertyList.Contains(item))
                        {
                            _propertyList.Add(item);
                        }
                    }
                }
            }

            if (space.IsObject())
            {
                var spaceObj = space.AsObject();
                if (spaceObj.Class == "Number")
                {
                    space = TypeConverter.ToNumber(spaceObj);
                }
                else if (spaceObj.Class == "String")
                {
                    space = TypeConverter.ToString(spaceObj);
                }
            }

            // defining the gap
            if (space.IsNumber())
            {
                if (space.AsNumber() > 0)
                {
                    _gap = new System.String(' ', (int)System.Math.Min(10, space.AsNumber()));
                }
                else
                {
                    _gap = string.Empty;
                }
            }
            else if (space.IsString())
            {
                var stringSpace = space.AsString();
                _gap = stringSpace.Length <= 10 ? stringSpace : stringSpace.Substring(0, 10);
            }
            else
            {
                _gap = string.Empty;
            }

            var wrapper = _engine.Object.Construct(Arguments.Empty);

            wrapper.DefineOwnProperty("", new PropertyDescriptor(value, true, true, true), false);

            return(Str("", wrapper));
        }
コード例 #6
0
ファイル: CellStyle.cs プロジェクト: windygu/wastedge-querier
 public void SetBorderColorLeft(JsValue value)
 {
     CellStyle.SetLeftBorderColor(value.Is <ColorInstance>() ? value.As <ColorInstance>().ToColor() : null);
 }
コード例 #7
0
ファイル: CellStyle.cs プロジェクト: windygu/wastedge-querier
 public void SetFont(JsValue value)
 {
     CellStyle.SetFont(value.Is <FontInstance>() ? value.As <FontInstance>().Font : null);
 }
コード例 #8
0
ファイル: Cell.cs プロジェクト: windygu/wastedge-querier
 public void SetStyle(JsValue value)
 {
     Cell.CellStyle = value.Is <CellStyleInstance>() ? value.As <CellStyleInstance>().CellStyle : null;
 }