Esempio n. 1
0
 public void MissingServiceThrowsException()
 {
     var attribute = new InjectDataAttribute();
     var method = typeof(XunitTestsWithConfigureMethod).GetMethod("MethodWithMissingService");            
     
     Assert.Throws<InvalidOperationException>(() => attribute.GetData(method));
 }
Esempio n. 2
0
        public void MissingServiceThrowsException()
        {
            var attribute = new InjectDataAttribute();
            var method    = typeof(XunitTestsWithConfigureMethod).GetMethod("MethodWithMissingService");

            Assert.Throws <InvalidOperationException>(() => attribute.GetData(method, new Type[] { typeof(int) }));
        }
Esempio n. 3
0
        public void MissingDependencyThrowsException()
        {
            var attribute = new InjectDataAttribute();
            var method    = typeof(XunitTestsWithMissingDependencies).GetMethod("MethodWithMissingDependency");

            Assert.Throws <InvalidOperationException>(() => attribute.GetData(method));
        }
Esempio n. 4
0
    /// <summary>
    /// 查找所有的GUI可显示组件项
    /// </summary>
    /// <param name="widgets"></param>
    /// <param name="obj"></param>
    public static void FindAllWidget(List <EditorWidgetState> widgets, EditorWidgetState parentWidget, object obj)
    {
        if (obj == null)
        {
            return;
        }

        Type objType = obj.GetType();

        foreach (PropertyInfo propertyInfo in objType.GetProperties())
        {
            Attribute attribute = Attribute.GetCustomAttribute(propertyInfo, typeof(InjectDataAttribute));
            if (attribute == null)
            {
                continue;
            }

            InjectDataAttribute display = attribute as InjectDataAttribute;
            if (string.IsNullOrEmpty(display.DisplayName))
            {
                continue;
            }

            Type propertyType = propertyInfo.PropertyType;
            if (!propertyType.IsEnum && !propertyType.IsValueType && !propertyType.Equals(typeof(System.String)))
            {
                EditorWidgetState childWidget = new EditorWidgetState();
                object            childObj    = propertyInfo.GetValue(obj, null);
                childWidget.Entity = childObj == null?Activator.CreateInstance(propertyType) : childObj;

                if (childObj == null)
                {
                    propertyInfo.SetValue(obj, childWidget.Entity, null);
                }
                widgets.Add(childWidget);

                FindAllWidget(new List <EditorWidgetState>(), childWidget, childWidget.Entity);
            }
        }
        parentWidget.SubWidget = widgets.ToArray();
    }
        public void MissingDependencyThrowsException()
        {
            var attribute = new InjectDataAttribute();
            var method = typeof(XunitTestsWithMissingDependencies).GetMethod("MethodWithMissingDependency");

            Assert.Throws<InvalidOperationException>(() => attribute.GetData(method));
        }
Esempio n. 6
0
    /// <summary>
    /// 绘制实例
    /// </summary>
    /// <param name="widgetState"></param>
    /// <param name="isRemove"></param>
    /// <returns></returns>
    public static bool OnGUIInstanceDisplay(EditorWidgetState widgetState, bool isRemove)
    {
        object obj = widgetState.Entity;

        if (obj == null)
        {
            return(false);
        }

        if (isRemove && widgetState.FoldOut)
        {
            NGUIEditorTools.DrawSeparator();
        }
        GUILayout.BeginHorizontal();

        widgetState.FoldOut = EditorGUILayout.Foldout(widgetState.FoldOut, widgetState.Entity.GetType().Name);

        if (isRemove && GUILayout.Button("X", GUILayout.Width(30)))
        {
            return(true);
        }
        GUILayout.EndHorizontal();
        if (isRemove && widgetState.FoldOut)
        {
            NGUIEditorTools.DrawSeparator();
            GUILayout.Space(10);
        }

        //如果被折叠,则不绘制具体的面板信息
        if (!widgetState.FoldOut)
        {
            return(false);
        }

        EditorGUI.indentLevel++;

        Type objType = obj.GetType();

        foreach (PropertyInfo propertyInfo in objType.GetProperties())
        {
            Attribute attribute = Attribute.GetCustomAttribute(propertyInfo, typeof(InjectDataAttribute));
            if (attribute == null)
            {
                continue;
            }

            InjectDataAttribute display = attribute as InjectDataAttribute;
            if (string.IsNullOrEmpty(display.DisplayName))
            {
                continue;
            }

            Type propertyType = propertyInfo.PropertyType;
            if (propertyType.IsEnum || propertyType.IsValueType || propertyType.Equals(typeof(System.String)))
            {
                GUILayout.BeginHorizontal();
                object result = OnGUIProperty(display.DisplayName, propertyType, propertyInfo.GetValue(obj, null));
                propertyInfo.SetValue(obj, result, null); //更新修改值
                GUILayout.EndHorizontal();
            }
        }

        //遍历绘制子层数据
        if (widgetState.SubWidget != null && widgetState.SubWidget.Length > 0)
        {
            EditorGUI.indentLevel++;
            foreach (EditorWidgetState subWidget in widgetState.SubWidget)
            {
                //bool lastFoldOut = subWidget.FoldOut;
                //NGUIEditorTools.DrawSeparator();

                //if(lastFoldOut)     NGUIEditorTools.DrawSeparator();

                OnGUIInstanceDisplay(subWidget, false);
            }
        }

        return(false);
    }