当前位置: 首页>>代码示例>>C#>>正文


C# Task.GetType方法代码示例

本文整理汇总了C#中Task.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Task.GetType方法的具体用法?C# Task.GetType怎么用?C# Task.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Task的用法示例。


在下文中一共展示了Task.GetType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetReferencedTasks

 public static List<Task> GetReferencedTasks(Task task)
 {
     List<Task> list = new List<Task>();
         FieldInfo[] fields = task.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
         for (int i = 0; i < fields.Length; i++)
         {
             if (!fields[i].IsPrivate || fields[i].GetCustomAttributes(typeof(SerializeField), false).Length != 0)
             {
                 if (fields[i].FieldType.IsArray && fields[i].FieldType.GetElementType().IsSubclassOf(typeof(Task)))
                 {
                     Task[] array = fields[i].GetValue(task) as Task[];
                     if (array != null)
                     {
                         for (int j = 0; j < array.Length; j++)
                         {
                             list.Add(array[j]);
                         }
                     }
                 }
                 else if (fields[i].FieldType.IsSubclassOf(typeof(Task)) && fields[i].GetValue(task) != null)
                 {
                     list.Add(fields[i].GetValue(task) as Task);
                 }
             }
         }
         if (list.Count <= 0)
         {
             return null;
         }
         return list;
 }
开发者ID:webconfig,项目名称:Design,代码行数:31,代码来源:TaskInspector.cs

示例2: AssignTask

 public override void AssignTask(Task Task)
 {
     //Pass task trigger delegate to the trigger itself
     Delegate Delegate = Delegate.CreateDelegate(typeof(Del), Task, Task.GetType().GetMethod("Trigger"));
     object[] Constructors = new object[2];
     Constructors[0] = Delegate;
     Constructors[1] = this.Args;
     this.TriggerInstance = Compiler.SourceToInstance(this.Source.CodeList().ToArray(), this.Source.ReferencedAssemblies.ToArray(), Conf.TriggerCriticals.Namespace, Conf.TriggerCriticals.Class, Constructors);
     base.AssignTask(Task);
 }
开发者ID:TimeToogo,项目名称:WIDA-Tasks,代码行数:10,代码来源:Trigger.cs

