예제 #1
0
        public static ObjectWrapper CreateFromObject(TypeRegistry registry, ClassWrapper clazz, object obj)
        {
            Type          type    = obj.GetType();
            ObjectWrapper wrapper = new ObjectWrapper(clazz, obj);

            foreach (MemberInfo info in type.GetMembers(BindingFlags.Instance | BindingFlags.Public))
            {
                switch (info.MemberType)
                {
                case MemberTypes.Method:
                    if (!wrapper.HasAttribute(info.Name))
                    {
                        wrapper.SetAttribute(info.Name, CreateMultiMethod(registry, type, obj,
                                                                          info.Name));
                    }
                    break;

                case MemberTypes.Field:
                    wrapper.SetAttribute(info.Name, FieldWrapper.Create(registry, (FieldInfo)info,
                                                                        obj));
                    break;

                case MemberTypes.Property:
                    wrapper.SetAttribute(info.Name, PropertyWrapper.Create(registry, (PropertyInfo)info,
                                                                           obj));
                    break;
                }
            }
            return(wrapper);
        }
예제 #2
0
        public static ClassWrapper CreateFromType(TypeRegistry registry, Type type, string name)
        {
            ClassWrapper wrapper = new ClassWrapper(registry, type, name);

            foreach (MemberInfo info in type.GetMembers(BindingFlags.Public | BindingFlags.Static))
            {
                switch (info.MemberType)
                {
                case MemberTypes.Method:
                    if (!wrapper.HasAttribute(info.Name))
                    {
                        wrapper.SetAttribute(info.Name, CreateMultiMethod(registry, type, info.Name));
                    }
                    break;

                case MemberTypes.Field:
                    wrapper.SetAttribute(info.Name, FieldWrapper.Create(registry, (FieldInfo)info));
                    break;

                case MemberTypes.Property:
                    wrapper.SetAttribute(info.Name, PropertyWrapper.Create(registry, (PropertyInfo)info));
                    break;
                }
            }

            registry.AddTypeMapping(type, wrapper, new ObjectTypeMapping(wrapper, registry));

            return(wrapper);
        }