(ObjectCheckers objCheckers, ObjectCasters objCasters)
| 61 | } |
| 62 | |
| 63 | public void Init(ObjectCheckers objCheckers, ObjectCasters objCasters) |
| 64 | { |
| 65 | if ((typeof(Delegate) != targetType && typeof(Delegate).IsAssignableFrom(targetType)) || |
| 66 | !method.IsStatic || method.IsConstructor) |
| 67 | { |
| 68 | luaStackPosStart = 2; |
| 69 | if (!method.IsConstructor) |
| 70 | { |
| 71 | targetNeeded = true; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | var paramInfos = method.GetParameters(); |
| 76 | refPos = new int[paramInfos.Length]; |
| 77 | |
| 78 | List<int> inPosList = new List<int>(); |
| 79 | List<int> outPosList = new List<int>(); |
| 80 | |
| 81 | List<ObjectCheck> paramsChecks = new List<ObjectCheck>(); |
| 82 | List<ObjectCast> paramsCasts = new List<ObjectCast>(); |
| 83 | List<bool> isOptionalList = new List<bool>(); |
| 84 | List<object> defaultValueList = new List<object>(); |
| 85 | |
| 86 | for(int i = 0; i < paramInfos.Length; i++) |
| 87 | { |
| 88 | refPos[i] = -1; |
| 89 | if (!paramInfos[i].IsIn && paramInfos[i].IsOut) // out parameter |
| 90 | { |
| 91 | outPosList.Add(i); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | if(paramInfos[i].ParameterType.IsByRef) |
| 96 | { |
| 97 | var ttype = paramInfos[i].ParameterType.GetElementType(); |
| 98 | if(CopyByValue.IsStruct(ttype) && ttype != typeof(decimal)) |
| 99 | { |
| 100 | refPos[i] = inPosList.Count; |
| 101 | } |
| 102 | outPosList.Add(i); |
| 103 | } |
| 104 | |
| 105 | inPosList.Add(i); |
| 106 | var paramType = paramInfos[i].IsDefined(typeof(ParamArrayAttribute), false) || (!paramInfos[i].ParameterType.IsArray && paramInfos[i].ParameterType.IsByRef ) ? |
| 107 | paramInfos[i].ParameterType.GetElementType() : paramInfos[i].ParameterType; |
| 108 | paramsChecks.Add (objCheckers.GetChecker(paramType)); |
| 109 | paramsCasts.Add (objCasters.GetCaster(paramType)); |
| 110 | isOptionalList.Add(paramInfos[i].IsOptional); |
| 111 | var defalutValue = paramInfos[i].DefaultValue; |
| 112 | if (paramInfos[i].IsOptional) |
| 113 | { |
| 114 | if (defalutValue != null && defalutValue.GetType() != paramInfos[i].ParameterType) |
| 115 | { |
| 116 | defalutValue = defalutValue.GetType() == typeof(Missing) ? (paramInfos[i].ParameterType.IsValueType() ? Activator.CreateInstance(paramInfos[i].ParameterType) : Missing.Value) |
| 117 | : Convert.ChangeType(defalutValue, paramInfos[i].ParameterType); |
| 118 | } |
| 119 | HasDefalutValue = true; |
| 120 | } |
no test coverage detected