void PushConstructor(ConstructorInfo cons) { ParameterInfo[] allParams = cons.GetParameters(); string szCallParam = string.Empty; Type nParamType; if (allParams != null) { for (int i = 0; i < allParams.Length; ++i) { ParameterInfo param = allParams[i]; nParamType = param.ParameterType; PushNameSpace(nParamType.Namespace); PushDelayType(nParamType); PushRefType(nParamType); if (i > 0) { szCallParam += ','; } FCValueType value = FCValueType.TransType(nParamType); szCallParam += value.GetTypeName(false); szCallParam = szCallParam + " " + param.Name; } } m_szTempBuilder.AppendFormat(" public {0}({1}){{}}\r\n", FCValueType.GetClassName(m_nClassType), szCallParam); }
public void ExportClass(Type nClassType, string szPathName, bool bPartWrap, bool bOnlyThisApi, Dictionary <string, int> aDontWrapName, Dictionary <string, List <Type> > aTemplateFunc, FCRefClass pRefClass) { m_bPartWrap = bPartWrap; m_bOnlyThisAPI = bOnlyThisApi; m_nClassType = nClassType; m_szPathName = szPathName; m_pRefClass = pRefClass; m_DelayType.Clear(); m_szTempBuilder.Length = 0; m_CurRefNameSpace.Clear(); m_CurRefNameSpacesFlags.Clear(); m_CurDelegate.Clear(); m_CurDontWrapName = aDontWrapName; m_CurSupportTemplateFunc = aTemplateFunc; m_AllExportType[nClassType] = 1; Type nParentType = nClassType.BaseType; m_AllRefType[nParentType] = 1; PushParentType(nParentType); string szParentName = FCValueType.GetClassName(nParentType); if (szParentName == "UnityEvent`1") { szParentName = "UnityEventBase"; } m_szTempBuilder.AppendFormat("\r\nclass {0} : {1}\r\n", FCValueType.GetClassName(nClassType), szParentName); m_szTempBuilder.AppendLine("{"); MakeInnerEnum(); // 分析内部的枚举类 MakeConstructor(); // 分析构造函数 MakeProperty(); // 分析get - set方法 MakeMethod(); // 分析函数 MakeDelegate(); // 成生委托声明 m_szTempBuilder.AppendLine("};\r\n"); // 导出类外的枚举 MakeOuterEnum(); m_szFileBuilder.Length = 0; foreach (string szNameSpace in m_CurRefNameSpace) { if (szNameSpace.IndexOf("UnityEngine") != -1) { if (szNameSpace != "UnityEngine.Events") { continue; } } m_szFileBuilder.AppendFormat("using {0};\r\n", szNameSpace); } m_szFileBuilder.AppendLine(); m_szFileBuilder.Append(m_szTempBuilder.ToString()); File.WriteAllText(m_szPathName, m_szFileBuilder.ToString()); }
void PushConstructor(ConstructorInfo cons, string szParentInitCall) { ParameterInfo[] allParams = cons.GetParameters(); // 如果是有参数的,就要考虑要不是导出 if (allParams != null && allParams.Length > 0) { if (m_bPartWrap) { if (!cons.IsDefined(typeof(PartWrapAttribute), false)) { return; } } // 如果该函数有不导出的标记 if (cons.IsDefined(typeof(DontWrapAttribute), false)) { return; } if (cons.IsDefined(typeof(ObsoleteAttribute), false)) { return; } } string szCallParam = string.Empty; Type nParamType; if (allParams != null) { for (int i = 0; i < allParams.Length; ++i) { ParameterInfo param = allParams[i]; nParamType = param.ParameterType; PushNameSpace(nParamType.Namespace); PushDelayType(nParamType); PushDelegateType(nParamType); PushRefType(nParamType); if (i > 0) { szCallParam += ','; } FCValueType value = FCValueType.TransType(nParamType); szCallParam += value.GetTypeName(false); szCallParam = szCallParam + " " + param.Name; } } if (string.IsNullOrEmpty(szParentInitCall)) { m_szTempBuilder.AppendFormat(" public {0}({1}){{}}\r\n", FCValueType.GetClassName(m_nClassType), szCallParam); } else { m_szTempBuilder.AppendFormat(" public {0}({1}):{2}{{}}\r\n", FCValueType.GetClassName(m_nClassType), szCallParam, szParentInitCall); } }
public void WrapClassEx(Type nClassType, bool bPartWrap, bool bOnlyThisApi) { m_bPartWrap = bPartWrap; m_bOnlyThisAPI = bOnlyThisApi; m_szTempBuilder.Length = 0; string szWrapName = FCValueType.GetClassName(nClassType) + "_wrap"; m_CurWrapClassNames.Add(szWrapName); m_szCurClassName = FCValueType.GetClassName(nClassType); m_nCurClassType = nClassType; WrapSubClass(m_szTempBuilder, nClassType); m_export.ExportClass(nClassType, m_szFCScriptPath + m_szCurClassName + ".cs", bPartWrap, bOnlyThisApi, m_CurDontWrapName); m_CurDontWrapName.Clear(); }
public void ExportClass(Type nClassType, string szPathName, bool bPartWrap, bool bOnlyThisApi, Dictionary <string, int> aDontWrapName) { m_bPartWrap = bPartWrap; m_bOnlyThisAPI = bOnlyThisApi; m_nClassType = nClassType; m_szPathName = szPathName; m_DelayType.Clear(); m_szTempBuilder.Length = 0; m_CurRefNameSpace.Clear(); m_CurRefNameSpacesFlags.Clear(); m_CurDontWrapName = aDontWrapName; m_AllExportType[nClassType] = 1; Type nParentType = nClassType.BaseType; m_AllRefType[nParentType] = 1; m_szTempBuilder.AppendFormat("\r\nclass {0} : {1}\r\n", FCValueType.GetClassName(nClassType), FCValueType.GetClassName(nParentType)); m_szTempBuilder.AppendLine("{"); MakeInnerEnum(); // 分析内部的枚举类 MakeConstructor(); // 分析构造函数 MakeProperty(); // 分析get - set方法 MakeMethod(); // 分析函数 m_szTempBuilder.AppendLine("};\r\n"); // 导出类外的枚举 MakeOuterEnum(); m_szFileBuilder.Length = 0; foreach (string szNameSpace in m_CurRefNameSpace) { m_szFileBuilder.AppendFormat("using {0};\r\n", szNameSpace); } m_szFileBuilder.AppendLine(); m_szFileBuilder.Append(m_szTempBuilder.ToString()); File.WriteAllText(m_szPathName, m_szFileBuilder.ToString()); }
void WrapSubClass(StringBuilder fileData, Type nClassType) { string szWrapName = FCValueType.GetClassName(nClassType) + "_wrap"; m_CurClassFunc.Clear(); m_CurSameName.Clear(); m_CurRefNameSpace.Clear(); m_CurRefNameSpacesFlags.Clear(); PushNameSpace("System"); PushNameSpace("System.Collections.Generic"); PushNameSpace("System.Text"); PushNameSpace("UnityEngine"); PushNameSpace("UnityObject = UnityEngine.Object"); // 给这个家伙换个名字吧 //PushNameSpace("UnityEngine.Rendering"); // 先生成init函数 FieldInfo[] allFields = FCValueType.GetFields(nClassType, m_bOnlyThisAPI); PropertyInfo[] allProperties = FCValueType.GetProperties(nClassType, m_bOnlyThisAPI); MethodInfo[] allMethods = FCValueType.GetMethods(nClassType, m_bOnlyThisAPI); if (allFields != null) { foreach (FieldInfo field in allFields) { PushFieldInfo(field); } } if (allProperties != null) { foreach (PropertyInfo property in allProperties) { PushPropertyInfo(property); } } if (allMethods != null) { m_CurFuncCount.Clear(); string szFuncName = string.Empty; int nFuncCount = 0; foreach (MethodInfo method in allMethods) { szFuncName = method.Name; nFuncCount = 0; m_CurFuncCount.TryGetValue(szFuncName, out nFuncCount); m_CurFuncCount[szFuncName] = nFuncCount + 1; } foreach (MethodInfo method in allMethods) { PushMethodInfo(method); } } MakeEqual(); MakeHash(); MakeReleaseRef(); MakeDel(); MakeNew(); // 生成Init函数 MakeInitFunc(FCValueType.GetClassName(nClassType)); MakeGetObj(); // 生成 _Ty get_obj()函数 MakeWrapClass(szWrapName); }