internal ClassDefinition(string className, ClassMember[] members, bool externalizable, bool dynamic)
		{
			_className = className;
            _members = members;
			_externalizable = externalizable;
			_dynamic = dynamic;
		}
Beispiel #2
0
 public ClassDefinition GetClassDefinition(object instance)
 {
     if (instance is ASObject)
     {
         ClassDefinition classDefinition;
         ASObject aso = instance as ASObject;
         if (aso.IsTypedObject)
         {
             ClassMember[] classMemberList = new ClassMember[aso.Count];
             int i = 0;
             foreach (KeyValuePair<string, object> entry in aso)
             {
                 ClassMember classMember = new ClassMember(entry.Key, BindingFlags.Default, MemberTypes.Custom, null);
                 classMemberList[i] = classMember;
                 i++;
             }
             string customClassName = aso.TypeName;
             classDefinition = new ClassDefinition(customClassName, classMemberList, false, false);
         }
         else
         {
             string customClassName = string.Empty;
             classDefinition = new ClassDefinition(customClassName, ClassDefinition.EmptyClassMembers, false, true);
         }
         if (log.IsDebugEnabled)
             log.Debug(string.Format("Creating class definition for AS object {0}", aso));
         return classDefinition;
     }
     throw new ArgumentException();
 }
        public override ClassDefinition GetClassDefinition(object instance)
        {
            Type type = instance.GetType();
            BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance;
            PropertyInfo[] propertyInfos = type.GetProperties(bindingAttr);
#if !(NET_1_1)
            List<ClassMember> classMemberList = new List<ClassMember>();
#else
            ArrayList classMemberList = new ArrayList();
#endif
            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 = type.FullName;
            customClassName = FluorineConfiguration.Instance.GetCustomClass(customClassName);
#if !(NET_1_1)
            ClassMember[] classMembers = classMemberList.ToArray();
#else
			ClassMember[] classMembers = classMemberList.ToArray(typeof(ClassMember)) as ClassMember[];
#endif
			ClassDefinition classDefinition = new ClassDefinition(customClassName, classMembers, GetIsExternalizable(instance), GetIsDynamic(instance));
            return classDefinition;
        }
Beispiel #4
0
 public object GetValue(object instance, ClassMember member)
 {
     if (instance is ASObject)
     {
         ASObject aso = instance as ASObject;
         if (aso.ContainsKey(member.Name))
             return aso[member.Name];
         string msg = __Res.GetString(__Res.Reflection_MemberNotFound, string.Format("ASObject[{0}]", member.Name));
         if (log.IsDebugEnabled)
         {
             log.Debug(string.Format("Member {0} not found in AS object {1}", member.Name, aso));
         }
         throw new FluorineException(msg);
     }
     throw new ArgumentException();
 }
 public override ClassDefinition GetClassDefinition(object instance)
 {
     //EntityObject eo = instance as EntityObject;
     Type type = instance.GetType();
     BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.DeclaredOnly;
     MemberInfo[] memberInfos = ReflectionUtils.FindMembers(type, MemberTypes.Property, flags, typeof(System.Runtime.Serialization.DataMemberAttribute));
     List<ClassMember> classMemberList = new List<ClassMember>();
     for (int i = 0; i < memberInfos.Length; i++)
     {
         MemberInfo memberInfo = memberInfos[i];
         PropertyInfo pi = memberInfo as PropertyInfo;
         //Do not serialize EntityReferences
         if (pi.PropertyType.IsSubclassOf(typeof(System.Data.Objects.DataClasses.EntityReference)))
             continue;
         object[] attributes = memberInfo.GetCustomAttributes(false);
         ClassMember classMember = new ClassMember(memberInfo.Name, flags, memberInfo.MemberType, attributes);
         classMemberList.Add(classMember);
     }
     string customClassName = type.FullName;
     customClassName = FluorineConfiguration.Instance.GetCustomClass(customClassName);
     ClassMember[] classMembers = classMemberList.ToArray();
     ClassDefinition classDefinition = new ClassDefinition(customClassName, classMembers, GetIsExternalizable(instance), GetIsDynamic(instance));
     return classDefinition;
 }
 public void SetValue(object instance, ClassMember member, object value)
 {
     throw new NotSupportedException();
 }
 public object GetValue(object instance, ClassMember member)
 {
     throw new NotSupportedException();
 }
