Пример #1
0
        private static void LoadGenericMethods(Type type)
        {
            var typeInfo = type.GetTypeInfo();

            foreach (var member in typeInfo.GetMembers())
            {
                var gmattr = member.GetCustomAttribute <GenericMethodAttribute>();
                if (gmattr == null)
                {
                    continue;
                }
                var name = gmattr.name;
                var gm   = name == null?GenericMethod.GetBound(member.Name) : GenericMethod.Get(name);

                var method = member.GetMemberType() == MemberTypes.Property
                    ? (member as PropertyInfo).GetGetMethod()
                    : (member as MethodInfo);
                var    types = gmattr.types;
                Type[] paramTypes;
                var    deleg = method.CreateDelegate(type, out paramTypes);
                if (types.IsEmpty())
                {
                    switch (gmattr.methodType)
                    {
                    case GenericMethodType.Method:
                        types = paramTypes;
                        break;

                    case GenericMethodType.Creator:
                        types = method.ReturnType.CreateArray(1);
                        break;

                    case GenericMethodType.Parser:
                        types = method.ReturnType.CreateArray(1);
                        break;

                    default:
                        break;
                    }
                }
                gm.Add(deleg, types);
            }
        }
Пример #2
0
        private static void InitParseFormat()
        {
            Parse  = GenericMethod.Get("Parse", "Parse");
            Format = GenericMethod.Get("Format", "Format");

            AddStringMethods(Unescape, Escape);

            AddStringMethods(bool.Parse);
            AddStringMethods(byte.Parse);
            AddStringMethods(sbyte.Parse);
            AddStringMethods(s => s[0]);
            AddStringMethods(short.Parse);
            AddStringMethods(ushort.Parse);
            AddStringMethods(int.Parse);
            AddStringMethods(uint.Parse);
            AddStringMethods(long.Parse);
            AddStringMethods(ulong.Parse);
            AddStringMethods(decimal.Parse);
            AddStringMethods(float.Parse);
            AddStringMethods(double.Parse);
        }
Пример #3
0
        private static void InitCreate()
        {
            Create = GenericMethod.Get("Create");

            Create.AddCreator(() => "");
        }