/** * Add an object to the mapper * When the object is added, call all the mappingWaitings (views which need this object) * * @param name the mapped object name, ex : for function($user), the name will be "user" * @param object the mapped object */ public void MapObject(string name, Object obj) { MappedObjects.AddOrUpdate(name, obj); CarpaccioLogger.d(TAG, "map object [" + name + "," + obj.GetType().Name + "]"); //call the waiting objects List<MappingWaiting> waitingsForThisName = MappingWaitings.GetOrDefault(name); if (waitingsForThisName != null) { foreach (MappingWaiting mappingWaiting in waitingsForThisName) { CarpaccioLogger.d(TAG, "call waiting mapped " + mappingWaiting.CarpaccioAction.CompleteCall); string value = Evaluate(obj, mappingWaiting.Call); CarpaccioLogger.d(TAG, "call waiting value = " + value); if (value != null && MappingManagerCallback != null) { mappingWaiting.CarpaccioAction.Values = new[]{value}; //TODO MappingManagerCallback.CallActionOnView(mappingWaiting.CarpaccioAction, mappingWaiting.View); } } //remove all waitings for this name waitingsForThisName.Clear(); MappingWaitings.Remove(name); } }
public void OnEvent(Java.Lang.Object value, FirebaseFirestoreException error) { if (error != null) { Toast.MakeText(this, error.ToString(), ToastLength.Long).Show(); } else { if (value != null) { if (value.GetType() == typeof(QuerySnapshot)) { var snapshot = (QuerySnapshot)value; if (snapshot != null && !snapshot.Metadata.IsFromCache && snapshot.DocumentChanges != null && snapshot.DocumentChanges.Count() > 0) { var changes = snapshot.DocumentChanges.ToList(); foreach (var change in changes) { System.Diagnostics.Debug.WriteLine("Changed DocumentId: " + change.Document.Id); var changedDocumentData = change.Document.Data; } } } } } }
//object.image.getUrl() public string Evaluate(Object obj, string call) { if (!call.Contains(".")) { //"object" CarpaccioLogger.d(TAG, "call " + call + " on " + obj.GetType().Name); return obj.ToString(); } string function = call.Substring(call.IndexOf('.') + 1); //image.getUrl(); or //image string callToGetObject; if (function.Contains(".")) { callToGetObject = function.Substring(0, function.IndexOf('.')); //image } else { callToGetObject = function; //image } string realCallToGetObject = GetFunctionName(callToGetObject); Object newObject = CarpaccioHelper.callFunction(obj, realCallToGetObject); if (newObject != null) { CarpaccioLogger.d(TAG, "call " + realCallToGetObject + " return =" + newObject.GetType().Name); if (newObject is Java.Lang.String) { return (string) newObject; } if (newObject is Java.Lang.Number) { return String.ValueOf(newObject); } return Evaluate(newObject, function); } CarpaccioLogger.d(TAG, "call " + realCallToGetObject + " return = NULL"); return null; }
public int getValueInt() { if (value.GetType() == typeof(int)) { return(Convert.ToInt32(value)); } //return Integer.class.cast(value); else if (value.GetType() == typeof(float)) { return((int)getValueFloat()); } else { return((int)value); } }
private void AutoCompleteOnItemSelected(object sender, AdapterView.ItemClickEventArgs args) { var view = (AutoCompleteTextView)sender; Java.Lang.Object obj = view.Adapter.GetItem(args.Position); var selectedItemArgs = new SelectedItemChangedEventArgs(obj.GetType().GetProperty("Instance").GetValue(obj, null), args.Position); var element = (AutoCompleteView)Element; Element.Text = NativeControl.Text; //Element.RaiseTextChanged(NativeControl.Text); element.OnItemSelectedInternal(Element, selectedItemArgs); }
public static T Cast <T>(Java.Lang.Object obj) where T : class { var propertyInfo = obj.GetType().GetProperty("Instance"); return(propertyInfo == null ? null : propertyInfo.GetValue(obj, null) as T); }
/** * Called when a view loaded and call a mapping function * * @param view the calling view * @param mappedObject If available, the object to map with the view. Else add the view to mappingWaitings */ public void CallMappingOnView(CarpaccioAction action, View view, Object mappedObject) { if (action.IsCallMapping) { CarpaccioLogger.d(TAG, "callMappingOnView mapping=" + mappedObject + " action=" + action.CompleteCall + " view=" + view.GetType().Name); string arg = action.Args[0]; //only map the first argument string objectName; string call; if (arg.Contains(".")) { //"$user.getName()" call = arg.Substring(1, arg.Length - 1); // "user.getName()" objectName = call.Substring(0, arg.IndexOf('.') - 1); // "user" } else { objectName = arg.Substring(1, arg.Length - 1); // "user" call = objectName; // "user" } //if you already have the object if (mappedObject != null) { string value = Evaluate(mappedObject, call); CarpaccioLogger.d(TAG, "callMappingOnView evaluate(" + call + ")" + " on " + mappedObject.GetType().Name + " returned " + value); action.Values = new[]{value}; //TODO MappingManagerCallback.CallActionOnView(action, view); } else { //add to waiting List<MappingWaiting> waitings = MappingWaitings.GetOrDefault(objectName) ?? new List<MappingWaiting>(); //["user"] = List<MappingWaiting> waitings.Add(new MappingWaiting(view, action, call, objectName)); CarpaccioLogger.d(TAG, "added to waiting " + call + " for " + view.GetType().Name); MappingWaitings.AddOrUpdate(objectName, waitings); } } }
public static T Cast2 <T>(this Object obj) where T : UserCompany { var propertyInfo = obj.GetType().GetProperty("Value"); return(propertyInfo == null ? null : propertyInfo.GetValue(obj, null) as T); }