Beispiel #8
0
        public virtual ClassDefinition GetClassDefinition(object instance)
        {
            ValidationUtils.ArgumentNotNull(instance, "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.GetCustomAttributes(typeof(TransientAttribute), true).Length > 0)
                    continue;
                if (propertyInfo.GetGetMethod() == null || propertyInfo.GetGetMethod().GetParameters().Length > 0)
                {
                    //The gateway will not be able to access this property
                    string msg = __Res.GetString(__Res.Reflection_PropertyIndexFail, string.Format("{0}.{1}", type.FullName, propertyInfo.Name));
#if !SILVERLIGHT
                    if (log.IsWarnEnabled)
                        log.Warn(msg);
#endif
                    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 !SILVERLIGHT
                if (fieldInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length > 0)
                    continue;
#endif
                if (fieldInfo.GetCustomAttributes(typeof(TransientAttribute), 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 = type.FullName;
            customClassName = FluorineConfiguration.Instance.GetCustomClass(customClassName);
            ClassDefinition classDefinition = new ClassDefinition(customClassName, classMembers, GetIsExternalizable(instance), GetIsDynamic(instance));
            return classDefinition;
        }
Beispiel #9
0
 public virtual void SetValue(object instance, ClassMember member, object value)
 {
     ValidationUtils.ArgumentNotNull(instance, "instance");
     Type type = instance.GetType();
     if (member.MemberType == MemberTypes.Property)
     {
         PropertyInfo propertyInfo = type.GetProperty(member.Name, member.BindingFlags);
         propertyInfo.SetValue(instance, value, null);
     }
     if (member.MemberType == MemberTypes.Field)
     {
         FieldInfo fieldInfo = type.GetField(member.Name, member.BindingFlags);
         fieldInfo.SetValue(instance, value);
     }
     string msg = __Res.GetString(__Res.Reflection_MemberNotFound, string.Format("{0}.{1}", type.FullName, member.Name));
     throw new FluorineException(msg);
 }
Beispiel #10
0
 public virtual object GetValue(object instance, ClassMember member)
 {
     ValidationUtils.ArgumentNotNull(instance, "instance");
     Type type = instance.GetType();
     if (member.MemberType == MemberTypes.Property)
     {
         PropertyInfo propertyInfo = type.GetProperty(member.Name, member.BindingFlags);
         object value = propertyInfo.GetValue(instance, null);
         value = HandleAttributes(instance, propertyInfo, value, member.CustomAttributes);
         return value;
     }
     if (member.MemberType == MemberTypes.Field)
     {
         FieldInfo fieldInfo = type.GetField(member.Name, member.BindingFlags);
         object value = fieldInfo.GetValue(instance);
         value = HandleAttributes(instance, fieldInfo, value, member.CustomAttributes);
         return value;
     }
     string msg = __Res.GetString(__Res.Reflection_MemberNotFound, string.Format("{0}.{1}", type.FullName, member.Name));
     throw new FluorineException(msg);
 }
Beispiel #11
0
 public override ClassDefinition GetClassDefinition(object instance)
 {
     ClassDefinition classDefinition = null;
     Type type = instance.GetType();
     //Verify [DataContract] or [Serializable] on type
     bool serializable = IsDataContract(type) || type.IsSerializable;
     if (!serializable && type.Assembly != typeof(AMFWriter).Assembly)
         throw new FluorineException(string.Format("Type {0} was not marked as a data contract.", type.FullName));
     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] as PropertyInfo;
         string name = propertyInfo.Name;
         if (propertyInfo.GetCustomAttributes(typeof(TransientAttribute), true).Length > 0)
             continue;
         if (propertyInfo.GetGetMethod() == null || propertyInfo.GetGetMethod().GetParameters().Length > 0)
         {
             //The gateway will not be able to access this property
             string msg = __Res.GetString(__Res.Reflection_PropertyIndexFail, string.Format("{0}.{1}", type.FullName, propertyInfo.Name));
             if (log.IsWarnEnabled)
                 log.Warn(msg);
             continue;
         }
         object[] customAttributes = propertyInfo.GetCustomAttributes(typeof(System.Runtime.Serialization.DataMemberAttribute), false);
         if ((customAttributes != null) && (customAttributes.Length > 0))
         {
             System.Runtime.Serialization.DataMemberAttribute attribute = (System.Runtime.Serialization.DataMemberAttribute)customAttributes[0];
             if (attribute.Name != null && attribute.Name.Length != 0)
                 name = attribute.Name;
         }
         else
         {
             if (!type.IsSerializable && type.Assembly != typeof(AMFWriter).Assembly)
                 continue;
         }
         if (memberNames.Contains(name))
             continue;
         memberNames.Add(name);
         BindingFlags bf = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
         try
         {
             PropertyInfo propertyInfoTmp = type.GetProperty(name);
         }
         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);
     }
     FieldInfo[] fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
     for (int i = 0; i < fieldInfos.Length; i++)
     {
         FieldInfo fieldInfo = fieldInfos[i] as FieldInfo;
         if (fieldInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length > 0)
             continue;
         if (fieldInfo.GetCustomAttributes(typeof(TransientAttribute), true).Length > 0)
             continue;
         string name = fieldInfo.Name;
         object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(System.Runtime.Serialization.DataMemberAttribute), false);
         if ((customAttributes != null) && (customAttributes.Length > 0))
         {
             System.Runtime.Serialization.DataMemberAttribute attribute = (System.Runtime.Serialization.DataMemberAttribute)customAttributes[0];
             if (attribute.Name != null && attribute.Name.Length != 0)
                 name = attribute.Name;
         }
         else
         {
             if (!type.IsSerializable && type.Assembly != typeof(AMFWriter).Assembly)
                 continue;
         }
         object[] attributes = fieldInfo.GetCustomAttributes(false);
         ClassMember classMember = new ClassMember(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, fieldInfo.MemberType, attributes);
         classMemberList.Add(classMember);
     }
     ClassMember[] classMembers = classMemberList.ToArray();
     string customClassName = type.FullName;
     customClassName = FluorineConfiguration.Instance.GetCustomClass(customClassName);
     classDefinition = new ClassDefinition(customClassName, classMembers, GetIsExternalizable(instance), GetIsDynamic(instance));
     return classDefinition;
 }
Beispiel #12
0
 public void SetValue(object instance, ClassMember member, object value)
 {
     if (instance is ASObject)
     {
         ASObject aso = instance as ASObject;
         aso[member.Name] = value;
     }
     throw new ArgumentException();
 }