예제 #1
0
        public override ClassDefinition GetClassDefinition(object instance)
        {
            Type         type        = instance.GetType();
            BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance;

            PropertyInfo[] propertyInfos = type.GetProperties(bindingAttr);

            List <ClassMember> classMemberList = new List <ClassMember>();

            for (int i = 0; i < propertyInfos.Length; i++)
            {
                PropertyInfo propertyInfo = propertyInfos[i];
                if (propertyInfo.Name != "HelpLink" && propertyInfo.Name != "TargetSite")
                {
                    ClassMember classMember = new ClassMember(propertyInfo.Name, bindingAttr, propertyInfo.MemberType, null);
                    classMemberList.Add(classMember);
                }
            }
            string customClassName = ObjectFactory.GetCustomClass(type);

            ClassMember[] classMembers = classMemberList.ToArray();

            ClassDefinition classDefinition = new ClassDefinition(customClassName, classMembers, GetIsExternalizable(instance), GetIsDynamic(instance));

            return(classDefinition);
        }
예제 #2
0
        public ClassDefinition GetClassDefinition(object instance)
        {
            Type            type            = instance.GetType();
            string          customClassName = ObjectFactory.GetCustomClass(type);
            ClassDefinition classDefinition = new ClassDefinition(customClassName, ClassDefinition.EmptyClassMembers, true, false);

            return(classDefinition);
        }
예제 #3
0
        public virtual ClassDefinition GetClassDefinition(object instance)
        {
            Type type = instance.GetType();

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Creating class definition for typed {0}", type.FullName);
            sb.Append("{");

            List <string>      memberNames     = new List <string>();
            List <ClassMember> classMemberList = new List <ClassMember>();

            PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            for (int i = 0; i < propertyInfos.Length; i++)
            {
                PropertyInfo propertyInfo = propertyInfos[i];
                string       name         = propertyInfo.Name;

                if (propertyInfo.GetGetMethod() == null || propertyInfo.GetSetMethod() == null || propertyInfo.GetGetMethod().GetParameters().Length > 0)
                {
                    //The gateway will not be able to access this property
                    continue;
                }
                if (memberNames.Contains(name))
                {
                    continue;
                }
                memberNames.Add(name);
                BindingFlags bf = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
                try
                {
                    PropertyInfo propertyInfoTmp = type.GetProperty(name);
                    Unreferenced.Parameter(propertyInfoTmp);
                }
                catch (AmbiguousMatchException)
                {
                    bf = BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance;
                }
                object[]    attributes  = propertyInfo.GetCustomAttributes(false);
                ClassMember classMember = new ClassMember(name, bf, propertyInfo.MemberType, attributes);
                classMemberList.Add(classMember);

                if (i != 0)
                {
                    sb.Append(", ");
                }
                sb.Append(name);
            }
            FieldInfo[] fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
            for (int i = 0; i < fieldInfos.Length; i++)
            {
                FieldInfo fieldInfo = fieldInfos[i];

                if (fieldInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length > 0)
                {
                    continue;
                }
                string      name        = fieldInfo.Name;
                object[]    attributes  = fieldInfo.GetCustomAttributes(false);
                ClassMember classMember = new ClassMember(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, fieldInfo.MemberType, attributes);
                classMemberList.Add(classMember);

                if (i != 0 && propertyInfos.Length > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(name);
            }
            ClassMember[]   classMembers    = classMemberList.ToArray();
            string          customClassName = ObjectFactory.GetCustomClass(type);
            ClassDefinition classDefinition = new ClassDefinition(customClassName, classMembers, GetIsExternalizable(instance), GetIsDynamic(instance));

            return(classDefinition);
        }