public static bool Convert(object value, Type to) { if (value == null) { value = null; return(PropertyReference.Convert(ref value, to, to)); } return(PropertyReference.Convert(ref value, value.GetType(), to)); }
static public int Convert_s(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (matchType(l, argc, 1, typeof(System.Object), typeof(System.Type))) { System.Object a1; checkType(l, 1, out a1); System.Type a2; checkType(l, 2, out a2); var ret = PropertyReference.Convert(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } else if (matchType(l, argc, 1, typeof(System.Type), typeof(System.Type))) { System.Type a1; checkType(l, 1, out a1); System.Type a2; checkType(l, 2, out a2); var ret = PropertyReference.Convert(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 3) { System.Object a1; checkType(l, 1, out a1); System.Type a2; checkType(l, 2, out a2); System.Type a3; checkType(l, 3, out a3); var ret = PropertyReference.Convert(ref a1, a2, a3); pushValue(l, true); pushValue(l, ret); pushValue(l, a1); return(3); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
private bool Convert(ref object value) { if (this.mTarget == null) { return(false); } Type propertyType = this.GetPropertyType(); Type from; if (value == null) { if (!propertyType.IsClass) { return(false); } from = propertyType; } else { from = value.GetType(); } return(PropertyReference.Convert(ref value, from, propertyType)); }
/// <summary> /// Collect a list of usable properties and fields. /// </summary> static public List <Entry> GetProperties(GameObject target, bool read, bool write) { Component[] comps = target.GetComponents <Component>(); List <Entry> list = new List <Entry>(); for (int i = 0, imax = comps.Length; i < imax; ++i) { Component comp = comps[i]; if (comp == null) { continue; } Type type = comp.GetType(); BindingFlags flags = BindingFlags.Instance | BindingFlags.Public; FieldInfo[] fields = type.GetFields(flags); PropertyInfo[] props = type.GetProperties(flags); // The component itself without any method if (PropertyReference.Convert(comp, filter)) { Entry ent = new Entry(); ent.target = comp; list.Add(ent); } for (int b = 0; b < fields.Length; ++b) { FieldInfo field = fields[b]; if (filter != typeof(void)) { if (canConvert) { if (!PropertyReference.Convert(field.FieldType, filter)) { continue; } } else if (!filter.IsAssignableFrom(field.FieldType)) { continue; } } Entry ent = new Entry(); ent.target = comp; ent.name = field.Name; list.Add(ent); } for (int b = 0; b < props.Length; ++b) { PropertyInfo prop = props[b]; if (read && !prop.CanRead) { continue; } if (write && !prop.CanWrite) { continue; } if (filter != typeof(void)) { if (canConvert) { if (!PropertyReference.Convert(prop.PropertyType, filter)) { continue; } } else if (!filter.IsAssignableFrom(prop.PropertyType)) { continue; } } Entry ent = new Entry(); ent.target = comp; ent.name = prop.Name; list.Add(ent); } } return(list); }
public static bool Convert(Type from, Type to) { object obj = null; return(PropertyReference.Convert(ref obj, from, to)); }
public override void OnInspectorGUI() { PropertyBinding pb = target as PropertyBinding; NGUIEditorTools.SetLabelWidth(80f); serializedObject.Update(); if (pb.direction == PropertyBinding.Direction.TargetUpdatesSource && pb.target != null) { PropertyReferenceDrawer.filter = pb.target.GetPropertyType(); } GUILayout.Space(3f); PropertyBinding.Direction dir = (target as PropertyBinding).direction; PropertyReferenceDrawer.mustRead = (dir == PropertyBinding.Direction.SourceUpdatesTarget || dir == PropertyBinding.Direction.BiDirectional); PropertyReferenceDrawer.mustWrite = (dir == PropertyBinding.Direction.TargetUpdatesSource || dir == PropertyBinding.Direction.BiDirectional); NGUIEditorTools.DrawProperty(serializedObject, "source"); if (pb.direction == PropertyBinding.Direction.SourceUpdatesTarget && pb.source != null) { PropertyReferenceDrawer.filter = pb.source.GetPropertyType(); } if (pb.source.target != null) { GUILayout.Space(-18f); if (pb.direction == PropertyBinding.Direction.TargetUpdatesSource) { GUILayout.Label(" \u25B2"); // Up } else if (pb.direction == PropertyBinding.Direction.SourceUpdatesTarget) { GUILayout.Label(" \u25BC"); // Down } else { GUILayout.Label(" \u25B2\u25BC"); } } GUILayout.Space(1f); PropertyReferenceDrawer.mustRead = (dir == PropertyBinding.Direction.TargetUpdatesSource || dir == PropertyBinding.Direction.BiDirectional); PropertyReferenceDrawer.mustWrite = (dir == PropertyBinding.Direction.SourceUpdatesTarget || dir == PropertyBinding.Direction.BiDirectional); NGUIEditorTools.DrawProperty(serializedObject, "target"); PropertyReferenceDrawer.mustRead = false; PropertyReferenceDrawer.mustWrite = false; PropertyReferenceDrawer.filter = typeof(void); GUILayout.Space(1f); NGUIEditorTools.DrawPaddedProperty(serializedObject, "direction"); NGUIEditorTools.DrawPaddedProperty(serializedObject, "update"); GUILayout.BeginHorizontal(); NGUIEditorTools.DrawProperty(" ", serializedObject, "editMode", GUILayout.Width(100f)); GUILayout.Label("Update in Edit Mode"); GUILayout.EndHorizontal(); if (!serializedObject.isEditingMultipleObjects) { if (pb.source != null && pb.target != null && pb.source.GetPropertyType() != pb.target.GetPropertyType()) { if (pb.direction == PropertyBinding.Direction.BiDirectional) { EditorGUILayout.HelpBox("Bi-Directional updates require both Source and Target to reference values of the same type.", MessageType.Error); } else if (pb.direction == PropertyBinding.Direction.SourceUpdatesTarget) { if (!PropertyReference.Convert(pb.source.Get(), pb.target.GetPropertyType())) { EditorGUILayout.HelpBox("Unable to convert " + pb.source.GetPropertyType() + " to " + pb.target.GetPropertyType(), MessageType.Error); } } else if (!PropertyReference.Convert(pb.target.Get(), pb.source.GetPropertyType())) { EditorGUILayout.HelpBox("Unable to convert " + pb.target.GetPropertyType() + " to " + pb.source.GetPropertyType(), MessageType.Error); } } } serializedObject.ApplyModifiedProperties(); }
public unsafe static long $Invoke3(long instance, long *args) { return(GCHandledObjects.ObjectToGCHandle(PropertyReference.Convert((Type)GCHandledObjects.GCHandleToObject(*args), (Type)GCHandledObjects.GCHandleToObject(args[1])))); }