This type supports the Fluorine infrastructure and is not intended to be used directly from your code.
        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;
        }
Example #2
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);
 }
Example #3
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 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;
 }
        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);
        }
Example #6
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);
            return new AMF3ReflectionOptimizer(type, classDefinition, reader, instance);
            #endif
        }
 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;
 }
 public object ReadData(AMFReader reader, ClassDefinition classDefinition)
 {
     var instance = ObjectFactory.CreateInstance(classDefinition.ClassName);
     if (instance == null) {
         throw new FluorineException(String.Format(Resources.Type_InitError, classDefinition.ClassName));
     }
     reader.AddAMF3ObjectReference(instance);
     if (instance is IExternalizable)
     {
         var externalizable = instance as IExternalizable;
         var dataInput = new DataInput(reader);
         externalizable.ReadExternal(dataInput);
         return instance;
     }
     throw new FluorineException(String.Format(Resources.Externalizable_CastFail, instance.GetType().FullName));
 }
 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);
     }
 }
 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 object ReadData(AMFReader reader, ClassDefinition classDefinition)
 {
     object amfObject = reader.ReadObject();
     return amfObject;
 }
Example #12
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;
 }
		public AMF3ReflectionOptimizer(Type type, ClassDefinition classDefinition, AMFReader reader) : base(type, reader)
		{
            _classDefinition = classDefinition;
		}
Example #14
0
 public override ClassDefinition GetClassDefinition(object instance)
 {
     var type = instance.GetType();
     //Verify [DataContract] or [Serializable] on type
     var 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));
     var memberNames = new List<string>();
     var classMemberList = new List<ClassMember>();
     var propertyInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
     foreach (var propertyInfo in propertyInfos) {
         var 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
             var msg = String.Format(Resources.Reflection_PropertyIndexFail, string.Format("{0}.{1}", type.FullName, propertyInfo.Name));
             if (Log.IsWarnEnabled)
                 Log.Warn(msg);
             continue;
         }
         var customAttributes = propertyInfo.GetCustomAttributes(typeof(System.Runtime.Serialization.DataMemberAttribute), false);
         if ((customAttributes != null) && (customAttributes.Length > 0))
         {
             var attribute = (System.Runtime.Serialization.DataMemberAttribute)customAttributes[0];
             if (!String.IsNullOrEmpty(attribute.Name))
                 name = attribute.Name;
         }
         else
         {
             if (!type.IsSerializable && type.Assembly != typeof(AMFWriter).Assembly)
                 continue;
         }
         if (memberNames.Contains(name))
             continue;
         memberNames.Add(name);
         var bf = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
         try
         {
             var propertyInfoTmp = type.GetProperty(name);
         }
         catch (AmbiguousMatchException)
         {
             bf = BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance;
         }
         var attributes = propertyInfo.GetCustomAttributes(false);
         var classMember = new ClassMember(name, bf, propertyInfo.MemberType, attributes);
         classMemberList.Add(classMember);
     }
     var fieldInfos = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
     foreach (var fieldInfo in fieldInfos) {
         if (fieldInfo.GetCustomAttributes(typeof(NonSerializedAttribute), true).Length > 0)
             continue;
         if (fieldInfo.GetCustomAttributes(typeof(TransientAttribute), true).Length > 0)
             continue;
         var name = fieldInfo.Name;
         var customAttributes = fieldInfo.GetCustomAttributes(typeof(System.Runtime.Serialization.DataMemberAttribute), false);
         if ((customAttributes != null) && (customAttributes.Length > 0))
         {
             var attribute = (System.Runtime.Serialization.DataMemberAttribute)customAttributes[0];
             if (!String.IsNullOrEmpty(attribute.Name))
                 name = attribute.Name;
         }
         else
         {
             if (!type.IsSerializable && type.Assembly != typeof(AMFWriter).Assembly)
                 continue;
         }
         var attributes = fieldInfo.GetCustomAttributes(false);
         var classMember = new ClassMember(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, fieldInfo.MemberType, attributes);
         classMemberList.Add(classMember);
     }
     var classMembers = classMemberList.ToArray();
     var customClassName = type.FullName;
     customClassName = FluorineConfiguration.Instance.GetCustomClass(customClassName);
     var classDefinition = new ClassDefinition(customClassName, classMembers, GetIsExternalizable(instance), GetIsDynamic(instance));
     return classDefinition;
 }
 public virtual object ReadData(AMFReader reader, ClassDefinition classDefinition)
 {
     return _readDataMethod(reader, classDefinition);
 }
Example #16
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;
        }
 public object ReadData(AMFReader reader, ClassDefinition classDefinition)
 {
     var asObject = reader.ReadASObject();
     asObject.Alias = _typeIdentifier;
     return asObject;
 }
 public object ReadData(AMFReader reader, ClassDefinition classDefinition)
 {
     object obj = reader.ReadAMF3Object(classDefinition);
     return obj;
 }
 public object ReadData(AMFReader reader, ClassDefinition classDefinition)
 {
     ASObject asObject = reader.ReadASObject();
     asObject.TypeName = _typeIdentifier;
     return asObject;
 }