private string RegVarInternal(object target, string varName, MemberInfo member, bool isMaths) { VariableData data = new VariableData(); data.target = target; data.member = member; mAliases.Clear(); mCachedErrors.Remove(0, mCachedErrors.Length); if (string.IsNullOrEmpty(varName)) { mAliases.Add(member.Name); StringEnricherAliasAttribute[] aliases = member.GetCustomAttributes(typeof(StringEnricherAliasAttribute), false) as StringEnricherAliasAttribute[]; for (int i = 0, imax = aliases == null ? 0 : aliases.Length; i < imax; i++) { StringEnricherAliasAttribute alias = aliases[i]; for (int j = 0, jmax = alias.alias.Length; j < jmax; j++) { string a = alias.alias[j]; if (!mAliases.Contains(a)) { mAliases.Add(a); } } } } else { mAliases.Add(varName); } Dictionary <string, VariableData> vars = isMaths ? mMathVariables : mVariables; for (int i = 0, imax = mAliases.Count; i < imax; i++) { string alias = mAliases[i]; if (vars.ContainsKey(alias)) { mCachedErrors.AppendLine(string.Format("Variable with the name '{0}' is already existed !", alias)); continue; } vars.Add(alias, data); } mAliases.Clear(); string ret = mCachedErrors.Length > 0 ? mCachedErrors.ToString() : null; mCachedErrors.Remove(0, mCachedErrors.Length); return(ret); }
private string RegFunc(object target, string funcName, MethodInfo method) { if (method.IsGenericMethod || method.ContainsGenericParameters) { return("Generic method is not supported !"); } if (method.ReturnType != s_type_string) { return(string.Format("Function '{0}' should return a string !", method.Name)); } ParameterInfo[] paras = method.GetParameters(); FunctionData funcData = new FunctionData(); funcData.target = target; funcData.method = method; funcData.paraTypes = new List <eParaType>(); funcData.hasArrayParams = false; //Debug.Log("method name : " + method.Name); for (int j = 0, jmax = paras.Length - 1; j <= jmax; j++) { ParameterInfo para = paras[j]; Type tParam = para.ParameterType; //Debug.Log("method para type : " + tParam); eParaType eType = eParaType.Unsupported; if (tParam.IsArray) { if (j == jmax) { eType = GetParaType(tParam.GetElementType()); funcData.hasArrayParams = true; //Debug.Log(GetParaType(tParam.GetElementType()) + " array"); } else { return("Array can only be the last param"); } } else { eType = GetParaType(tParam); //Debug.LogWarning(GetParaType(tParam)); } if (eType == eParaType.Unsupported) { return(string.Format("Type '{0}' not supportted !", tParam)); } funcData.paraTypes.Add(eType); } mAliases.Clear(); mCachedErrors.Remove(0, mCachedErrors.Length); if (string.IsNullOrEmpty(funcName)) { mAliases.Add(method.Name); StringEnricherAliasAttribute[] aliases = method.GetCustomAttributes(typeof(StringEnricherAliasAttribute), false) as StringEnricherAliasAttribute[]; for (int i = 0, imax = aliases == null ? 0 : aliases.Length; i < imax; i++) { StringEnricherAliasAttribute alias = aliases[i]; for (int j = 0, jmax = alias.alias.Length; j < jmax; j++) { string a = alias.alias[j]; if (!mAliases.Contains(a)) { mAliases.Add(a); } } } } else { mAliases.Add(funcName); } for (int i = 0, imax = mAliases.Count; i < imax; i++) { string alias = mAliases[i]; string key = string.Format("{0}:{1}{2}", alias, funcData.paraTypes.Count, funcData.hasArrayParams ? "+" : ""); if (mFunctions.ContainsKey(key)) { mCachedErrors.AppendLine(string.Format("Method ({0}) with same name, param amount but different para type is not supportted !", alias)); continue; } mFunctions.Add(key, funcData); } mAliases.Clear(); string ret = mCachedErrors.Length > 0 ? mCachedErrors.ToString() : null; mCachedErrors.Remove(0, mCachedErrors.Length); return(ret); }