private static void EmitNullableToNullableConversion(this ILGenerator ilGenerator, TypeInfo typeFrom, TypeInfo typeTo, bool isChecked)
        {
            Label        labIfNull = default(Label);
            Label        labEnd    = default(Label);
            LocalBuilder locFrom   = null;
            LocalBuilder locTo     = null;

            locFrom = ilGenerator.DeclareLocal(typeFrom.AsType());
            ilGenerator.Emit(OpCodes.Stloc, locFrom);
            locTo = ilGenerator.DeclareLocal(typeTo.AsType());
            // test for null
            ilGenerator.Emit(OpCodes.Ldloca, locFrom);
            ilGenerator.EmitHasValue(typeFrom.AsType());
            labIfNull = ilGenerator.DefineLabel();
            ilGenerator.Emit(OpCodes.Brfalse_S, labIfNull);
            ilGenerator.Emit(OpCodes.Ldloca, locFrom);
            ilGenerator.EmitGetValueOrDefault(typeFrom.AsType());
            Type nnTypeFrom = TypeInfoUtils.GetNonNullableType(typeFrom);
            Type nnTypeTo   = TypeInfoUtils.GetNonNullableType(typeTo);

            ilGenerator.EmitConvertToType(nnTypeFrom, nnTypeTo, isChecked);
            // construct result type
            ConstructorInfo ci = typeTo.GetConstructor(new Type[] { nnTypeTo });

            ilGenerator.Emit(OpCodes.Newobj, ci);
            ilGenerator.Emit(OpCodes.Stloc, locTo);
            labEnd = ilGenerator.DefineLabel();
            ilGenerator.Emit(OpCodes.Br_S, labEnd);
            // if null then create a default one
            ilGenerator.MarkLabel(labIfNull);
            ilGenerator.Emit(OpCodes.Ldloca, locTo);
            ilGenerator.Emit(OpCodes.Initobj, typeTo.AsType());
            ilGenerator.MarkLabel(labEnd);
            ilGenerator.Emit(OpCodes.Ldloc, locTo);
        }
