Example #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            EquationTokenizer.AddNamespace(typeof(object));
            EquationTokenizer.AddNamespace(typeof(System.Windows.Visibility));

            //bool existed;
            //string id = Marshal.GetTypeLibGuidForAssembly(Assembly.GetExecutingAssembly()).ToString();
            //MessageBox.Show(id);
            //Mutex mutex = new Mutex(true, id, out existed);
            //if (existed == false)
            //{
            //    MessageBox.Show("App is already opened");
            //    Application.Current.Shutdown();
            //    return;
            //}

            base.OnStartup(e);
        }
Example #2
0
        /// <summary>
        /// QuickConverter の設定を初期化します。
        /// </summary>
        private void InitializeQuickConverter()
        {
            // System
            EquationTokenizer.AddNamespace(typeof(System.Object));                   // System                  : mscorlib.dll
            EquationTokenizer.AddNamespace(typeof(System.IO.Path));                  // System.IO               : mscorlib.dll
            EquationTokenizer.AddNamespace(typeof(System.Text.Encoding));            // System.Text             : mscorlib.dll
            EquationTokenizer.AddNamespace(typeof(System.Reflection.Assembly));      // System.Reflection       : mscorlib.dll
            EquationTokenizer.AddNamespace(typeof(System.Windows.Point));            // System.Windows          : WindowsBase.dll
            EquationTokenizer.AddNamespace(typeof(System.Windows.UIElement));        // System.Windows          : PresentationCore.dll
            EquationTokenizer.AddNamespace(typeof(System.Windows.Input.Key));        // System.Windows.Input    : WindowsBase.dll
            EquationTokenizer.AddNamespace(typeof(System.Windows.Input.Cursor));     // System.Windows.Input    : PresentationCore.dll
            EquationTokenizer.AddNamespace(typeof(System.Windows.Controls.Control)); // System.Windows.Controls : PresentationFramework.dll
            EquationTokenizer.AddExtensionMethods(typeof(System.Linq.Enumerable));   // System.Linq             : System.Core.dll

            // Lib
            EquationTokenizer.AddNamespace(typeof(Microsoft.VisualBasic.Globals));   // Microsoft.VisualBasic   : Microsoft.VisualBasic.dll
            EquationTokenizer.AddNamespace(typeof(MyLib.Wpf.Interactions.InteractionNotification));
        }
Example #3
0
            public static void InitQuickConverter()
            {
#pragma warning disable IDE0049
                EquationTokenizer.AddNamespace(typeof(System.Object));                           // System                  : System.Runtime.dll
                EquationTokenizer.AddNamespace(typeof(System.IO.Path));                          // System.IO               : System.Runtime.dll
                EquationTokenizer.AddNamespace(typeof(System.Text.Encoding));                    // System.Text             : System.Runtime.dll
                EquationTokenizer.AddNamespace(typeof(System.Reflection.Assembly));              // System.Reflection       : System.Runtime.dll
                EquationTokenizer.AddNamespace(typeof(System.Windows.Point));                    // System.Windows          : WindowsBase.dll
                EquationTokenizer.AddNamespace(typeof(System.Windows.UIElement));                // System.Windows          : PresentationCore.dll
                EquationTokenizer.AddNamespace(typeof(System.Windows.Window));                   // System.Windows          : PresentationFramework.dll
                EquationTokenizer.AddNamespace(typeof(System.Windows.Input.Key));                // System.Windows.Input    : WindowsBase.dll
                EquationTokenizer.AddNamespace(typeof(System.Windows.Input.Cursor));             // System.Windows.Input    : PresentationCore.dll
                EquationTokenizer.AddNamespace(typeof(System.Windows.Input.KeyboardNavigation)); // System.Windows.Input    : PresentationFramework.dll
                EquationTokenizer.AddNamespace(typeof(System.Windows.Controls.Control));         // System.Windows.Controls : PresentationFramework.dll
                EquationTokenizer.AddNamespace(typeof(System.Windows.Media.Brush));              // System.Windows.Media    : PresentationFramework.dll
                EquationTokenizer.AddNamespace(typeof(System.Linq.Enumerable));                  // System.Linq             : System.Linq.dll
                EquationTokenizer.AddExtensionMethods(typeof(System.Linq.Enumerable));           // System.Linq             : System.Linq.dll
#pragma warning restore IDE0049
            }
Example #4
0
        internal override bool TryGetToken(ref string text, out TokenBase token, bool requireReturnValue = true)
        {
            token = null;
            if (text.Length == 0)
            {
                return(false);
            }
            Operator op;

            if (text[0] == '!')
            {
                op = Operator.Not;
            }
            else if (text[0] == '+')
            {
                op = Operator.Positive;
            }
            else if (text[0] == '-')
            {
                op = Operator.Negative;
            }
            else
            {
                return(false);
            }
            TokenBase valToken;
            string    temp = text.Substring(1).TrimStart();

            if (!EquationTokenizer.TryGetValueToken(ref temp, out valToken))
            {
                return(false);
            }
            token = new UnaryOperatorToken()
            {
                operation = op, value = valToken
            };
            text = temp;
            return(true);
        }
Example #5
0
        internal override bool TryGetToken(ref string text, out TokenBase token)
        {
            token = null;
            if (!text.StartsWith("throw"))
            {
                return(false);
            }
            string temp = text.Substring(5).TrimStart();

            TokenBase valToken = null;

            if (!EquationTokenizer.TryGetValueToken(ref temp, out valToken))
            {
                return(false);
            }

            text  = temp;
            token = new ThrowToken()
            {
                Exception = valToken
            };
            return(true);
        }
 public void OnInitialized(IContainerProvider containerProvider)
 {
     //Инициализация QuickConverter
     EquationTokenizer.AddNamespace(typeof(object));
     EquationTokenizer.AddNamespace(typeof(Visibility));
 }
