예제 #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;
		}
예제 #2
0
		public ClassDefinition GetClassDefinition(object instance) {
			Type type = instance.GetType();
			string customClassName = type.FullName;
			customClassName = FluorineConfiguration.Instance.GetCustomClass(customClassName);
			ClassDefinition classDefinition = new ClassDefinition(customClassName, ClassDefinition.EmptyClassMembers, true, false);
			return classDefinition;
		}
예제 #3
0
		public AMF3ReflectionOptimizer(Type type, ClassDefinition classDefinition, AMFReader reader, object instance) {
			_classDefinition = classDefinition;
			_createInstanceMethod = CreateCreateInstanceMethod(type);
#if !(MONO) && !(NET_2_0) && !(NET_3_5) && !(SILVERLIGHT)
			_ps = new PermissionSet(PermissionState.None);
			_ps.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
#endif
			_readDataMethod = CreateReadDataMethod(type, reader, instance);
		}
예제 #4
0
		public IReflectionOptimizer GetReflectionOptimizer(Type type, ClassDefinition classDefinition, AMFReader reader, object instance) {
#if NET_1_1
            return null;

#else
			if (classDefinition == null)
				return new AMF0ReflectionOptimizer(type, reader, instance);
			else
				return new AMF3ReflectionOptimizer(type, classDefinition, reader, instance);
#endif
		}
예제 #5
0
		public object ReadData(AMFReader reader, ClassDefinition classDefinition) {
			ASObject aso = new ASObject(_typeIdentifier);
			reader.AddAMF3ObjectReference(aso);
			string key = reader.ReadAMF3String();
			aso.TypeName = _typeIdentifier;
			while (key != string.Empty) {
				object value = reader.ReadAMF3Data();
				aso.Add(key, value);
				key = reader.ReadAMF3String();
			}
			return aso;
		}
예제 #6
0
		public object ReadData(AMFReader reader, ClassDefinition classDefinition) {
			object instance = ObjectFactory.CreateInstance(classDefinition.ClassName);
			if (instance == null) {
				string msg = __Res.GetString(__Res.Type_InitError, classDefinition.ClassName);
				throw new FluorineException(msg);
			}
			reader.AddAMF3ObjectReference(instance);
			if (instance is IExternalizable) {
				IExternalizable externalizable = instance as IExternalizable;
				DataInput dataInput = new DataInput(reader);
				externalizable.ReadExternal(dataInput);
				return instance;
			} else {
				string msg = __Res.GetString(__Res.Externalizable_CastFail, instance.GetType().FullName);
				throw new FluorineException(msg);
			}
		}
예제 #7
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;
		}
예제 #8
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();
		}
예제 #9
0
		public object ReadData(AMFReader reader, ClassDefinition classDefinition) {
			object obj = reader.ReadAMF3Object(classDefinition);
			return obj;
		}
예제 #10
0
		public object ReadData(AMFReader reader, ClassDefinition classDefinition) {
			ASObject asObject = reader.ReadASObject();
			asObject.TypeName = _typeIdentifier;
			return asObject;
		}
예제 #11
0
		public object ReadData(AMFReader reader, ClassDefinition classDefinition) {
			return _readDataMethod(reader, classDefinition);
		}
예제 #12
0
		public IReflectionOptimizer GetReflectionOptimizer(Type type, ClassDefinition classDefinition, AMFReader reader, object instance) {
			if (classDefinition == null)
				return new AMF0ReflectionOptimizer(type, reader).Generate(instance);
			else
				return new AMF3ReflectionOptimizer(type, classDefinition, reader).Generate(instance);
		}
예제 #13
0
		public AMF3ReflectionOptimizer(Type type, ClassDefinition classDefinition, AMFReader reader)
			: base(type, reader) {
			_classDefinition = classDefinition;
		}
예제 #14
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;
		}