示例3: TestPropertyEquality

        public void TestPropertyEquality()
        {
            var task = new Task();
            var task2 = new Task();
            Type t = task.GetType();
            Type t2 = task2.GetType();

            var prop1 = t.GetProperty("Id");
            var prop2 = t2.GetProperty("Id");

            Assert.AreEqual(prop1, prop2);
            // this fails:
            //Assert.AreSame(prop1, prop2);
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:14,代码来源:ReflectionTests.cs

示例4: GetTaskException

 private Exception GetTaskException(Task task)
 {
     Exception exception = task.Exception;
     if (exception != null)
     {
         return exception.InnerException;
     }
     if (!task.IsCanceled)
     {
         return null;
     }
     exception = new TaskCanceledException(task);
     try
     {
         MethodInfo info = task.GetType().GetMethod("GetCancellationExceptionDispatchInfo", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
         if (info == null)
         {
             return exception;
         }
         object obj2 = info.Invoke(task, null);
         if (obj2 == null)
         {
             return exception;
         }
         MethodInfo info2 = obj2.GetType().GetMethod("Throw", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
         if (info2 == null)
         {
             return exception;
         }
         try
         {
             info2.Invoke(obj2, null);
         }
         catch (Exception exception3)
         {
             return exception3;
         }
     }
     catch
     {
     }
     return exception;
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:43,代码来源:Server.cs

示例5: StartChild

        /// <summary>
        /// Starts a new child context.
        /// </summary>
        /// <param name="task">The task.</param>
        /// <returns>
        /// The new child <see cref="TaskExecutionContext"/>.
        /// </returns>
        public virtual TaskExecutionContext StartChild(Task task)
        {
            logger.Debug("Starting new task execution context for '{0}'", task.NameOrType);
            var parameters = new TaskExecutionParameters
                                 {
                                     XmlWriter = this.writer,
                                     FileSystem = this.fileSystem,
                                     Clock = this.clock,
                                     IntegrationRequest = this.request,
                                     Project = this.project,
                                     BuildName = this.buildName
                                 };
            var child = new TaskExecutionContext(parameters)
                            {
                                Parent = this,
                                modificationsSets = this.modificationsSets,
                                modificationsLock = this.modificationsLock
                            };
            this.writer.WriteStartElement("task");
            if (!string.IsNullOrEmpty(task.Name))
            {
                this.writer.WriteAttributeString("name", task.Name);
            }

            this.writer.WriteAttributeString("type", task.GetType().Name);
            writer.WriteElementString("start", this.clock.Now.ToString("s"));
            return child;
        }
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:35,代码来源:TaskExecutionContext.cs

示例6: SerializeTask_UI

    /// <summary>
    /// 序列化任务
    /// </summary>
    /// <param name="task"></param>
    /// <param name="behavior"></param>
    /// <param name="taskCount"></param>
    /// <returns></returns>
    public static SerializeData SerializeTask_UI(Task task)
    {
        SerializeData xd = new SerializeData();
        Dictionary<string, string> dictionary = new Dictionary<string, string>();
        dictionary.Add("ObjectType", task.GetType().ToString());
        task.NodeData.serialize_ui(dictionary);
        task.SerializeUI(dictionary);
        xd.property = dictionary;

        foreach (var item in task.OutLinks)
        {
            List<SerializeData> sds = new List<SerializeData>();
            for (int i = 0; i < item.Value.Childs.Count; i++)
            {
                SerializeData xd_child = SerializeTask_UI(item.Value.Childs[i]);
                sds.Add(xd_child);
            }
            xd.childs.Add(item.Key, sds);
        }
        return xd;
    }
开发者ID:webconfig,项目名称:Design,代码行数:28,代码来源:SerializeXml.cs

示例7: GetTaskResult

        private static object GetTaskResult(Task task)
        {
            if (task.IsFaulted)
            {
                throw task.Exception;
            }

            Type taskType = task.GetType();

            if (taskType.IsGenericType)
            {
                return taskType.GetProperty("Result").GetValue(task);
            }

            return null;
        }
开发者ID:isaacabraham,项目名称:azure-webjobs-sdk-script,代码行数:16,代码来源:CSharpFunctionInvoker.cs

示例8: referenceTasks

 public static bool referenceTasks(Task sourceTask, Task referenceTask, FieldInfo sourceFieldInfo, ref bool fullSync, ref bool doReference, bool synchronize, bool registerUndo, bool unreferenceAll)
 {
     if (referenceTask == null || referenceTask.Equals(sourceTask) || (!sourceFieldInfo.FieldType.IsArray && !sourceFieldInfo.FieldType.Equals(referenceTask.GetType()) && !referenceTask.GetType().IsSubclassOf(sourceFieldInfo.FieldType)) || (sourceFieldInfo.FieldType.IsArray && !sourceFieldInfo.FieldType.GetElementType().Equals(referenceTask.GetType()) && !referenceTask.GetType().IsSubclassOf(sourceFieldInfo.FieldType.GetElementType())))
         {
             return false;
         }
         if (synchronize)
         {
             synchronize = false;
         }
         if (unreferenceAll)
         {
             sourceFieldInfo.SetValue(sourceTask, null);
             //(sourceTask.NodeData.NodeDesigner as NodeDesigner).ShowReferenceIcon = false;
         }
         else
         {
             doReference = true;
             bool flag = false;
             if (sourceFieldInfo.FieldType.IsArray)
             {
                 Task[] array = sourceFieldInfo.GetValue(sourceTask) as Task[];
                 IList list = Activator.CreateInstance(typeof(List<>).MakeGenericType(new Type[]
                 {
                     sourceFieldInfo.FieldType.GetElementType()
                 })) as IList;
                 if (array != null)
                 {
                     for (int i = 0; i < array.Length; i++)
                     {
                         if (referenceTask.Equals(array[i]))
                         {
                             doReference = false;
                         }
                         else
                         {
                             list.Add(array[i]);
                         }
                     }
                 }
                 if (synchronize)
                 {
                     if (array != null && array.Length > 0)
                     {
                         for (int j = 0; j < array.Length; j++)
                         {
                             TaskInspector.referenceTasks(array[j], referenceTask, array[j].GetType().GetField(sourceFieldInfo.Name), ref flag, ref doReference, false, registerUndo, false);
                             if (doReference)
                             {
                                 TaskInspector.referenceTasks(referenceTask, array[j], referenceTask.GetType().GetField(sourceFieldInfo.Name), ref flag, ref doReference, false, registerUndo, false);
                             }
                         }
                     }
                     else if (doReference)
                     {
                         array = (referenceTask.GetType().GetField(sourceFieldInfo.Name).GetValue(referenceTask) as Task[]);
                         if (array != null)
                         {
                             for (int k = 0; k < array.Length; k++)
                             {
                                 list.Add(array[k]);
                                 //(array[k].NodeData.NodeDesigner as NodeDesigner).ShowReferenceIcon = true;
                                 TaskInspector.referenceTasks(array[k], sourceTask, array[k].GetType().GetField(sourceFieldInfo.Name), ref doReference, ref flag, false, registerUndo, false);
                             }
                             doReference = true;
                         }
                     }
                     TaskInspector.referenceTasks(referenceTask, sourceTask, referenceTask.GetType().GetField(sourceFieldInfo.Name), ref flag, ref doReference, false, registerUndo, !doReference);
                 }
                 if (doReference)
                 {
                     list.Add(referenceTask);
                 }
                 Array array2 = Array.CreateInstance(sourceFieldInfo.FieldType.GetElementType(), list.Count);
                 list.CopyTo(array2, 0);
                 //if (registerUndo)
                 //{
                 //    BehaviorUndo.RegisterUndo(doReference ? "Select" : "Deselect", sourceTask, true, true);
                 //}
                 sourceFieldInfo.SetValue(sourceTask, array2);
             }
             else
             {
                 Task task = sourceFieldInfo.GetValue(sourceTask) as Task;
                 doReference = !referenceTask.Equals(task);
                 //if (registerUndo)
                 //{
                 //    BehaviorUndo.RegisterUndo(doReference ? "Select" : "Deselect", sourceTask, true, true);
                 //}
                 //if (TaskInspector.isFieldLinked(sourceFieldInfo) && task != null)
                 //{
                 //    TaskInspector.referenceTasks(task, sourceTask, task.GetType().GetField(sourceFieldInfo.Name), ref flag, ref doReference, false, registerUndo, true);
                 //}
                 if (synchronize)
                 {
                     TaskInspector.referenceTasks(referenceTask, sourceTask, referenceTask.GetType().GetField(sourceFieldInfo.Name), ref flag, ref doReference, false, registerUndo, !doReference);
                 }
                 sourceFieldInfo.SetValue(sourceTask, doReference ? referenceTask : null);
             }
             //if (synchronize)
//.........这里部分代码省略.........
开发者ID:webconfig,项目名称:Design,代码行数:101,代码来源:TaskInspector.cs

示例9: performFullSync

 private void performFullSync(Task task)
 {
     List<Task> referencedTasks = TaskInspector.GetReferencedTasks(task);
         if (referencedTasks != null)
         {
             List<bool> list = new List<bool>();
             for (int i = 0; i < referencedTasks.Count; i++)
             {
                 list.Add(true);
             }
             bool registerUndo = true;
             FieldInfo[] fields = task.GetType().GetFields();
             for (int j = 0; j < fields.Length; j++)
             {
                 //if (!TaskInspector.isFieldLinked(fields[j]))
                 //{
                     for (int k = 0; k < referencedTasks.Count; k++)
                     {
                         FieldInfo field;
                         if ((field = referencedTasks[k].GetType().GetField(fields[j].Name)) != null)
                         {
                             if (list[k])
                             {
                                 //BehaviorUndo.RegisterUndo("Inspector", referencedTasks[k], registerUndo, true);
                                 list[k] = false;
                                 registerUndo = false;
                             }
                             field.SetValue(referencedTasks[k], fields[j].GetValue(task));
                         }
                     }
                 //}
             }
         }
 }
开发者ID:webconfig,项目名称:Design,代码行数:34,代码来源:TaskInspector.cs

示例10: drawTaskFields

    public bool drawTaskFields(SkillData _data, Task task)
    {
        if (task == null)
            {
                return false;
            }
            this.mScrollPosition = GUILayout.BeginScrollView(this.mScrollPosition, new GUILayoutOption[0]);

            bool result = false;
            EditorGUIUtility.labelWidth = TaskPropertiesLabelWidth;
            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            EditorGUILayout.LabelField("Name", new GUILayoutOption[]
            {
                GUILayout.Width(90f)
            });
            task.NodeData.FriendlyName = EditorGUILayout.TextField(task.NodeData.FriendlyName, new GUILayoutOption[0]);

            if (GUILayout.Button("编辑", new GUILayoutOption[0]))
            {
                GenericMenu genericMenu = new GenericMenu();
                genericMenu.AddItem(new GUIContent("Edit Script"), false, new GenericMenu.MenuFunction2(this.openInFileEditor), task);
                genericMenu.AddItem(new GUIContent("Reset"), false, new GenericMenu.MenuFunction2(this.resetTask), task);
                genericMenu.ShowAsContext();
            }
            GUILayout.EndHorizontal();

            EditorGUILayout.LabelField("Comment", new GUILayoutOption[0]);
            task.NodeData.Comment = EditorGUILayout.TextArea(task.NodeData.Comment,  new GUILayoutOption[]{GUILayout.Height(48f)});
            if (EditorGUI.EndChangeCheck())
            {
                result = true;
            }
            //BehaviorDesignerUtility.DrawContentSeperator(2);
            GUILayout.Space(6f);
            HideFlags hideFlags = task.hideFlags;
            task.hideFlags = 0;
            SerializedObject serializedObject = new SerializedObject(task);
            serializedObject.Update();
            FieldInfo[] fields = task.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            for (int i = 0; i < fields.Length; i++)
            {
                if (fields[i].GetCustomAttributes(typeof(NonSerializedAttribute), false).Length <= 0 && ((!fields[i].IsPrivate && !fields[i].IsFamily) || fields[i].GetCustomAttributes(typeof(SerializeField), false).Length != 0))
                {
                    SerializedProperty serializedProperty = serializedObject.FindProperty(fields[i].Name);
                    if (serializedProperty != null)
                    {
                        SkillEditor.Runtime.Tasks.TooltipAttribute[] array;
                        GUIContent gUIContent;
                        if ((array = (fields[i].GetCustomAttributes(typeof(SkillEditor.Runtime.Tasks.TooltipAttribute), false) as SkillEditor.Runtime.Tasks.TooltipAttribute[])).Length > 0)
                        {
                            gUIContent = new GUIContent(fields[i].Name, array[0].Tooltip);
                        }
                        else
                        {
                            gUIContent = new GUIContent(fields[i].Name);
                        }
                        EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        if (fields[i].FieldType.IsSubclassOf(typeof(SharedVariable)))
                        {
                            EditorGUI.BeginChangeCheck();
                            SharedVariable sharedVariable = fields[i].GetValue(task) as SharedVariable;
                            GUILayout.BeginVertical(new GUILayoutOption[0]);
                            GUILayout.Space(2f);
                            GUILayout.Label(gUIContent, new GUILayoutOption[]
                            {
                                GUILayout.Width(146f)
                            });
                            GUILayout.EndVertical();
                            bool flag4 = false;
                            switch (sharedVariable.ValueType)
                            {
                                case SharedVariableTypes.Vector2:
                                case SharedVariableTypes.Vector3:
                                case SharedVariableTypes.Vector4:
                                case SharedVariableTypes.Quaternion:
                                case SharedVariableTypes.Rect:
                                    flag4 = true;
                                    break;
                            }
                            if (sharedVariable.IsShared)
                            {
                                string[] array3 = null;
                                int num = this.getVariablesOfType(sharedVariable, _data, out array3);
                                Color backgroundColor2 = GUI.backgroundColor;
                                if (num == 0)
                                {
                                    GUI.backgroundColor = Color.red;
                                }
                                int num2 = num;
                                num = EditorGUILayout.Popup(num, array3, EditorStyles.toolbarPopup, new GUILayoutOption[0]);
                                GUI.backgroundColor = backgroundColor2;
                                if (num != num2)
                                {//===========设置分享变量==============
                                    if (num == 0)
                                    {
                                        SharedVariable sharedVariable2 = ScriptableObject.CreateInstance(fields[i].FieldType) as SharedVariable;
                                        sharedVariable2.IsShared = true;
                                        fields[i].SetValue(task, sharedVariable2);
                                    }
//.........这里部分代码省略.........
开发者ID:webconfig,项目名称:Design,代码行数:101,代码来源:TaskInspector.cs


注:本文中的Task.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。