Beispiel #2
0
        public bool Set <T>(string variableKey, T value = default(T), bool skipIfExists = false)
        {
            string variable = ParameterDicUtils.GetVariable(variableKey);

            string[] variableSplit = variable.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            if (variableSplit.Length > 1)
            {
                //If have more than one hierarchy (e.g. {Code.Directory.Temp})
                //Remove last node, and construct as variable key (e.g. {Code.Directory}))
                string parentKey    = "{" + String.Join(".", variableSplit.Take(variableSplit.Length - 1)) + "}";
                string childPath    = variableSplit.Last();
                string childKey     = "{" + childPath + "}";
                object parentObject = Get(parentKey);

                //If ParentObject not found, create as ParameterDic.
                if (parentObject == null)
                {
                    parentObject = new ParameterDic();
                    Set <ParameterDic>(parentKey, (ParameterDic)parentObject, false);
                }

                if (parentObject is IParameterDic)
                {
                    (parentObject as IParameterDic).Set <T>(childKey, value, skipIfExists);
                    return(true);
                }
                else
                {
                    TypeInfoUtils.SetProperty(parentObject, childPath, value);
                    return(true);
                }
            }
            else
            if (_store.ContainsKey(variable))
            {
                if (!skipIfExists)
                {
                    if (!(_store[variable] is T) || !(_store[variable].Equals(value)))
                    {
                        _store[variable] = value;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                _store.Add(variable, value);
                return(true);
            }
        }
Beispiel #3
0
        public bool SetValue <T>(string variableKey, T value, bool skipIfExists = false)
        {
            if (variableKey == null)
            {
                return(false);
            }

            string variable = GetVariable(variableKey);

            string[] variableSplit = variable.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            if (variableSplit.Length > 1)
            {
                string parentKey    = "{" + String.Join(".", variableSplit.Take(variableSplit.Length - 1)) + "}";
                string childPath    = variableSplit.Last();
                string childKey     = "{" + childPath + "}";
                object parentObject = GetValue(parentKey);
                if (parentObject is ParameterDic)
                {
                    (parentObject as ParameterDic).SetValue <T>(childKey, value, skipIfExists);
                    return(true);
                }
                else
                {
                    if (parentObject != null)
                    {
                        TypeInfoUtils.SetProperty(parentObject, childPath, value);
                        return(true);
                    }
                }
                return(false);
            }
            else
            if (_store.ContainsKey(variable))
            {
                if (!skipIfExists)
                {
                    if (!(_store[variable] is T) || !(_store[variable].Equals(value)))
                    {
                        this[variable] = value;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                _store.Add(variable, value);
                return(true);
            }
        }
        public static void EmitConvertToType(this ILGenerator ilGenerator, Type typeFrom, Type typeTo, bool isChecked = true)
        {
            if (ilGenerator == null)
            {
                throw new ArgumentNullException(nameof(ilGenerator));
            }
            if (typeFrom == null)
            {
                throw new ArgumentNullException(nameof(typeFrom));
            }
            if (typeTo == null)
            {
                throw new ArgumentNullException(nameof(typeTo));
            }

            var typeFromInfo = typeFrom.GetTypeInfo();
            var typeToInfo   = typeTo.GetTypeInfo();

            var nnExprType = typeFromInfo.GetNonNullableType();
            var nnType     = typeToInfo.GetNonNullableType();

            if (TypeInfoUtils.AreEquivalent(typeFromInfo, typeToInfo))
            {
                return;
            }

            if (typeFromInfo.IsInterface ||   // interface cast
                typeToInfo.IsInterface ||
                typeFrom == typeof(object) || // boxing cast
                typeTo == typeof(object) ||
                typeFrom == typeof(System.Enum) ||
                typeFrom == typeof(System.ValueType) ||
                TypeInfoUtils.IsLegalExplicitVariantDelegateConversion(typeFromInfo, typeToInfo))
            {
                ilGenerator.EmitCastToType(typeFromInfo, typeToInfo);
            }
            else if (typeFromInfo.IsNullableType() || typeToInfo.IsNullableType())
            {
                ilGenerator.EmitNullableConversion(typeFromInfo, typeToInfo, isChecked);
            }
            else if (!(typeFromInfo.IsConvertible() && typeToInfo.IsConvertible()) // primitive runtime conversion
                     &&
                     (nnExprType.GetTypeInfo().IsAssignableFrom(nnType) ||         // down cast
                      nnType.GetTypeInfo().IsAssignableFrom(nnExprType)))          // up cast
            {
                ilGenerator.EmitCastToType(typeFromInfo, typeToInfo);
            }
            else if (typeFromInfo.IsArray && typeToInfo.IsArray)
            {
                // See DevDiv Bugs #94657.
                ilGenerator.EmitCastToType(typeFromInfo, typeToInfo);
            }
            else
            {
                ilGenerator.EmitNumericConversion(typeFromInfo, typeToInfo, isChecked);
            }
        }
 /**
  * A required option that sets the object inspector for the rows. If
  * setSchema is not called, it also defines the schema.
  */
 public WriterOptions inspector(ObjectInspector value)
 {
     _inspector = value;
     if (!explicitSchema)
     {
         schema = OrcUtils.convertTypeInfo(
             TypeInfoUtils.getTypeInfoFromObjectInspector(value));
     }
     return(this);
 }
        private static void EmitNullableToNonNullableStructConversion(this ILGenerator ilGenerator, TypeInfo typeFrom, TypeInfo typeTo, bool isChecked)
        {
            LocalBuilder locFrom = null;

            locFrom = ilGenerator.DeclareLocal(typeFrom.AsType());
            ilGenerator.Emit(OpCodes.Stloc, locFrom);
            ilGenerator.Emit(OpCodes.Ldloca, locFrom);
            ilGenerator.EmitGetValue(typeFrom.AsType());
            Type nnTypeFrom = TypeInfoUtils.GetNonNullableType(typeFrom);

            ilGenerator.EmitConvertToType(nnTypeFrom, typeTo.AsType(), isChecked);
        }
Beispiel #7
0
        /// <summary>
        ///     Returns the current data value, converted to the specified type.
        /// </summary>
        /// <param name="type">Desired type of data.</param>
        /// <returns>Current data value, converted to the specified type.</returns>
        /// <exception cref="System.InvalidCastException">Thrown if the data value can't be cast to the specified type.</exception>
        public object GetValue(Type type)
        {
            var rawValue = this.Value;

            if (rawValue == null)
            {
                return(TypeInfoUtils.IsValueType(type) ? Activator.CreateInstance(type) : null);
            }

            object convertedValue;

            return(ReflectionUtils.TryConvertValue(rawValue, type, out convertedValue) ? convertedValue : rawValue);
        }
Beispiel #8
0
        /**
         * Convert a Hive type property string that contains separated type names into a list of
         * TypeDescription objects.
         * @return the list of TypeDescription objects.
         */
        public static List <TypeDescription> typeDescriptionsFromHiveTypeProperty(string hiveTypeProperty)
        {
            // CONSDIER: We need a type name parser for TypeDescription.

            List <TypeInfo>        typeInfoList  = TypeInfoUtils.getTypeInfosFromTypeString(hiveTypeProperty);
            List <TypeDescription> typeDescrList = new List <TypeDescription>(typeInfoList.Count);

            foreach (TypeInfo typeInfo in typeInfoList)
            {
                typeDescrList.Add(convertTypeInfo(typeInfo));
            }
            return(typeDescrList);
        }
        private static void EmitNonNullableToNullableConversion(this ILGenerator ilGenerator, TypeInfo typeFrom, TypeInfo typeTo, bool isChecked)
        {
            LocalBuilder locTo = null;

            locTo = ilGenerator.DeclareLocal(typeTo.AsType());
            Type nnTypeTo = TypeInfoUtils.GetNonNullableType(typeTo);

            ilGenerator.EmitConvertToType(typeFrom.AsType(), nnTypeTo, isChecked);
            ConstructorInfo ci = typeTo.GetConstructor(new Type[] { nnTypeTo });

            ilGenerator.Emit(OpCodes.Newobj, ci);
            ilGenerator.Emit(OpCodes.Stloc, locTo);
            ilGenerator.Emit(OpCodes.Ldloc, locTo);
        }
        public void testInspectorFromTypeInfo()
        {
            TypeInfo typeInfo =
                TypeInfoUtils.getTypeInfoFromTypeString("struct<c1:boolean,c2:tinyint" +
                                                        ",c3:smallint,c4:int,c5:bigint,c6:float,c7:double,c8:binary," +
                                                        "c9:string,c10:struct<c1:int>,c11:map<int,int>,c12:uniontype<int>" +
                                                        ",c13:array<timestamp>>");
            StructObjectInspector inspector = (StructObjectInspector)
                                              OrcStruct.createObjectInspector(typeInfo);

            Assert.Equal("struct<c1:boolean,c2:tinyint,c3:smallint,c4:int,c5:" +
                         "bigint,c6:float,c7:double,c8:binary,c9:string,c10:struct<" +
                         "c1:int>,c11:map<int,int>,c12:uniontype<int>,c13:array<timestamp>>",
                         inspector.getTypeName());
            Assert.Equal(null,
                         inspector.getAllStructFieldRefs()[0].getFieldComment());
            Assert.Equal(null, inspector.getStructFieldRef("UNKNOWN"));
            OrcStruct s1 = new OrcStruct(13);

            for (int i = 0; i < 13; ++i)
            {
                s1.setFieldValue(i, i);
            }

            List <object> list = new List <object> {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
            };

            Assert.Equal(list, inspector.getStructFieldsDataAsList(s1));
            ListObjectInspector listOI = (ListObjectInspector)
                                         inspector.getAllStructFieldRefs()[12].getFieldObjectInspector();

            Assert.Equal(ObjectInspectorCategory.LIST, listOI.getCategory());
            Assert.Equal(10, listOI.getListElement(list, 10));
            Assert.Equal(null, listOI.getListElement(list, -1));
            Assert.Equal(null, listOI.getListElement(list, 13));
            Assert.Equal(13, listOI.getListLength(list));

            Dictionary <object, object> map = new Dictionary <object, object>()
            {
                { 1, 2 },
                { 2, 4 },
                { 3, 6 },
            };
            MapObjectInspector mapOI = (MapObjectInspector)
                                       inspector.getAllStructFieldRefs()[10].getFieldObjectInspector();

            Assert.Equal(3, mapOI.getMapSize(map));
            Assert.Equal(4, mapOI.getMapValueElement(map, 2));
        }
        private static void EmitNullableConversion(this ILGenerator ilGenerator, TypeInfo typeFrom, TypeInfo typeTo, bool isChecked)
        {
            bool isTypeFromNullable = TypeInfoUtils.IsNullableType(typeFrom);
            bool isTypeToNullable   = TypeInfoUtils.IsNullableType(typeTo);

            if (isTypeFromNullable && isTypeToNullable)
            {
                ilGenerator.EmitNullableToNullableConversion(typeFrom, typeTo, isChecked);
            }
            else if (isTypeFromNullable)
            {
                ilGenerator.EmitNullableToNonNullableConversion(typeFrom, typeTo, isChecked);
            }
            else
            {
                ilGenerator.EmitNonNullableToNullableConversion(typeFrom, typeTo, isChecked);
            }
        }
Beispiel #12
0
        public T GetValue <T>(string variableKey, T defaultValue)
        {
            if (variableKey == null)
            {
                return(defaultValue);
            }

            string variable = GetVariable(variableKey);

            string[] variableSplit = variable.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            var    match   = Regex.Match(variableSplit[0], RegexPatterns.ParseArrayCounterPattern);
            string varName = match.Groups["variable"].Value;
            int    idx     = match.Groups["counter"].Success ? Int32.Parse(match.Groups["counter"].Value) : -1;

            if (_store.ContainsKey(varName))
            {
                object initValue = _store[varName];
                if (initValue == null)
                {
                    return(default(T));
                }
                if (initValue is ParameterDic && idx == -1 && variableSplit.Length > 1)
                {
                    //Omit the first variable.
                    string trailVariable = "{" + String.Join(".", variableSplit.Skip(1).ToArray()) + "}";
                    return((initValue as ParameterDic).GetValue <T>(trailVariable));
                }
                if (idx != -1 && initValue is Array)
                {
                    initValue = (initValue as Array).GetValue(idx);
                }
                var val = TypeInfoUtils.GetPropertyOrMethod(initValue, variableSplit.Skip(1).ToArray());
                if (val is T)
                {
                    return((T)val);
                }
            }

            return(defaultValue);
        }
        private static void EmitNumericConversion(this ILGenerator ilGenerator, TypeInfo typeFrom, TypeInfo typeTo, bool isChecked)
        {
            bool isFromUnsigned      = TypeInfoUtils.IsUnsigned(typeFrom);
            bool isFromFloatingPoint = TypeInfoUtils.IsFloatingPoint(typeFrom);

            if (typeTo.AsType() == typeof(Single))
            {
                if (isFromUnsigned)
                {
                    ilGenerator.Emit(OpCodes.Conv_R_Un);
                }
                ilGenerator.Emit(OpCodes.Conv_R4);
            }
            else if (typeTo.AsType() == typeof(Double))
            {
                if (isFromUnsigned)
                {
                    ilGenerator.Emit(OpCodes.Conv_R_Un);
                }
                ilGenerator.Emit(OpCodes.Conv_R8);
            }
            else
            {
                TypeCode tc = Type.GetTypeCode(typeTo.AsType());
                if (isChecked)
                {
                    // Overflow checking needs to know if the source value on the IL stack is unsigned or not.
                    if (isFromUnsigned)
                    {
                        switch (tc)
                        {
                        case TypeCode.SByte:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_I1_Un);
                            break;

                        case TypeCode.Int16:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_I2_Un);
                            break;

                        case TypeCode.Int32:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_I4_Un);
                            break;

                        case TypeCode.Int64:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_I8_Un);
                            break;

                        case TypeCode.Byte:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_U1_Un);
                            break;

                        case TypeCode.UInt16:
                        case TypeCode.Char:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_U2_Un);
                            break;

                        case TypeCode.UInt32:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_U4_Un);
                            break;

                        case TypeCode.UInt64:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_U8_Un);
                            break;

                        default:
                            throw new InvalidCastException();
                        }
                    }
                    else
                    {
                        switch (tc)
                        {
                        case TypeCode.SByte:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_I1);
                            break;

                        case TypeCode.Int16:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_I2);
                            break;

                        case TypeCode.Int32:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_I4);
                            break;

                        case TypeCode.Int64:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_I8);
                            break;

                        case TypeCode.Byte:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_U1);
                            break;

                        case TypeCode.UInt16:
                        case TypeCode.Char:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_U2);
                            break;

                        case TypeCode.UInt32:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_U4);
                            break;

                        case TypeCode.UInt64:
                            ilGenerator.Emit(OpCodes.Conv_Ovf_U8);
                            break;

                        default:
                            throw new InvalidCastException();
                        }
                    }
                }
                else
                {
                    switch (tc)
                    {
                    case TypeCode.SByte:
                        ilGenerator.Emit(OpCodes.Conv_I1);
                        break;

                    case TypeCode.Byte:
                        ilGenerator.Emit(OpCodes.Conv_U1);
                        break;

                    case TypeCode.Int16:
                        ilGenerator.Emit(OpCodes.Conv_I2);
                        break;

                    case TypeCode.UInt16:
                    case TypeCode.Char:
                        ilGenerator.Emit(OpCodes.Conv_U2);
                        break;

                    case TypeCode.Int32:
                        ilGenerator.Emit(OpCodes.Conv_I4);
                        break;

                    case TypeCode.UInt32:
                        ilGenerator.Emit(OpCodes.Conv_U4);
                        break;

                    case TypeCode.Int64:
                        if (isFromUnsigned)
                        {
                            ilGenerator.Emit(OpCodes.Conv_U8);
                        }
                        else
                        {
                            ilGenerator.Emit(OpCodes.Conv_I8);
                        }
                        break;

                    case TypeCode.UInt64:
                        if (isFromUnsigned || isFromFloatingPoint)
                        {
                            ilGenerator.Emit(OpCodes.Conv_U8);
                        }
                        else
                        {
                            ilGenerator.Emit(OpCodes.Conv_I8);
                        }
                        break;

                    default:
                        throw new InvalidCastException();
                    }
                }
            }
        }
Beispiel #14
0
        public static object DrawValueField(string memberName, Type memberType, object memberValue, Func <string, Type, object, object> fallbackAction = null)
        {
            if (memberValue == null)
            {
                if (memberType.IsValueType)
                {
                    memberValue = Activator.CreateInstance(memberType);
                }
            }

            if (memberType == typeof(int))
            {
                return(EditorGUILayout.IntField(memberName, (int)memberValue));
            }

            if (memberType == typeof(long))
            {
                return(EditorGUILayout.LongField(memberName, (long)memberValue));
            }

            if (memberType == typeof(float))
            {
                return(EditorGUILayout.FloatField(memberName, (float)memberValue));
            }

            if (memberType == typeof(bool))
            {
                return(EditorGUILayout.Toggle(memberName, (bool)memberValue));
            }

            if (memberType == typeof(Vector2))
            {
                return(EditorGUILayout.Vector2Field(memberName, (Vector2)memberValue));
            }

            if (memberType == typeof(Vector3))
            {
                return(EditorGUILayout.Vector3Field(memberName, (Vector3)memberValue));
            }

            if (memberType == typeof(Vector4))
            {
                return(EditorGUILayout.Vector4Field(memberName, (Vector4)memberValue));
            }

            if (memberType == typeof(string))
            {
                return(EditorGUILayout.TextField(memberName, (string)memberValue));
            }

            if (TypeInfoUtils.IsEnum(memberType))
            {
                return(EditorGUILayout.EnumPopup(memberName, (Enum)memberValue));
            }

            var unityObjectType = typeof(Object);

            if (unityObjectType.IsAssignableFrom(memberType))
            {
                return(EditorGUILayout.ObjectField(memberName, (Object)memberValue, memberType, true));
            }

            return(fallbackAction == null
                ? DrawValueFieldFallback(memberName, memberType, memberValue)
                : fallbackAction(memberName, memberType, memberValue));
        }
        private void DrawDictionaryData(DataDictionary dataDictionary, int level)
        {
            var prevIndentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = level;

            Dictionary <object, object> changedValues = null;

            foreach (var key in dataDictionary.Keys)
            {
                var value    = dataDictionary[key];
                var newValue = this.DrawMemberData("Item " + key, dataDictionary.ValueType, value, level);
                if (!Equals(value, newValue))
                {
                    if (changedValues == null)
                    {
                        changedValues = new Dictionary <object, object>();
                    }

                    changedValues[key] = newValue;
                }
            }

            if (changedValues != null)
            {
                foreach (var key in changedValues.Keys)
                {
                    dataDictionary[key] = changedValues[key];
                }
            }

            GUILayout.BeginHorizontal();

            object newKey;

            this.newKeys.TryGetValue(dataDictionary, out newKey);
            var          keyType     = dataDictionary.KeyType;
            const string NewKeyLabel = "New:";

            if (keyType == typeof(string))
            {
                this.newKeys[dataDictionary] = newKey = EditorGUILayout.TextField(NewKeyLabel, (string)newKey);
            }
            else if (TypeInfoUtils.IsEnum(keyType))
            {
                if (newKey == null)
                {
                    newKey = Enum.GetValues(keyType).GetValue(0);
                }

                this.newKeys[dataDictionary] = newKey = EditorGUILayout.EnumPopup(NewKeyLabel, (Enum)newKey);
            }

            if (GUILayout.Button("+") && newKey != null)
            {
                var valueType = dataDictionary.ValueType;
                dataDictionary.Add(newKey, valueType.IsValueType ? Activator.CreateInstance(valueType) : null);
            }

            GUILayout.EndHorizontal();

            EditorGUI.indentLevel = prevIndentLevel;
        }
