Exemplo n.º 1
0
        private void MapMembers()
        {
            // we want to loop through all the attributes on all the members of the source
            var targetMembers = Type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            foreach (var member in targetMembers)
            {
                var attr = member.GetCustomAttribute<SpliceAttribute>(false);
                if (attr != null)
                {
                    var mapping = new MemberMapping(Type, member, attr);
                    Members.Add(member, mapping);
                }
            }

            // we want to loop through all the attributes on all the methods of the source
            var targeMethods = Type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            foreach (var method in targeMethods)
            {
                var attrs = method.GetCustomAttributes<SpliceEventAttribute>(false);
                foreach (var attr in attrs)
                {
                    var mapping = new MethodMapping(Type, method, attr);
                    if (!Methods.ContainsKey(method))
                    {
                        Methods.Add(method, new List<MethodMapping>());
                    }
                    Methods[method].Add(mapping);
                }
            }
        }
Exemplo n.º 2
0
 public void Sever(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
     if (memberMapping.Attribute.DisposeOnSever)
     {
         var bitmap = memberMapping.GetterMethod(target) as Bitmap;
         DisposeBitmap(bitmap);
     }
     memberMapping.SetterMethod(target, null);
 }
Exemplo n.º 3
0
 public void Sever(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
     var reader = memberMapping.GetterMethod(target) as XmlReader;
     if (memberMapping.Attribute.DisposeOnSever)
     {
         reader.Dispose();
     }
     memberMapping.SetterMethod(target, null);
 }
Exemplo n.º 4
0
 public virtual bool Splice(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
     var value = GetValue(context.Resources, resourceId, memberMapping.MemberType);
     if (value != null)
     {
         memberMapping.SetterMethod(target, value);
     }
     return value != null;
 }
Exemplo n.º 5
0
 public override void Sever(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
     if (memberMapping.Attribute.DisposeOnSever)
     {
         var drawable = memberMapping.GetterMethod(target) as Drawable;
         if (drawable != null)
         {
             drawable.Dispose();
         }
     }
     memberMapping.SetterMethod(target, null);
 }
Exemplo n.º 6
0
 public override void Sever(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
     if (memberMapping.Attribute.DisposeOnSever)
     {
         var typedArray = memberMapping.GetterMethod(target) as TypedArray;
         if (typedArray != null)
         {
             typedArray.Recycle();
             typedArray.Dispose();
         }
     }
     memberMapping.SetterMethod(target, null);
 }
Exemplo n.º 7
0
 public bool Splice(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
     var assigned = false;
     var value = context.Resources.GetColor(resourceId);
     if (memberMapping.MemberType.IsAssignableFrom(typeof(Color)))
     {
         memberMapping.SetterMethod(target, value);
         assigned = true;
     }
     else if (memberMapping.MemberType.IsAssignableFrom(typeof(System.Drawing.Color)))
     {
         memberMapping.SetterMethod(target, System.Drawing.Color.FromArgb(value.ToArgb()));
         assigned = true;
     }
     return assigned;
 }
Exemplo n.º 8
0
        public bool Splice(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
        {
            var assigned = false;
            var reader = new WrappedXmlReader(context.Resources.GetXml(resourceId));
            try
            {
                if (memberMapping.MemberType.IsAssignableFrom(typeof(XmlReader)))
                {
                    memberMapping.SetterMethod(target, reader);
                    assigned = true;
                }
                else if (memberMapping.MemberType.IsAssignableFrom(typeof(XmlDocument)))
                {
                    var doc = new XmlDocument();
                    doc.Load(reader);
                    reader.Close();
                    memberMapping.SetterMethod(target, doc);
                    assigned = true;
                }
                else if (memberMapping.MemberType.IsAssignableFrom(typeof(XDocument)))
                {
                    var doc = XDocument.Load(reader);
                    reader.Close();
                    memberMapping.SetterMethod(target, doc);
                    assigned = true;
                }
                else if (memberMapping.MemberType.IsAssignableFrom(typeof(string)))
                {
                    var xml = XDocument.Load(reader).ToString();
                    memberMapping.SetterMethod(target, xml);
                    assigned = true;
                }
            }
            catch (Exception exception)
            {
                reader.Dispose();

                Geneticist.HandleError(
                    exception,
                    "Unable to splice resource '{0}' with id '{1}' to member '{2}'.",
                    context.Resources.GetResourceName(resourceId),
                    resourceId,
                    memberMapping.Member.Name);
            }
            return assigned;
        }
Exemplo n.º 9
0
        public bool Splice(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
        {
            var assigned = false;
            var value = GeneticsExtensions.FindViewById(source, resourceId);
            if (value != null)
            {
                var valueType = value.GetType();
                var memberType = memberMapping.MemberType;

                if (memberType.IsAssignableFrom(valueType))
                {
                    // first see if it a direct inheritance
                    memberMapping.SetterMethod(target, value);
                    assigned = true;
                }
                else if (javaObjectType.IsAssignableFrom(memberType) && javaObjectType.IsAssignableFrom(memberType))
                {
                    // it may be inheritance inside Java
                    memberMapping.SetterMethod(target, value.JavaCast(memberType));
                    assigned = true;
                }
            }
            else
            {
                if (memberMapping.Attribute.Optional)
                {
                    assigned = true;
                    Geneticist.HandleMessage(
                            "Skipping splice of view with id '{0}' for member '{1}'.",
                            context.Resources.GetResourceName(resourceId),
                            memberMapping.Member.Name);
                }
                else
                {
                    Geneticist.HandleError(
                        "Unable to splice view with id '{0}' for member '{1}'.",
                        context.Resources.GetResourceName(resourceId),
                        memberMapping.Member.Name);
                }
            }
            return assigned;
        }
Exemplo n.º 10
0
        public bool Splice(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
        {
            Bitmap bitmap = null;
            try
            {
                bitmap = BitmapFactory.DecodeResource(context.Resources, resourceId);
                memberMapping.SetterMethod(target, bitmap);
            }
            catch (Exception exception)
            {
                DisposeBitmap(bitmap);
                bitmap = null;

                Geneticist.HandleError(
                    exception,
                    "Unable to splice resource '{0}' with id '{1}' to member '{2}'.",
                    context.Resources.GetResourceName(resourceId),
                    resourceId,
                    memberMapping.Member.Name);
            }
            return bitmap != null;
        }
Exemplo n.º 11
0
 public void Sever(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
 }
Exemplo n.º 12
0
 public void Sever(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
     memberMapping.SetterMethod(target, null);
 }
Exemplo n.º 13
0
 public bool Splice(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
     var value = AnimationUtils.LoadAnimation(context, resourceId);
     memberMapping.SetterMethod(target, value);
     return value != null;
 }