|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq; |
| 4 | +using System.Linq.Expressions; |
| 5 | +using System.Reflection; |
4 | 6 | using System.Text; |
5 | 7 |
|
6 | 8 | using Android.Runtime; |
7 | 9 |
|
| 10 | +using Java.Interop; |
| 11 | +using Java.Interop.Expressions; |
| 12 | + |
8 | 13 | namespace Android.Graphics |
9 | 14 | { |
| 15 | + [JniValueMarshaler (typeof (ColorValueMarshaler))] |
10 | 16 | public struct Color |
11 | 17 | { |
12 | 18 | private int color; |
@@ -386,4 +392,50 @@ public static void RGBToHSV (int red, int green, int blue, float[] hsv) |
386 | 392 | public static Color YellowGreen { get { return new Color (0xFF9ACD32); } } |
387 | 393 | #endregion |
388 | 394 | } |
| 395 | + |
| 396 | + public class ColorValueMarshaler : JniValueMarshaler<Color> |
| 397 | + { |
| 398 | + public override Type MarshalType { |
| 399 | + get { return typeof (int); } |
| 400 | + } |
| 401 | + |
| 402 | + public override Color CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type targetType) |
| 403 | + { |
| 404 | + throw new NotImplementedException (); |
| 405 | + } |
| 406 | + |
| 407 | + public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (Color value, ParameterAttributes synchronize) |
| 408 | + { |
| 409 | + throw new NotImplementedException (); |
| 410 | + } |
| 411 | + |
| 412 | + public override void DestroyGenericArgumentState (Color value, ref JniValueMarshalerState state, ParameterAttributes synchronize) |
| 413 | + { |
| 414 | + throw new NotImplementedException (); |
| 415 | + } |
| 416 | + |
| 417 | + public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type targetType) |
| 418 | + { |
| 419 | + var c = typeof (Color).GetConstructor (new[]{typeof (int)}); |
| 420 | + var v = Expression.Variable (typeof (Color), sourceValue.Name + "_val"); |
| 421 | + context.LocalVariables.Add (v); |
| 422 | + context.CreationStatements.Add (Expression.Assign (v, Expression.New (c, sourceValue))); |
| 423 | + |
| 424 | + return v; |
| 425 | + } |
| 426 | + |
| 427 | + public override Expression CreateParameterFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize) |
| 428 | + { |
| 429 | + var r = Expression.Variable (MarshalType, sourceValue.Name + "_p"); |
| 430 | + context.LocalVariables.Add (r); |
| 431 | + context.CreationStatements.Add (Expression.Assign (r, Expression.Field (sourceValue, "color"))); |
| 432 | + |
| 433 | + return r; |
| 434 | + } |
| 435 | + |
| 436 | + public override Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue) |
| 437 | + { |
| 438 | + return CreateParameterFromManagedExpression (context, sourceValue, 0); |
| 439 | + } |
| 440 | + } |
389 | 441 | } |
0 commit comments