Exemple #1
0
        public static string[] TryGetParamsByNameFromSubKey(string inKeyName, IKey inKey, ILogPrinter inLogger, bool inSubKeyMustBe, params int[] inParamCounts)
        {
            IKey sub_key = inKey.FindChildByName(inKeyName, StringComparison.InvariantCultureIgnoreCase);

            if (sub_key == null)
            {
                if (inSubKeyMustBe)
                {
                    inLogger.LogError(string.Format("Can't find subkey by name. Key [{0}] must have subkey {1}!", inKey.GetPath(), inKeyName));
                }
                return(null);
            }

            int value_count = sub_key.GetValuesCount();

            if (!inParamCounts.ContainsCheck(value_count))
            {
                string counts = inParamCounts.ToString(", ");
                inLogger.LogError(string.Format("Subkey [{0}] must have [{1}] counts of values, but was found {2}", sub_key.GetPath(), counts, value_count));
                return(null);
            }

            var a = new string[value_count];

            for (int i = 0; i < value_count; i++)
            {
                a[i] = sub_key.GetValueAsString(i);
            }

            return(a);
        }
Exemple #2
0
        public void LogError(EErrorCode inErrorCode, string inText, int inLineNumber)
        {
            _error_count++;
            string text = string.Format("{0} [{3}]. [{1}]: {2}", inErrorCode, inLineNumber, inText, _parsing_file);

            _printer.LogError(text);
        }
Exemple #3
0
        public static Func <object> CreateParameterlessConstructorHandler(Type type, ILogPrinter inLogger)
        {
            var         dynam = new DynamicMethod(string.Empty, typeof(object), Type.EmptyTypes, Module, true);
            ILGenerator il    = dynam.GetILGenerator();

            if (type.IsValueType)
            {
                il.DeclareLocal(type);
                il.Emit(OpCodes.Ldloc_0);
                il.Emit(OpCodes.Box, type);
            }
            else
            {
                ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes);
                if (ci == null)
                {
                    inLogger.LogError(string.Format("Type {0} hasnt default constructor", type.Name));
                    return(null);
                }
                il.Emit(OpCodes.Newobj, ci);
            }

            il.Emit(OpCodes.Ret);

            return((Func <object>)dynam.CreateDelegate(typeof(Func <object>)));
        }
Exemple #4
0
        public static SWinKeyInfo[] GetWinKeyInfos(IKey inWinKeyParent, CWindowTypeDescrs inWindowTypeDescrs, ILogPrinter inLogger)
        {
            int count = inWinKeyParent.GetChildCount();
            List <SWinKeyInfo> res = new List <SWinKeyInfo>(count);

            for (int i = 0; i < count; i++)
            {
                IKey window_key = inWinKeyParent.GetChild(i);

                var info = new SWinKeyInfo();

                info.WinKey = window_key;

                info.Name = Utils.GetWindowNameFromKey(window_key, i.ToString(), inLogger);

                string[] a = Utils.TryGetParamsByNameFromSubKey("Type", window_key, inLogger, true, 1);
                if (a.Length > 0)
                {
                    string stype = a[0];

                    NamedId?id = inWindowTypeDescrs.GetWinType(stype);

                    if (id.HasValue)
                    {
                        info.WinType = id.Value;
                        res.Add(info);
                    }
                    else
                    {
                        inLogger.LogError(string.Format("Undefined type. Key [{0}]!", window_key.GetPath()));
                    }
                }
            }
            return(res.ToArray());
        }
Exemple #5
0
        public override void SetValue(MemberInfo memberInfo, object instance, object value, ILogPrinter inLogger)
        {
            Action <object, object> setter;

            if (memberInfo is PropertyInfo)
            {
                var propertyInfo = memberInfo as PropertyInfo;
                var key          = propertyInfo.GetSetMethod(true).MethodHandle.Value;
                if (!setterCache.TryGetValue(key, out setter))
                {
                    setterCache.Add(key, setter = EmitHelper.CreatePropertySetterHandler(propertyInfo));
                }
            }
            else if (memberInfo is FieldInfo)
            {
                var fieldInfo = memberInfo as FieldInfo;
                if (!setterCache.TryGetValue(fieldInfo.FieldHandle.Value, out setter))
                {
                    setterCache.Add(fieldInfo.FieldHandle.Value, setter = EmitHelper.CreateFieldSetterHandler(fieldInfo));
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            try
            {
                setter(instance, value);
            }
            catch (Exception ex)
            {
                inLogger.LogError($"Exception for {memberInfo.Name}: {ex.Message}");
            }
        }
Exemple #6
0
 public static int FindChildIndex(this IKey key, IKey child, ILogPrinter inLogger)
 {
     for (int i = 0; i < key.GetChildCount(); i++)
     {
         if (key.GetChild(i) == child)
         {
             return(i);
         }
     }
     inLogger.LogError(string.Format("Can't FindChildIndex"));
     return(-1);
 }
Exemple #7
0
        public void DeserializationFromCscd(IKey key, ILogPrinter inLogger)
        {
            if (key.GetValuesCount() == 0)
            {
                inLogger.LogError(string.Format("NamedId.CscdConverter: Key {0} hasnt value!", key.GetPath()));
                return;
            }
            string  n   = key.GetValue(0).ToString();
            NamedId nid = GetNamedId(n);

            id   = nid.id;
            name = nid.name;
        }
Exemple #8
0
        public override object Instantiate(Type type, ILogPrinter inLogger)
        {
            Func <object> constructor;

            if (!constructorCache.TryGetValue(type.TypeHandle.Value, out constructor))
            {
                constructor = EmitHelper.CreateParameterlessConstructorHandler(type, inLogger);
                if (constructor == null)
                {
                    inLogger.LogError(string.Format("Cant create {0} object.", type.Name));
                    return(null);
                }
                constructorCache.Add(type.TypeHandle.Value, constructor);
            }
            return(constructor());
        }
Exemple #9
0
        void LogError(ILogPrinter inLogger, string inText)
        {
            string pt = string.Empty;

            if (!string.IsNullOrEmpty(_debug_text))
            {
                if (_debug_text.Length > 30)
                {
                    pt = _debug_text.Substring(0, 30);
                }
                else
                {
                    pt = _debug_text;
                }
            }
            inLogger.LogError(string.Format("{2}: [File: {0}. Text: {1}]", _debug_file_name, _debug_text, inText));
        }