Beispiel #16
0
        /// <summary>
        ///     Invokes the bound method with the specified arguments.
        /// </summary>
        /// <param name="args">Arguments to invoke the bound method with.</param>
        public void InvokeCommand(params object[] args)
        {
            if (this.command == null)
            {
                return;
            }

            // Add additional arguments if there are any.
            var commandArgs        = args;
            var additionalArgCount = this.AdditionalArguments.Length;

            if (additionalArgCount > 0)
            {
                var argList = new List <object>();
                argList.AddRange(args);
                argList.AddRange(
                    this.AdditionalArguments.Select(
                        additionArgument => additionArgument != null ? additionArgument.Value : null));
                commandArgs = argList.ToArray();
            }

            // Use default parameters if more are required than provided.
            var methodInfo     = TypeInfoUtils.GetMethodInfo(this.command);
            var parameterInfos = methodInfo.GetParameters();

            if (parameterInfos.Length > commandArgs.Length)
            {
                var argList = new List <object>();
                argList.AddRange(commandArgs);
                for (var index = commandArgs.Length; index < parameterInfos.Length; index++)
                {
                    var parameterInfo = parameterInfos[index];
                    var defaultValue  = TypeInfoUtils.IsValueType(parameterInfo.ParameterType)
                        ? Activator.CreateInstance(parameterInfo.ParameterType)
                        : null;
                    argList.Add(defaultValue);
                }

                commandArgs = argList.ToArray();
            }
            // Skip base arguments if less are required.
            else if (parameterInfos.Length < commandArgs.Length)
            {
                var argList = new List <object>();

                var baseArgCount = parameterInfos.Length - additionalArgCount;
                for (var index = 0; index < baseArgCount; index++)
                {
                    argList.Add(args[index]);
                }

                // Add additional arguments.
                argList.AddRange(
                    this.AdditionalArguments.Select(
                        additionArgument => additionArgument != null ? additionArgument.Value : null));

                commandArgs = argList.ToArray();
            }

            try
            {
                // Invoke delegate.
                this.command.DynamicInvoke(commandArgs);
            }
            catch (Exception e)
            {
                if (e is ArgumentException || e is TargetParameterCountException)
                {
                    Debug.LogError(
                        string.Format(
                            "Couldn't invoke command '{0}' with arguments: [{1}]. (Exception: {2})",
                            this.Path,
                            commandArgs.Aggregate(
                                string.Empty,
                                (text, arg) => (string.IsNullOrEmpty(text) ? string.Empty : text + ", ")
                                + (arg != null ? arg.ToString() : "null")),
                            e),
                        this);
                }
                else
                {
                    throw;
                }
            }
        }