Created
January 23, 2017 14:38
-
-
Save seibe/9fabb0c244419bf9bbbd0fe70d1bd14d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary>TypeCheckerTest</summary> | |
/// <author>Seibe TAKAHASHI</author> | |
/// <remarks> | |
/// (c) 2017 Seibe TAKAHASHI. | |
/// This software is released under the MIT License. | |
/// http://opensource.org/licenses/mit-license.php | |
/// </remarks> | |
public class TypeCheckerTest | |
{ | |
[UnityEditor.MenuItem("TypeChecker/SpriteRenderer")] | |
static void CheckSpriteRenderer() | |
{ | |
var type = typeof(UnityEngine.SpriteRenderer); | |
check(type); | |
} | |
[UnityEditor.MenuItem("TypeChecker/Vector4")] | |
static void CheckVector4() | |
{ | |
var type = typeof(UnityEngine.Vector4); | |
check(type); | |
} | |
static void check(System.Type type) | |
{ | |
var builder = new System.Text.StringBuilder(); | |
var methods = type.GetMethods(); | |
foreach (var method in methods) | |
{ | |
if (method.IsStatic) continue; | |
var name = method.Name; | |
if (name.IndexOf("get_") == 0 || name.IndexOf("set_") == 0) continue; | |
var attrs = method.GetCustomAttributes(false); | |
foreach (var attr in attrs) | |
{ | |
if (attr is System.ObsoleteAttribute) goto NextMethod; | |
} | |
foreach (var attr in attrs) | |
{ | |
builder.AppendFormat("[{0}]\n", attr.GetType().Name); | |
} | |
builder.AppendFormat("public {0} {1}(", method.ReturnType.Name, name); | |
var parameters = method.GetParameters(); | |
for (var i = 0; i < parameters.Length; ++i) | |
{ | |
if (i != 0) builder.Append(", "); | |
builder.AppendFormat("{0} {1}", parameters[i].ParameterType.Name, parameters[i].Name); | |
} | |
builder.Append(")\n\n"); | |
NextMethod:; | |
} | |
var properties = type.GetProperties(); | |
foreach (var prop in properties) | |
{ | |
var getter = prop.GetGetMethod(true); | |
var setter = prop.GetSetMethod(true); | |
if (getter != null && setter == null && getter.IsStatic) continue; | |
if (setter != null && getter == null && setter.IsStatic) continue; | |
var attrs = prop.GetCustomAttributes(false); | |
foreach (var attr in attrs) | |
{ | |
if (attr is System.ObsoleteAttribute) goto NextProp; | |
} | |
foreach (var attr in attrs) | |
{ | |
builder.AppendFormat("[{0}]\n", attr.GetType().Name); | |
} | |
builder.AppendFormat("public {0} {1}", prop.PropertyType.Name, prop.Name); | |
var hasGetter = getter != null; | |
var hasSetter = setter != null; | |
if (hasGetter && hasSetter) builder.Append(" [set, get]\n\n"); | |
else if (hasGetter) builder.Append(" [get]\n\n"); | |
else if (hasGetter) builder.Append(" [set]\n\n"); | |
else builder.Append(" []\n\n"); | |
NextProp:; | |
} | |
var fields = type.GetFields(); | |
foreach (var field in fields) | |
{ | |
if (field.IsStatic) continue; | |
var attrs = field.GetCustomAttributes(false); | |
foreach (var attr in attrs) | |
{ | |
if (attr is System.ObsoleteAttribute) goto NextProp; | |
} | |
foreach (var attr in attrs) | |
{ | |
builder.AppendFormat("[{0}]\n", attr.GetType().Name); | |
} | |
builder.AppendFormat("public {0} {1}\n\n", field.FieldType.Name, field.Name); | |
NextProp:; | |
} | |
UnityEngine.Debug.Log(builder.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment