//The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single. public string getWrappedFile(Type type) { string forwardToType = type.FullName; // "UnityEngine."+ type.Name; forwardToType = forwardToType.Replace("+", "."); //handle inner classes per http://msdn.microsoft.com/en-us/library/w3f99sx1(v=vs.110).aspx PropertyInfo[] properties = type.GetProperties(BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.SetProperty | BindingFlags.GetProperty | BindingFlags.Public); var gettersSetters = new StringBuilder(); foreach (PropertyInfo property in properties) { //string propForward = "UnityEngine." + forwardToType;//not sue why the method info works and this doesn' if (property.CanRead || property.CanWrite) { string name = property.Name; string possibleGetter = property.CanRead ? string.Format("get {{ return {0}.{1}; }}", forwardToType, name) : ""; string possibleSetter = property.CanWrite ? string.Format("set {{ {0}.{1} = value; }}", forwardToType, name) : ""; string stringProp = string.Format("\n public static {0} {1} {{\n {2}\n {3}\n}}", property.PropertyType, property.Name, possibleGetter, possibleSetter); if (debug) { Debug.Log("Prop: " + stringProp); } gettersSetters.Append(stringProp); } } var funcitons = new StringBuilder(); MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static); var specialMethods = new List <MethodInfo>(); foreach (MethodInfo methodInfo in methods) { if (methodInfo.IsSpecialName) //do not add the getters/setters, as those are added another way { specialMethods.Add(methodInfo); continue; } string functionDef = new MethodRepresentation(methodInfo, forwardToType).functionString; funcitons.Append(functionDef); if (debug) { Debug.Log(functionDef); } } string header = string.Format(headerFormat, type.Name); string fullFile = string.Format("{0}\n{1}\n{2}\n{3}", header, gettersSetters, funcitons, footer); fullFile = fullFile.Replace("System.Single&", "float"); //ugh fullFile = fullFile.Replace("System.Void", "void"); return(fullFile.Replace("\r\n", "\n")); //could do the other way around, but just want the line endings to be the same }
//The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single. public string getWrappedFile(Type type) { string forwardToType = type.FullName; // "UnityEngine."+ type.Name; forwardToType = forwardToType.Replace("+", "."); //handle inner classes per http://msdn.microsoft.com/en-us/library/w3f99sx1(v=vs.110).aspx PropertyInfo[] properties = type.GetProperties(BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.SetProperty | BindingFlags.GetProperty | BindingFlags.Public); var gettersSetters = new StringBuilder(); foreach(PropertyInfo property in properties) { //string propForward = "UnityEngine." + forwardToType;//not sue why the method info works and this doesn' if(property.CanRead || property.CanWrite) { string name = property.Name; string possibleGetter = property.CanRead ? string.Format("get {{ return {0}.{1}; }}", forwardToType, name) : ""; string possibleSetter = property.CanWrite ? string.Format("set {{ {0}.{1} = value; }}", forwardToType, name) : ""; string stringProp = string.Format("\n public static {0} {1} {{\n {2}\n {3}\n}}", property.PropertyType, property.Name, possibleGetter, possibleSetter); if(debug) Debug.Log("Prop: " + stringProp); gettersSetters.Append(stringProp); } } var funcitons = new StringBuilder(); MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.Static); var specialMethods = new List<MethodInfo>(); foreach(MethodInfo methodInfo in methods) { if(methodInfo.IsSpecialName) //do not add the getters/setters, as those are added another way { specialMethods.Add(methodInfo); continue; } string functionDef = new MethodRepresentation(methodInfo, forwardToType).functionString; funcitons.Append(functionDef); if(debug) Debug.Log(functionDef); } string header = string.Format(headerFormat, type.Name); string fullFile = string.Format("{0}\n{1}\n{2}\n{3}", header, gettersSetters, funcitons, footer); fullFile = fullFile.Replace("System.Single&", "float"); //ugh fullFile = fullFile.Replace("System.Void", "void"); return fullFile.Replace("\r\n", "\n"); //could do the other way around, but just want the line endings to be the same }