Exemplo n.º 1
0
        public static Dictionary<Type, ClassReflectionInfo> GetLibraryClassScriptInfo()
        {
            var ret = new Dictionary<Type, ClassReflectionInfo>();
            var v2 = typeof(Vector2);
            var v3 = typeof(Vector3);
            Func<IEnumerable<Tuple<string, string>>, Type, Dictionary<string, ScriptMethodInfo>> getMethod = (keys, type) =>
                keys.ToDictionary(x => x.Item1, x => new ScriptMethodInfo(type.GetMethod(x.Item2), x.Item1, 0));//scriptName, originalName, type

            ret[v2] = new ClassReflectionInfo(v2,
                getMethod(new[]
                {
                    Tuple.Create("len", "Length"),
                    Tuple.Create("len2", "LengthSquared"),
                }, v2),
                //new Dictionary<string, ScriptMethodInfo>()
                //{
                //	{ "len", new ScriptMethodInfo(v2.GetMethod("Length"), "len", 0)},
                //	{ "len2", new ScriptMethodInfo(v2.GetMethod("LengthSquared"), "len2")},
                //},
                new Dictionary<string, ScriptPropertyInfo>()
                {

                },
                new Dictionary<string, FieldInfo>()
                {
                    {"x", v2.GetField("X")},
                    {"y", v2.GetField("Y")},
                },
                new Dictionary<string, ScriptMethodInfo>()
                {
                });
            ret[v3] = new ClassReflectionInfo(v3,
                //new Dictionary<string, ScriptMethodInfo>()
                //{
                //	{ "len", new ScriptMethodInfo(v3.GetMethod("Length"), "len")},
                //	{ "len2", new ScriptMethodInfo(v3.GetMethod("LengthSquared"), "len2")},
                //},
                getMethod(new[]
                {
                    Tuple.Create("len", "Length"),
                    Tuple.Create("len2", "LengthSquared"),
                }, v3),
                new Dictionary<string, ScriptPropertyInfo>()
                {

                },
                new Dictionary<string, FieldInfo>()
                {
                    {"x", v3.GetField("X")},
                    {"y", v3.GetField("Y")},
                    {"z", v3.GetField("Z")},
                },
                new Dictionary<string, ScriptMethodInfo>()
                {
                });
            return ret;
        }
Exemplo n.º 2
0
        internal static XElement ClassToXml(Type target, ClassReflectionInfo info)
        {
            var root = new XElement("class");
            var atr = Attribute.GetCustomAttribute(target, typeof(ScriptTypeAttribute)) as ScriptTypeAttribute;
            if (atr != null)
            {
                root.Add(NameToXml(target.Name + " (" + atr.Name + ")"));
            }
            else
            {
                root.Add(NameToXml(target.Name));
            }
            var methodRoot = new XElement("methods");
            methodRoot.Add(info.MethodDict.Select(x => MethodToXml(x.Value)).ToArray());
            var propRoot = new XElement("propertys");
            propRoot.Add(info.PropertyDict.Select(x => PropertyToXml(x.Value)).ToArray());
            root.Add(methodRoot, propRoot);

            return root;
        }
Exemplo n.º 3
0
        internal static string OutputClass(ClassReflectionInfo classInfo)
        {
            var str = new StringBuilder();
            string[] itemTypes = { "Method", "Function", "Property" };
            foreach (var item in classInfo.MethodDict.OrderBy(i => i.Key))
            {
                PrintName(str, item.Value.MethodInfo.ReturnType == typeof(float) ? "Function" : "Method", item.Key, item.Value.MethodInfo.Name);
                //str.Append(itemTypes[item.Value.ReturnType == typeof(float) ? 1 : 0]);
                //str.Append(": ");
                //str.Append(item.Key);
                //str.Append(" from ");
                //str.AppendLine(item.Value.Name);
                var attr = item.Value.Attribute;
                var param = item.Value.MethodInfo.GetParameters();
                int index = 0;
                ParameterInfo[] normalParams;
                if (attr.OptionName != null)
                {
                    normalParams = param.Take(param.Length - attr.OptionArgNum.Sum()).ToArray();
                }
                else
                {
                    normalParams = param;
                }
                foreach (var p in normalParams)
                {
                    str.Append(p.Name);
                    str.Append(", ");
                }
                if (normalParams.Length != 0)
                {
                    str.AppendLine();
                }
                index = normalParams.Length;
                if (attr.OptionName != null)
                {
                    for (int i = 0; i < attr.OptionName.Length; i++)
                    {
                        str.Append(attr.OptionName[i]);
                        str.Append(" : ");
                        for (int j = 0; j < attr.OptionArgNum[i]; j++)
                        {
                            str.Append(param[index].Name);
                            str.Append(", ");
                            index++;
                        }
                        str.AppendLine();

                    }
                }
                str.AppendLine();
            }
            foreach (var item in classInfo.PropertyDict)
            {
                //str.Append(itemTypes[2]);
                //str.Append(": ");
                //str.Append(item.Key);
                PrintName(str, "Property", item.Key, item.Value.Name);
                str.AppendLine();
            }
            return str.ToString();
        }
Exemplo n.º 4
0
 void GetTargetInfo()
 {
     if (!ReflectionCashe.ContainsKey(TargetType))
     {
         MakeTargetInfoCache(TargetType);
     }
     ClassInfo = ReflectionCashe[TargetType];
 }
Exemplo n.º 5
0
 /// <summary>
 /// 型情報のキャッシュを作る。明示的に呼ばなくても必要なら作られる
 /// </summary>
 public static void MakeTargetInfoCache(Type target)
 {
     if (ReflectionCashe.ContainsKey(target)) return;
     ReflectionCashe[target] = new ClassReflectionInfo(target);
     var atr = Attribute.GetCustomAttribute(target, typeof(ScriptTypeAttribute)) as ScriptTypeAttribute;
     if (atr != null)
     {
         TypeNameDictionary[atr.Name] = target;
     }
 }