示例#1
0
 public ZXPDatum(string key, FieldInfo fi)
 {
     Key   = key;
     field = fi;
     prop  = null;
     if (!ZXParser.GetConverter(Type, out Converter))
     {
         Converter = null;
     }
 }
示例#2
0
 public ZXPDatum(string key, PropertyInfo pi)
 {
     Key   = key;
     field = null;
     prop  = pi;
     if (!ZXParser.GetConverter(Type, out Converter))
     {
         Converter = null;
     }
 }
示例#3
0
 public static void AddXNATypes()
 {
     ZXParser.AddConverter(typeof(Vector2), new ZXPCVector2());
     ZXParser.AddConverter(typeof(Vector3), new ZXPCVector3());
     ZXParser.AddConverter(typeof(Vector4), new ZXPCVector4());
     ZXParser.AddConverter(typeof(Point), new ZXPCPoint());
     ZXParser.AddConverter(typeof(Color), new ZXPCColor());
     ZXParser.AddConverter(typeof(Rectangle), new ZXPCRectangle());
     ZXParser.AddConverter(typeof(BoundingBox), new ZXPCBBox());
 }
示例#4
0
        private static bool ParseArray(Type eType, string sArray, out object val)
        {
            val = null;
            IZXPConverter etConv;

            ZXParser.GetConverter(eType, out etConv);

            var nl = Delimiter.Delimit(sArray, DelimitType.Angled | DelimitType.Curly);

            // Create Parameters
            object element;
            var    elements = new List <object>();

            for (int ai = 0; ai < nl.Count;)
            {
                if (nl[ai].Type == DelimitType.Angled)
                {
                    if (ai >= nl.Count - 1 || nl[ai + 1].Type != DelimitType.Curly)
                    {
                        ai++;
                        continue;
                    }

                    // Get The Argument Type
                    string atValue = sArray.Substring(nl[ai].Start, nl[ai].Length);
                    if (string.IsNullOrWhiteSpace(atValue))
                    {
                        break;
                    }
                    Type aType = GetTypeFromString(atValue);
                    if (aType == null)
                    {
                        ai += 2;
                        continue;
                    }

                    // Get The Argument
                    string        sValue = sArray.Substring(nl[ai + 1].Start, nl[ai + 1].Length);
                    IZXPConverter conv;
                    ZXParser.GetConverter(aType, out conv);
                    if (ReadValue(sValue, conv, aType, out element))
                    {
                        elements.Add(element);
                    }
                    ai += 2;
                }
                else
                {
                    // Simple Parse
                    string sValue = sArray.Substring(nl[ai].Start, nl[ai].Length);
                    if (ReadValue(sValue, etConv, eType, out element))
                    {
                        elements.Add(element);
                    }
                    ai++;
                }
            }

            if (elements.Count < 1)
            {
                return(true);
            }
            var valArr = Array.CreateInstance(eType, elements.Count);

            for (int i = 0; i < elements.Count; i++)
            {
                valArr.SetValue(elements[i], i);
            }
            val = valArr;
            return(true);
        }
示例#5
0
        private static void ParseFunction(object o, ZXPProxy zpp, string s, List <DIndices> ld, ref int li)
        {
            // Check If A Key Is Available
            string key = GetKeyString(s, ld, li);

            if (string.IsNullOrWhiteSpace(key))
            {
                return;
            }

            // Find The Method That Matches To This Key
            ZXPFunc    func;
            MethodInfo method = null;

            if (!zpp.FuncsDict.TryGetValue(key, out func))
            {
                return;
            }
            method = func.Method;

            // Check For Simple Invoke
            ParameterInfo[] paramInfo = method.GetParameters();
            if (paramInfo.Length < 1 || paramInfo == null)
            {
                method.Invoke(o, null);
                return;
            }

            // Parse Parameters
            string sArgs = s.Substring(ld[li].Start, ld[li].Length);

            object[] args = new object[paramInfo.Length];
            var      nl   = Delimiter.Delimit(sArgs, DelimitType.Angled | DelimitType.Curly);

            // Check Number Of Arguments
            int ca = 0;

            foreach (var ndi in nl)
            {
                if (ndi.Type == DelimitType.Curly)
                {
                    ca++;
                }
            }
            if (ca != args.Length)
            {
                return;
            }

            // Create Parameters
            int ai = 0, pi = 0;

            for (; pi < args.Length;)
            {
                if (nl[ai].Type == DelimitType.Angled)
                {
                    if (ai >= nl.Count - 1 || nl[ai + 1].Type != DelimitType.Curly)
                    {
                        ai++;
                        continue;
                    }

                    // Get The Argument Type
                    string atValue = sArgs.Substring(nl[ai].Start, nl[ai].Length);
                    if (string.IsNullOrWhiteSpace(atValue))
                    {
                        break;
                    }
                    Type aType = GetTypeFromString(atValue);
                    if (aType == null)
                    {
                        break;
                    }


                    // Get The Argument
                    string        sValue = sArgs.Substring(nl[ai + 1].Start, nl[ai + 1].Length);
                    IZXPConverter conv;
                    ZXParser.GetConverter(aType, out conv);
                    if (ReadValue(sValue, conv, aType, out args[pi]))
                    {
                        pi++;
                    }
                    ai += 2;
                }
                else
                {
                    // Simple Parse
                    Type          aType  = paramInfo[pi].ParameterType;
                    string        sValue = sArgs.Substring(nl[ai].Start, nl[ai].Length);
                    IZXPConverter conv;
                    ZXParser.GetConverter(aType, out conv);
                    if (ReadValue(sValue, conv, aType, out args[pi]))
                    {
                        pi++;
                    }
                    ai++;
                }
            }
            // Check That All Arguments Are OK
            if (pi == args.Length)
            {
                method.Invoke(o, args);
            }
        }