English 中文(简体)
系统: 投递量不是正确的格式。
原标题:System.FormatException: Input string was not in a correct format.at System.Number.StringToNumber
  • 时间:2023-12-10 02:40:18
  •  标签:
  • c#
Closed. This question needs debugging details. It is not currently accepting answers.

public void GenerateLua()
        {
            _list = new List<string>();

            _list.Add("");

            Structs.Child parentObj = null;

            if(_root.document.children.Count > 1)
            {
                _list.Add("-- REMOVE ALL GROUPING IN YOUR PROJECT TO CONTINUE!!!");
                return;
            }

            //Get parent window size
            foreach(var el in _root.document.children[0].children)
            {
                if(el == null) 
                    continue;

                if(el.name.Equals(_parent))
                {
                    parentObj = el;
                    break;
                }
            }

            if (parentObj == null)
            {
                _list.Add("-- CAN T FIND THE PARENT ELEMENT, TRY AGAIN!");
                return;
            }

            if(parentObj.absoluteBoundingBox == null)
            {
                _list.Add("-- YOUR BACKGROUND IS INVALID, PLEASE SELECT THE MOST DEEP IMAGE");
                return;
            }

            double width, height;
            if (double.TryParse(parentObj.absoluteBoundingBox.width.ToString(), out width)
                && double.TryParse(parentObj.absoluteBoundingBox.height.ToString(), out height))
            {
                _list.Add($"function sw(value)
    return sx*value/{width}    
end
            
function sh(value)    
    return sy*value/{height}
end");
            }
            else
            {
                _list.Add("-- WIDTH OR HEIGHT IS NULL OR IN INVALID FORMAT, PLEASE CHECK YOUR ELEMENTS");
            }
            //_list.Add("local x, y = (sW/resW), (sH/resH)");
            _list.Add("");
            _list.Add("function on()");
            foreach(var el in _root.document.children[0].children)
            {
                if (el == null) 
                    continue;

                if (el.name.Equals(_parent))
                    continue;

                var elType = el.type;

                if(elType.Equals("RECTANGLE"))
                {
                    if (el.fills[0].type.Equals("IMAGE"))
                    {
                        double opacity = 1.0f;

                        if (el.fills[0].opacity != null)
                            opacity = el.fills[0].opacity.GetValueOrDefault();
                        else
                            opacity = 1.0f;
                        //Console.WriteLine("test {0}",el.absoluteBoundingBox);
                        if (el.absoluteBoundingBox == null)
                        {
                            
                                _list.Add("   -- ELEMENT jakis IS INVALID, PLEASE CONFIGURE IT PROPERLY");
                                continue;
                            
                           
                        }

                        int val_0 = int.Parse(el.absoluteBoundingBox.x.ToString());
                        int val_1 = int.Parse(el.absoluteBoundingBox.y.ToString());
                        int val_2 = int.Parse(el.absoluteBoundingBox.width.ToString());
                        int val_3 = int.Parse(el.absoluteBoundingBox.height.ToString());

请帮助。 我不知道这一错误会发生什么,我浪费了一小时或多小时的时间,超出了我,但对于一些人来说,这或许会很容易。

Throws an error System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s) ...

https://i.stack.imgur.com/ad41L.png” rel=“nofollow noreferer”>

_list.Add(string.Format(”) - ELEMENT jakis IS INVALID, PLEASE CONFIGURE IT PROPERLY”;

我删除了号”。 格式“,在“扼杀”方面仍有错误。

最佳回答

One possible fix is to make an if statement checking if it is not an int. This is an example on how you can achieve it:

if (!int.TryParse(el.absoluteBoundingBox.x.ToString(), out int val_0) ||
    !int.TryParse(el.absoluteBoundingBox.y.ToString(), out int val_1) ||
    !int.TryParse(el.absoluteBoundingBox.width.ToString(), out int val_2) ||
    !int.TryParse(el.absoluteBoundingBox.height.ToString(), out int val_3))
{
    _list.Add("   -- Invalid dimensions, please check configuration");
    continue;
}

I hope this helps you solve your problem :)

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...