Example #7
0
        internal static IEnumerable <Tuple <object, string> > GetNameMatches(string name, string previous, Type parent)
        {
            if (name.Length > 0 && (Char.IsLetter(name[0]) || name[0] == '_'))
            {
                int count = 1;
                while (count < name.Length && (Char.IsLetterOrDigit(name[count]) || name[count] == '_'))
                {
                    ++count;
                }
                string      val      = (previous != null && parent == null ? previous + "." : "") + name.Substring(0, count);
                string      temp     = name.Substring(count).TrimStart();
                List <Type> typeArgs = null;
                if (temp.Length > 0 && temp[0] == '[')
                {
                    string old = temp;
                    typeArgs = new List <Type>();
                    List <string> split;
                    if (TrySplitByCommas(ref temp, '[', ']', out split))
                    {
                        if (split.Count == 0)
                        {
                            typeArgs = null;
                            val     += "[]";
                        }
                        else
                        {
                            foreach (string str in split)
                            {
                                Tuple <object, string> tuple = GetNameMatches(str.Trim(), null, null).FirstOrDefault(tp => tp.Item1 is Type && string.IsNullOrWhiteSpace(tp.Item2));
                                if (tuple == null)
                                {
                                    typeArgs = null;
                                    temp     = old;
                                    break;
                                }
                                typeArgs.Add(tuple.Item1 as Type);
                            }
                        }
                    }
                    else
                    {
                        yield break;
                    }
                }
                bool more = temp.Length > 0 && temp[0] == '.';
                if (parent == null)
                {
                    Type type;
                    if (EquationTokenizer.TryGetType(val, typeArgs != null ? typeArgs.ToArray() : null, out type))
                    {
                        yield return(new Tuple <object, string>(type, temp));

                        if (more)
                        {
                            foreach (var match in GetNameMatches(temp.Substring(1), val, type))
                            {
                                yield return(match);
                            }
                        }
                    }
                    if (more)
                    {
                        foreach (var match in GetNameMatches(temp.Substring(1), val, null))
                        {
                            yield return(match);
                        }
                    }
                }
                else
                {
                    foreach (MemberInfo info in parent.GetMember(val, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy))
                    {
                        if (info.MemberType == MemberTypes.Method)
                        {
                            MemberInfo ret = info;
                            if ((typeArgs != null) != (info as MethodInfo).IsGenericMethodDefinition)
                            {
                                continue;
                            }
                            if ((info as MethodInfo).IsGenericMethodDefinition && typeArgs.Count != (info as MethodInfo).GetGenericArguments().Length)
                            {
                                continue;
                            }
                            if ((info as MethodInfo).IsGenericMethodDefinition)
                            {
                                try { ret = (info as MethodInfo).MakeGenericMethod(typeArgs.ToArray()); }
                                catch { continue; }
                            }
                            yield return(new Tuple <object, string>(ret, temp));
                        }
                        else if (info.MemberType == MemberTypes.Field || info.MemberType == MemberTypes.Property)
                        {
                            yield return(new Tuple <object, string>(info, temp));
                        }
                        else if (info.MemberType == MemberTypes.NestedType)
                        {
                            yield return(new Tuple <object, string>(info, temp));

                            if (temp.Length > 0 && temp[0] == '.')
                            {
                                foreach (var match in GetNameMatches(temp.Substring(1), val, info as Type))
                                {
                                    yield return(match);
                                }
                            }
                        }
                    }
                }
            }
        }
        internal override bool TryGetToken(ref string text, out TokenBase token, bool requireReturnValue = true)
        {
            token = null;
            var           list = new List <TokenBase>();
            List <string> split;
            string        temp = text;

            if (!TrySplitByCommas(ref temp, open, close, out split))
            {
                return(false);
            }
            foreach (string str in split)
            {
                TokenBase newToken;
                string    s = str.Trim();
                if (allowSubLists && s.StartsWith(open.ToString()) && s.EndsWith(close.ToString()))
                {
                    if (new ArgumentListToken(open, close).TryGetToken(ref s, out newToken))
                    {
                        list.Add(newToken);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (findAssignments)
                {
                    if (new LambdaAssignmentToken(assignmentType).TryGetToken(ref s, out newToken))
                    {
                        list.Add(newToken);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (allowTypeCasts)
                {
                    if (new TypeCastToken(false).TryGetToken(ref s, out newToken))
                    {
                        string    nameTemp = "$" + s;
                        TokenBase tokenTemp;
                        if (!new ParameterToken().TryGetToken(ref nameTemp, out tokenTemp) || !String.IsNullOrWhiteSpace(nameTemp))
                        {
                            return(false);
                        }
                        (newToken as TypeCastToken).Target = tokenTemp;
                        list.Add(newToken);
                    }
                    else
                    {
                        string    nameTemp = "$" + s;
                        TokenBase tokenTemp;
                        if (!new ParameterToken().TryGetToken(ref nameTemp, out tokenTemp) || !String.IsNullOrWhiteSpace(nameTemp))
                        {
                            return(false);
                        }
                        list.Add(tokenTemp);
                    }
                }
                else
                {
                    if (EquationTokenizer.TryEvaluateExpression(str.Trim(), out newToken))
                    {
                        list.Add(newToken);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            token = new ArgumentListToken('\0', '\0')
            {
                Arguments = list.ToArray()
            };
            text = temp;
            return(true);
        }
Example #9
0
 public App()
 {
     //Инициализация QuickConverter
     EquationTokenizer.AddNamespace(typeof(object));
     EquationTokenizer.AddNamespace(typeof(Visibility));
 }
Example #10
0
        internal override bool TryGetToken(ref string text, out TokenBase token)
        {
            token = null;
            bool inQuotes = false;
            int  brackets = 0;
            int  count    = 0;
            int  i        = 0;
            int  qPos     = -1;
            int  cPos     = -1;

            while (true)
            {
                if (i >= text.Length)
                {
                    return(false);
                }
                if (i > 0 && text[i] == '\'' && text[i - 1] != '\\')
                {
                    inQuotes = !inQuotes;
                }
                else if (!inQuotes)
                {
                    if (text[i] == '(')
                    {
                        ++brackets;
                    }
                    else if (text[i] == ')')
                    {
                        --brackets;
                    }
                    else if (brackets == 0)
                    {
                        if (text[i] == '?' && (i >= text.Length - 1 || (text[i + 1] != '.' && text[i + 1] != '[')))
                        {
                            if (count == 0)
                            {
                                qPos = i;
                            }
                            ++count;
                        }
                        else if (text[i] == ':')
                        {
                            --count;
                            if (count < 0)
                            {
                                return(false);
                            }
                            if (count == 0)
                            {
                                cPos = i;
                                break;
                            }
                        }
                    }
                }
                ++i;
            }
            TokenBase left, middle, right;

            if (!EquationTokenizer.TryEvaluateExpression(text.Substring(0, qPos).Trim(), out left))
            {
                return(false);
            }
            if (!EquationTokenizer.TryEvaluateExpression(text.Substring(qPos + 1, cPos - qPos - 1).Trim(), out middle))
            {
                return(false);
            }
            if (!EquationTokenizer.TryEvaluateExpression(text.Substring(cPos + 1).Trim(), out right))
            {
                return(false);
            }
            token = new TernaryOperatorToken()
            {
                Condition = left, OnTrue = middle, OnFalse = right
            };
            text = "";
            return(true);
        }