public static void GenerateCode(object obj, StreamWriter stream, string indent, string var, object parent, string paramName) { Debug.Check(obj != null); Type type = obj.GetType(); Debug.Check(Plugin.IsCustomClassType(type)); MethodDef method = parent as MethodDef; IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave)) { object member = property.GetValue(obj); if (property.Attribute is DesignerStruct) { GenerateCode(member, stream, indent, var + "." + property.Property.Name, parent, paramName); } else { bool bStructProperty = false; if (method != null) { MethodDef.Param param = method.GetParam(paramName, property); if (param != null) { bStructProperty = true; ParameterCsExporter.GenerateCode(param, stream, indent, string.Empty, var + "." + property.Property.Name, string.Empty); } } if (!bStructProperty) { DataCsExporter.GenerateCode(member, stream, indent, string.Empty, var + "." + property.Property.Name, string.Empty); } } } } }
public static void GenerateClassConstructor(Behaviac.Design.MethodDef method, StreamWriter stream, string indent, string var) { Debug.Check(!string.IsNullOrEmpty(var)); if (method.Params.Count == 0) { return; } string paramsName = getParamsName(var, ""); if (!method.IsPublic) { stream.WriteLine("{0}\t\t\t{1} = new object[{2}];", indent, paramsName, method.Params.Count); } for (int i = 0; i < method.Params.Count; ++i) { // const value if (!method.Params[i].IsProperty && !method.Params[i].IsPar) { object obj = method.Params[i].Value; if (obj != null) { string param = getParamName(var, "", i); string paramName = string.Format("{0}[{1}]", paramsName, i); Type type = obj.GetType(); if (Plugin.IsArrayType(type)) { string typename = DataCsExporter.GetGeneratedNativeType(method.Params[i].NativeType); int startIndex = typename.IndexOf('<'); int endIndex = typename.LastIndexOf('>'); string itemType = typename.Substring(startIndex + 1, endIndex - startIndex - 1); ArrayCsExporter.GenerateCode(obj, stream, indent + "\t\t\t", itemType, param); if (!method.IsPublic) { stream.WriteLine("{0}\t\t\t{1} = {2};", indent, paramName, param); } } else if (Plugin.IsCustomClassType(type)) { if (DesignerStruct.IsPureConstDatum(obj, method, method.Params[i].Name)) { if (obj is Behaviac.Design.Agent) { stream.WriteLine("{0}\t\t\t{1} = null;", indent, param); } StructCsExporter.GenerateCode(obj, stream, indent + "\t\t\t", param, null, ""); if (!method.IsPublic) { stream.WriteLine("{0}\t\t\t{1} = {2};", indent, paramName, param); } } } else { string retStr = DataCsExporter.GenerateCode(obj, stream, string.Empty, method.Params[i].NativeType, string.Empty, string.Empty); if (!method.IsPublic) { param = paramName; } stream.WriteLine("{0}\t\t\t{1} = {2};", indent, param, retStr); } } } } }
public static void GenerateCode(object obj, DefaultObject defaultObj, StreamWriter stream, string indent, string var, string typename, object parent, string paramName) { Debug.Check(obj != null); Type type = obj.GetType(); Debug.Check(Plugin.IsCustomClassType(type)); if (!Plugin.IsRefType(type)) { stream.WriteLine("{0}{1} = new {2}();", indent, var, typename); } MethodDef method = parent as MethodDef; IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(type); foreach (DesignerPropertyInfo property in properties) { if (!property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoSave)) { object member = property.GetValue(obj); Type memberType = member.GetType(); if (Plugin.IsArrayType(memberType)) { string memberNativeType = Plugin.GetNativeTypeName(memberType); string nativeTypeStr = DataCsExporter.GetGeneratedNativeType(memberNativeType); int startIndex = nativeTypeStr.IndexOf('<'); int endIndex = nativeTypeStr.LastIndexOf('>'); string itemType = nativeTypeStr.Substring(startIndex + 1, endIndex - startIndex - 1); ArrayCsExporter.GenerateCode(member, defaultObj, stream, indent, itemType, var + "." + property.Property.Name); } else { if (property.Attribute is DesignerStruct) { string memberTypeStr = DataCsExporter.GetGeneratedNativeType(member.GetType()); GenerateCode(member, defaultObj, stream, indent, var + "." + property.Property.Name, memberTypeStr, parent, paramName); } else { bool bStructProperty = false; if (method != null) { MethodDef.Param param = method.GetParam(paramName, property); if (param != null) { bStructProperty = true; ParameterCsExporter.GenerateCode(defaultObj, param, stream, indent, string.Empty, var + "." + property.Property.Name, string.Empty); } } if (!bStructProperty) { DataCsExporter.GenerateCode(member, defaultObj, stream, indent, string.Empty, var + "." + property.Property.Name, string.Empty); } } } } } }