/// <summary> /// Clone Solution. /// </summary> /// <returns>new solution</returns> public Solution Clone() { Solution s = (Solution)ReflectionEx.DeepClone(this); for (int iProject = 0; iProject < s.projects.Count; iProject++) { Project newp = s.projects[iProject]; newp.solution = s; Project oldp = projects[iProject]; // References either solutionRoot or some of project. if (oldp.parent == solutionRoot) { newp.parent = s.solutionRoot; s.solutionRoot.nodes.Add(newp); } else { newp.parent = s.projects[projects.IndexOf(oldp.parent)]; } // References solution projects. for (int i = 0; i < oldp.nodes.Count; i++) { newp.nodes.Add(s.projects[projects.IndexOf(oldp.nodes[i])]); } } return(s); }
public BaseSetter(DependencyObject[] target, PropertyInfo[] pi) { this.Focusable = false; this.Targets = target; this.TargetProperties = pi; if (this.TargetProperties != null) { this.TargetDependencyProperties = this.TargetProperties .Select(tp => ReflectionEx.GetDependencyProperty(tp)) .Where(dp => dp != null) .ToArray(); } if (this.TargetProperties == null || this.TargetDependencyProperties == null || this.TargetProperties.Length != this.TargetDependencyProperties.Length) { throw new ArgumentException("속성을 찾을 수 없습니다."); } this.PropertyType = this.TargetProperties[0].PropertyType; InitializeMultiBinding(); this.Loaded += BaseSetter_Loaded; this.Unloaded += BaseSetter_Unloaded; }
private bool IsFoucsedLocationProperty() { bool selected = propertyGrid.Controls .Cast <Control>() .Aggregate(false, (current, c) => current || c.Focused); if (!selected) { return(false); } GridItem item = propertyGrid.SelectedGridItem; string locationName = ReflectionEx.GetPropertyDisplayName <MouseActionItem>(i => i.Location); return(item != null && item.Label != null && item.Label.Equals(locationName)); }
public static bool CanExposeGenericObject(Type type) { if (type == typeof(int) || type == typeof(float) || type == typeof(bool) || type == typeof(string) || type == typeof(Vector2) || type == typeof(Vector3) || type == typeof(Color) || type.IsEnum || ReflectionEx.IsSameOrSubclassOf(type, typeof(Object)) ) { return(true); } return(false); }
public void DisassembleThisMethodAndCheckCalling() { Action thisMethod = DisassembleThisMethodAndCheckCalling; var disassembler = new Disassembler(); // disassembling this method var result = disassembler.Disassemble(thisMethod); result.IsNotNull(); // tests this method calls Disassembler.Disassemble var method = ReflectionEx.GetMethod <Action>(() => disassembler.Disassemble(thisMethod)); result.IsCalling(method).IsTrue(); // this method not calling Console.WriteLine var cwr = ReflectionEx.GetMethod <Action>(() => Console.WriteLine()); result.IsCalling(cwr).IsFalse(); }
public void ReadSimulationOptionString() { var value = FSharpOption <string> .Some("abc"); var type = value.GetType(); var serializer = new Serializer(new SerializerOptions(knownTypes: new List <Type>() { type })); var session = new DeserializerSession(serializer); var stream = new MemoryStream(); serializer.Serialize(value, stream); stream.Position = 3; //skip forward to payload var fields = ReflectionEx.GetFieldInfosForType(type); var readAllFields = GetDelegate(type, fields, serializer); var x = (FSharpOption <string>)readAllFields(stream, session); Assert.Equal(value.Value, x.Value); }
public BaseSetter(DependencyObject target, PropertyInfo pi) { this.Focusable = false; this.Target = target; TargetProperty = pi; if (TargetProperty != null) { TargetDependencyProperty = ReflectionEx.GetDependencyProperty(TargetProperty); } if (TargetProperty == null || TargetDependencyProperty == null) { throw new ArgumentException("속성을 찾을 수 없습니다."); } // Target Binding OnTargetPropertyBinding(); this.Loaded += BaseSetter_Loaded; this.Unloaded += BaseSetter_Unloaded; }
public void OnAfterDeserialize() { this.Clear(); if (this.json == "[]") { return; } try { var jsonBlobStringReader = new StringReader(this.json); using (JsonTextReader jsonBlobReader = new JsonTextReader(jsonBlobStringReader)) { this.ReadAndAssert(jsonBlobReader, JsonToken.StartArray); while (jsonBlobReader.Read()) { if (jsonBlobReader.TokenType == JsonToken.EndArray) { break; } Assert.AreEqual(jsonBlobReader.TokenType, JsonToken.StartObject); this.ReadAndAssert(jsonBlobReader, JsonToken.PropertyName); Assert.AreEqual((string)jsonBlobReader.Value, "Type"); string typeName = jsonBlobReader.ReadAsString(); Type valueType = ReflectionEx.GetTypeFromAllAssemblies(typeName); Assert.IsNotNull(valueType); this.ReadAndAssert(jsonBlobReader, JsonToken.PropertyName); string propertyName = (string)jsonBlobReader.Value; string propertyValueAsJson = jsonBlobReader.ReadAsString(); if (string.Equals(propertyValueAsJson, "null", StringComparison.OrdinalIgnoreCase)) { this.Add(propertyName, null); } else { try { if (valueType == typeof(string)) { this.Add(propertyName, propertyValueAsJson); } else { object propertyValue = JsonUtility.FromJson(propertyValueAsJson, valueType); this.Add(propertyName, propertyValue); } } catch (Exception ex) { Debug.LogException(ex); } } this.ReadAndAssert(jsonBlobReader, JsonToken.EndObject); } } } catch (Exception ex) { Debug.LogException(ex); } foreach (KeyValuePair <string, Object> pair in this.unityObjects) { this.Add(pair.Key, pair.Value); } this.json = "[]"; }
public static bool ExposeProperty(object context, PropertyInfo property, bool showHeader, params GUILayoutOption[] options) { Type type = property.PropertyType; EditorGUI.BeginChangeCheck(); GUIContent label = showHeader ? new GUIContent(property.Name) : GUIContent.none; if (!property.CanWrite || ReflectionEx.HasAttribute <ReadOnlyAttribute>(property)) { GUI.enabled = false; } EditorGUILayout.BeginHorizontal(); if (type == typeof(int)) { int oldValue = (int)property.GetValue(context, null); int newValue = EditorGUILayout.IntField(label, oldValue, options); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type == typeof(float)) { float oldValue = (float)property.GetValue(context, null); float newValue = EditorGUILayout.FloatField(label, oldValue, options); if (!Mathf.Approximately(oldValue, newValue)) { property.SetValue(context, newValue, null); } } else if (type == typeof(bool)) { bool oldValue = (bool)property.GetValue(context, null); bool newValue = EditorGUILayout.Toggle(label, oldValue, options); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type == typeof(string)) { string oldValue = (string)property.GetValue(context, null); string newValue = EditorGUILayout.TextField(label, oldValue, options); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type == typeof(Vector2)) { Vector2 oldValue = (Vector2)property.GetValue(context, null); Vector2 newValue = EditorGUILayout.Vector2Field(label, oldValue, options); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type == typeof(Vector3)) { Vector3 oldValue = (Vector3)property.GetValue(context, null); Vector3 newValue = EditorGUILayout.Vector3Field(label, oldValue, options); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type.IsEnum) { Enum oldValue = (Enum)property.GetValue(context, null); Enum newValue = EditorGUILayout.EnumPopup(label, oldValue, options); if (!object.Equals(oldValue, newValue)) { property.SetValue(context, newValue, null); } } else if (type == typeof(Color)) { Color oldValue = (Color)property.GetValue(context, null); Color newValue = EditorGUILayout.ColorField(label, oldValue, options); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (ReflectionEx.IsSameOrSubclassOf(type, typeof(Object))) { Object oldValue = (Object)property.GetValue(context, null); Object newValue = EditorGUILayout.ObjectField(label, oldValue, type, true, options); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else { EditorGUILayout.HelpBox("Unsupported dependency property type.", MessageType.Warning); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; return(EditorGUI.EndChangeCheck()); }
public static object ExposeGenericObject(Rect rect, object value, Type type, GUIContent label) { if (type == typeof(int)) { int oldValue = (int)value; int newValue = EditorGUI.IntField(rect, label, oldValue); if (oldValue != newValue) { value = newValue; } } else if (type == typeof(float)) { float oldValue = (float)value; float newValue = EditorGUI.FloatField(rect, label, oldValue); if (!Mathf.Approximately(oldValue, newValue)) { value = newValue; } } else if (type == typeof(bool)) { bool oldValue = (bool)value; bool newValue = EditorGUI.Toggle(rect, label, oldValue); if (oldValue != newValue) { value = newValue; } } else if (type == typeof(string)) { string oldValue = (string)value; string newValue = EditorGUI.TextField(rect, label, oldValue); if (oldValue != newValue) { value = newValue; } } else if (type == typeof(Vector2)) { Vector2 oldValue = (Vector2)value; Vector2 newValue = EditorGUI.Vector2Field(rect, label, oldValue); if (oldValue != newValue) { value = newValue; } } else if (type == typeof(Vector3)) { Vector3 oldValue = (Vector3)value; Vector3 newValue = EditorGUI.Vector3Field(rect, label, oldValue); if (oldValue != newValue) { value = newValue; } } else if (type.IsEnum) { Enum oldValue = (Enum)value; Enum newValue = EditorGUI.EnumPopup(rect, label, oldValue); if (!object.Equals(oldValue, newValue)) { value = newValue; } } else if (type == typeof(Color)) { Color oldValue = (Color)value; Color newValue = EditorGUI.ColorField(rect, label, oldValue); if (oldValue != newValue) { value = newValue; } } else if (ReflectionEx.IsSameOrSubclassOf(type, typeof(Object))) { Object oldValue = (Object)value; Object newValue = EditorGUI.ObjectField(rect, label, oldValue, type, true); if (oldValue != newValue) { value = newValue; } } else if (type == typeof(GUIContent)) { GUI.enabled = false; EditorGUI.TextField(rect, label, StringEx.Stringify((GUIContent)value)); GUI.enabled = true; } else { GUI.enabled = false; EditorGUI.TextField(rect, label, StringEx.Stringify(value)); GUI.enabled = true; } return(value); }
public static bool ExposeProperty(Rect rect, object context, PropertyInfo property, bool showHeader) { Type type = property.PropertyType; EditorGUI.BeginChangeCheck(); GUIContent label = showHeader ? new GUIContent(property.Name) : GUIContent.none; if (type == typeof(int)) { int oldValue = (int)property.GetValue(context, null); int newValue = EditorGUI.IntField(rect, label, oldValue); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type == typeof(float)) { float oldValue = (float)property.GetValue(context, null); float newValue = EditorGUI.FloatField(rect, label, oldValue); if (!Mathf.Approximately(oldValue, newValue)) { property.SetValue(context, newValue, null); } } else if (type == typeof(bool)) { bool oldValue = (bool)property.GetValue(context, null); bool newValue = EditorGUI.Toggle(rect, label, oldValue); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type == typeof(string)) { string oldValue = (string)property.GetValue(context, null); string newValue = EditorGUI.TextField(rect, label, oldValue); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type == typeof(Vector2)) { Vector2 oldValue = (Vector2)property.GetValue(context, null); Vector2 newValue = EditorGUI.Vector2Field(rect, label, oldValue); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type == typeof(Vector3)) { Vector3 oldValue = (Vector3)property.GetValue(context, null); Vector3 newValue = EditorGUI.Vector3Field(rect, label, oldValue); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (type.IsEnum) { Enum oldValue = (Enum)property.GetValue(context, null); Enum newValue = EditorGUI.EnumPopup(rect, label, oldValue); if (!object.Equals(oldValue, newValue)) { property.SetValue(context, newValue, null); } } else if (type == typeof(Color)) { Color oldValue = (Color)property.GetValue(context, null); Color newValue = EditorGUI.ColorField(rect, label, oldValue); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else if (ReflectionEx.IsSameOrSubclassOf(type, typeof(Object))) { Object oldValue = (Object)property.GetValue(context, null); Object newValue = EditorGUI.ObjectField(rect, label, oldValue, type, true); if (oldValue != newValue) { property.SetValue(context, newValue, null); } } else { EditorGUI.HelpBox(rect, "Unsupported dependency property type.", MessageType.Warning); } return(EditorGUI.EndChangeCheck()); }