Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
 public void Sever(object target, object source, string resourceType, int resourceId, Context context, MemberMapping memberMapping)
 {
     memberMapping.SetterMethod(target, null);
 }
Ejemplo n.º 11
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;
 }