Esempio n. 1
0
		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;
		}
Esempio n. 2
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();
		}
Esempio n. 3
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();
		}
Esempio n. 4
0
		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;
		}
Esempio n. 5
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();
		}
Esempio n. 6
0
		public void SetValue(object instance, ClassMember member, object value) {
			throw new NotSupportedException();
		}
Esempio n. 7
0
		public object GetValue(object instance, ClassMember member) {
			throw new NotSupportedException();
		}
Esempio n. 8
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);
		}
Esempio n. 9
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;
		}
Esempio n. 10
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);
		}
Esempio n. 11
0
		internal ClassDefinition(string className, ClassMember[] members, bool externalizable, bool dynamic) {
			_className = className;
			_members = members;
			_externalizable = externalizable;
			_dynamic = dynamic;
		}