/// <summary> /// WPFモジュールのインストール /// </summary> /// <returns></returns> static bool InstallWpfInApp() { TypeFinder finder = new TypeFinder(); Type t = finder.GetType("Codeer.Friendly.Windows.Wpf.Grasp.WpfAnalyzer"); if (t != null) { return true; } //参照 List<string> reference = new List<string>(); reference.Add(typeof(TargetAppInitializer).Assembly.Location); reference.Add(typeof(AppVar).Assembly.Location); reference.Add("System.dll"); reference.Add("System.Drawing.dll"); foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { switch (asm.GetName().Name) { case "PresentationCore": case "PresentationFramework": case "WindowsBase": case "System.Xaml": reference.Add(asm.Location); break; } } CompilerResults compilerResults = CspCompiler.Compile(reference.ToArray(), Resources.WpfAnalyzer); return !compilerResults.Errors.HasErrors; }
static void ResolveInvokeTarget(VarPool varManager, TypeFinder typeFinder, ProtocolInfo info, out Type type, out object targetObj, out object[] args, out Type[] argTypes, out BindingFlags bind) { type = null; targetObj = null; bind = new BindingFlags(); if (info.VarAddress == null) { type = typeFinder.GetType(info.TypeFullName); if (type == null) { throw new InformationException(string.Format(CultureInfo.CurrentCulture, ResourcesLocal.Instance.UnknownTypeInfoFormat, info.TypeFullName)); } bind.IsStatic = true; } else { VarAndType varAndType = varManager.GetVarAndType(info.VarAddress); targetObj = varAndType.Core; if (targetObj == null) { throw new InformationException(ResourcesLocal.Instance.NullObjectOperation); } type = varAndType.Type; } ResolveArgs(varManager, info.Arguments, out args, out argTypes); }
static void Main(string[] args) { var path = args[0]; var uri = args[1]; var entry = args[2]; var dir = Path.GetDirectoryName(path); var dlls = Directory.GetFiles(dir, "*.dll", SearchOption.AllDirectories). Concat(Directory.GetFiles(dir, "*.exe", SearchOption.AllDirectories)).ToArray(); AssemblyManager.AddInterfaceType(typeof(FriendlyServer).Assembly); foreach (var e in dlls) { try { var asm = Assembly.LoadFrom(e); AssemblyManager.AddInterfaceType(asm); } catch { } } FriendlyServer.StartLoop(uri, (a) => Application.OpenForms[0].Invoke(a)); var sp = entry.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries); var typeFullName = string.Join(".", sp.Take(sp.Length - 1)); var method = sp[sp.Length - 1]; var finder = new TypeFinder(); finder.GetType(typeFullName).GetMethod(method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Invoke(null, args.Skip(3).Select(e => (object)e).ToArray()); }
/// <summary> /// GetCoreElement. /// </summary> /// <param name="visual">Root.</param> /// <param name="typeFullName">Type full name.</param> /// <returns>Match visual.</returns> public static Visual GetCoreElement(Visual visual, string typeFullName) { TypeFinder finder = new TypeFinder(); var type = finder.GetType(typeFullName); if (type == null) { return(null); } return(GetCoreElement(visual, type)); }
internal static void ResetTimeout(this WindowsAppFriend app) { app.ClearTimeout(); var type = _finder.GetType(TestContext.CurrentContext.Test.ClassName); var method = type.GetMethod(TestContext.CurrentContext.Test.MethodName); var attrs = method.GetCustomAttributes(typeof(TimeoutExAttribute), true); if (attrs.Length == 1) { var timeout = (TimeoutExAttribute)attrs[0]; var exe = typeof(Killer.Program).Assembly.Location; _killer = Process.Start(exe, app.ProcessId + " " + timeout.Time + " \"" + TestResult.MakeErrPngPath() + "\""); } }
/// <summary> /// Search by Type from DependencyObject collection. /// </summary> /// <param name="collection">DependencyObject collection.</param> /// <param name="typeFullName">Target type.</param> /// <returns>Hit elements.</returns> #else /// <summary> /// タイプから要素を検索。 /// </summary> /// <param name="collection">DependencyObjectのコレクション。</param> /// <param name="typeFullName">検索対象のタイプ。</param> /// <returns>ヒットした要素。</returns> #endif public static IEnumerable <DependencyObject> ByType(IEnumerable <DependencyObject> collection, string typeFullName) { List <DependencyObject> list = new List <DependencyObject>(); var finder = new TypeFinder(); var type = finder.GetType(typeFullName); foreach (var e in collection) { if (type.IsAssignableFrom(e.GetType())) { list.Add(e); } } return(list); }
Delegate GetMethod(FrameworkElement element, PropertyInfo invokerProp) { var invokeInfo = invokerProp.PropertyType.GetMethod("Invoke"); if (invokeInfo == null) { return(null); } var names = Name.Split('.'); if (names.Length != 1) { var type = TypeFinder.GetType(string.Join(".", names.Take(names.Length - 1))); var targetMethodInfo = type.GetMethod(names[names.Length - 1], invokeInfo.GetParameters().Select(e => e.ParameterType).ToArray()); if (targetMethodInfo == null) { return(null); } return(targetMethodInfo.CreateDelegate(invokerProp.PropertyType)); } else { object target = null; if (Target != null) { target = Target; } else if (element != null) { target = element; } else { return(null); } var targetMethodInfo = target.GetType().GetMethod(Name, invokeInfo.GetParameters().Select(e => e.ParameterType).ToArray()); if (targetMethodInfo == null) { return(null); } return(targetMethodInfo.CreateDelegate(invokerProp.PropertyType, target)); } }
/// <summary> /// Search by Type from DependencyObject collection. /// </summary> /// <param name="collection">DependencyObject collection.</param> /// <param name="typeFullName">Target type.</param> /// <returns>Hit elements.</returns> #else /// <summary> /// タイプから要素を検索。 /// </summary> /// <param name="collection">DependencyObjectのコレクション。</param> /// <param name="typeFullName">検索対象のタイプ。</param> /// <returns>ヒットした要素。</returns> #endif public static IEnumerable <DependencyObject> ByType(IEnumerable <DependencyObject> collection, string typeFullName) { List <DependencyObject> list = new List <DependencyObject>(); var finder = new TypeFinder(); var type = finder.GetType(typeFullName); if (type == null) { throw new ArgumentException("typeFullName's type is not found."); } foreach (var e in collection) { if (type.IsAssignableFrom(e.GetType())) { list.Add(e); } } return(list); }
internal static void ResetTimeout(this WindowsAppFriend app) { app.ClearTimeout(); if (Debugger.IsAttached) { return; } var type = _finder.GetType(TestContext.CurrentContext.Test.ClassName); var method = type.GetMethod(TestContext.CurrentContext.Test.MethodName); var attrs = method.GetCustomAttributes(typeof(TimeoutExAttribute), true); if (attrs.Length != 1) { return; } var timeout = (TimeoutExAttribute)attrs[0]; _alive = true; _killer = new Thread(() => PollingTimeout(app, timeout)); _killer.Start(); }
/// <summary> /// Processes the received message. /// </summary> /// <param name="message">The message.</param> /// <param name="serializedMessage">The serialized message.</param> protected override void ProcessReceivedMessage(byte[] serializedMessage) { var message = DataContractSerializer.Deserialize <MessageBus>(MessageBusParser.GetMessageFromBytes(serializedMessage)); Logger.Debug("OnMessageBusReceived"); var split = message.Header.BodyType.Split(','); if (split.Length < 2) { Logger.Error(string.Format("El mensaje no tiene el bodytype correcto {0}", serializedMessage)); return; } var bodyType = split[0]; var assemblyName = split[1]; var type = TypeFinder.GetType(bodyType, assemblyName); var body = MessageBuilder.Instance.CreateInstance(DataContractSerializer, type, message.Body, Encoding.GetEncoding(message.Header.EncodingCodePage)); InvokeOnMessage((TMessage)body, serializedMessage, message.Header); InvokeReceivedMessage(message.Header.BodyType, serializedMessage.Length, message.Header.CreatedAt); }
private void ApplyPreset() { // 1st, apply DynamicBoneCollider foreach (var collider in _preset.Configs.Where(w => w.EffectiveAs == "DynamicBoneCollider")) foreach (var gameObject in FindGameObjectByPath(collider.NamingConvention)) { if (gameObject.GetComponent(TypeFinder.GetType(DynamicBoneColliderFullName)) != null) continue; // already attached var component = gameObject.AddComponent(TypeFinder.GetType(DynamicBoneColliderFullName)); collider.DynamicBoneColliderProperties.ApplyProperties(component); } // 2nd, apply DynamicBone foreach (var bone in _preset.Configs.Where(w => w.EffectiveAs == "DynamicBone")) foreach (var gameObject in FindGameObjectByPath(bone.NamingConvention)) { if (gameObject.GetComponent(TypeFinder.GetType(DynamicBoneFullName)) != null) continue; // already attached var component = gameObject.AddComponent(TypeFinder.GetType(DynamicBoneFullName)); bone.DynamicBoneProperties.ApplyProperties(component, _gameObject); } }
static Type[] GetArgTypes(TypeFinder typeFinder, OperationTypeInfo operationTypeInfo, Type[] argTypesOri) { List <Type> argTypes = new List <Type>(); if (operationTypeInfo == null) { argTypes.AddRange(argTypesOri); } else { for (int i = 0; i < operationTypeInfo.Arguments.Length; i++) { Type type = typeFinder.GetType(operationTypeInfo.Arguments[i]); if (type == null) { throw new InformationException(string.Format(CultureInfo.CurrentCulture, ResourcesLocal.Instance.UnknownTypeInfoFormat, operationTypeInfo.Arguments[i])); } argTypes.Add(type); } if (operationTypeInfo.Arguments.Length == 1 && operationTypeInfo.Arguments[0] == typeof(object[]).ToString() && argTypesOri.Length != 1) { throw new InformationException(string.Format(CultureInfo.CurrentCulture, ResourcesLocal.Instance.ErrorOperationTypeArgInfoForObjectArrayFormat, MakeErrorInvokeArgInfo(argTypes.ToArray()), MakeErrorInvokeArgInfo(argTypesOri))); } if (argTypesOri.Length != operationTypeInfo.Arguments.Length) { throw new InformationException(string.Format(CultureInfo.CurrentCulture, ResourcesLocal.Instance.ErrorOperationTypeArgInfoFormat, MakeErrorInvokeArgInfo(argTypes.ToArray()), MakeErrorInvokeArgInfo(argTypesOri))); } } return(argTypes.ToArray()); }
static ReturnInfo AsyncOperation(IAsyncInvoke async, VarPool varManager, TypeFinder typeFinder, ProtocolInfo info) { Type type; object obj; object[] args; Type[] argTypesOri; BindingFlags bind; ResolveInvokeTarget(varManager, typeFinder, info, out type, out obj, out args, out argTypesOri, out bind); List <object> argTmp = new List <object>(args); argTmp.RemoveAt(0); args = argTmp.ToArray(); List <Type> argTypeTmp = new List <Type>(argTypesOri); argTypeTmp.RemoveAt(0); argTypesOri = argTypeTmp.ToArray(); if (info.OperationTypeInfo != null) { type = typeFinder.GetType(info.OperationTypeInfo.Target); if (type == null) { throw new InformationException(string.Format(CultureInfo.CurrentCulture, ResourcesLocal.Instance.UnknownTypeInfoFormat, info.OperationTypeInfo.Target)); } } string operation = OptimizeOperationName(type, info.Operation, args.Length); Type findStartType = type; Type[] argTypes = GetArgTypes(typeFinder, info.OperationTypeInfo, argTypesOri); //find operation. bool isObjectArrayArg = false; int nameMatchCount = 0; bool first = true; bool isAmbiguousArgs = false; while (!isAmbiguousArgs && type != null) { if (!first) { type = type.BaseType(); if (type == null) { break; } } first = false; FieldInfo field = FindField(type, bind, operation, args, ref isObjectArrayArg, ref nameMatchCount); if (field != null) { return(ExecuteField(async, varManager, info, obj, args, field)); } PropertyInfo property = FindProperty(type, bind, operation, args, ref isObjectArrayArg, ref nameMatchCount); if (property != null) { return(ExecuteProperty(async, varManager, info, obj, args, property)); } MethodInfo method = FindMethodOrProperty(info.OperationTypeInfo != null, type, bind, operation, argTypes, ref isObjectArrayArg, ref nameMatchCount, ref isAmbiguousArgs); if (method != null) { return(ExecuteMethodOrProperty(async, varManager, info, obj, args, method)); } } throw MakeNotFoundException(info, findStartType, argTypes, isObjectArrayArg, nameMatchCount, isAmbiguousArgs); }
private void CreatePresetLayout() { EditorContent.Label("Create DynamicBone preset from existing GameObject tree."); EditorGUIUtility.labelWidth = 200; _gameObject = EditorContent.ObjectPicker<GameObject>("Root GameObject", _gameObject, true); if (ReferenceEquals(_gameObject, null)) return; var components = new List<Component>(); components.AddRange(_gameObject.GetComponentsInChildren(TypeFinder.GetType(DynamicBoneFullName))); components.AddRange(_gameObject.GetComponentsInChildren(TypeFinder.GetType(DynamicBoneColliderFullName))); components.AddRange(_gameObject.GetComponentsInChildren(TypeFinder.GetType(DynamicBonePlaneColliderFullName))); if (components.Count == 0) return; // differ { var added = components.Where(w => !_enabledComponents.ContainsKey(w.GetInstanceID())).ToList(); var removed = _enabledComponents.Where(w => ReferenceEquals(components.SingleOrDefault(v => v.GetInstanceID() == w.Key), null)).ToList(); foreach (var component in added) _enabledComponents.Add(component.GetInstanceID(), false); foreach (var instanceId in removed.Select(w => w.Key)) _enabledComponents.Remove(instanceId); } EditorContent.Space(); EditorContent.Label("Enabled Components:"); foreach (var component in components) { var instanceId = component.GetInstanceID(); _enabledComponents[instanceId] = EditorContent.Checkbox(component.ToString(), _enabledComponents[instanceId]); } if (_enabledComponents.Any(w => w.Value)) { EditorContent.Space(); EditorContent.Label("Naming Conventions:"); } foreach (var component in _enabledComponents.Where(w => w.Value).Select(w => components.Single(v => v.GetInstanceID() == w.Key))) { var convention = PropertyTransformer.TransformToStringPath(component); var instance = _configurations.SingleOrDefault(w => w.OriginalInstanceId == component.GetInstanceID()); if (ReferenceEquals(instance, null)) { instance = new DynamicBoneConfiguration(); instance.Name = instance.NamingConvention = convention; instance.Component = component; instance.OriginalInstanceId = component.GetInstanceID(); _configurations.Add(instance); } instance.NamingConvention = EditorContent.TextField(component.ToString(), instance.NamingConvention); } // cleanup instances foreach (var configuration in _enabledComponents.Where(w => !w.Value).Select(w => _configurations.SingleOrDefault(v => w.Key == v.OriginalInstanceId)).Where(w => !ReferenceEquals(w, null)).ToList()) _configurations.Remove(configuration); EditorContent.Space(); EditorContent.Label("DynamicBone Preset Manager convert hierarchy tree to the below name:"); EditorContent.Label("Avatar → Armature → Hips → ... to Avatar/Armature/Hips/..."); EditorContent.Label("If you want to preserve the tree structure, use `/` and `[^/]*?` in the naming convention."); using (EditorContent.DisabledGroup(_configurations.Count == 0)) _name = EditorContent.TextField("Preset Name", _name); using (EditorContent.DisabledGroup(string.IsNullOrEmpty(_name) || _configurations.Count == 0)) if (EditorContent.Button("Create DynamicBone Preset")) CreatePreset(); }
private static void ApplyArrayToProperty(SerializedProperty property, List <Transform> transforms) { if (transforms.Count == 0) { return; } for (var i = 0; i < transforms.Count; i++) { property.InsertArrayElementAtIndex(i); property.GetArrayElementAtIndex(i).objectReferenceValue = transforms[i].gameObject.GetComponent(TypeFinder.GetType("DynamicBoneCollider")); } property.serializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public override object ProvideValue(IServiceProvider serviceProvider) { var targetProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; if (targetProvider == null) { return(null); } var target = targetProvider.TargetObject as FrameworkElement; if (target == null) { return(null); } Type handlerType = null; var eventInfo = targetProvider.TargetProperty as EventInfo; if (eventInfo != null) { handlerType = eventInfo.EventHandlerType; } else { var method = targetProvider.TargetProperty as MethodInfo; handlerType = method.GetParameters()[1].ParameterType; } Action <object, object> invoke = null; if (string.IsNullOrEmpty(_bridge)) { invoke = (_, __) => target.DataContext.GetType().GetMethod(_path).Invoke(target.DataContext, new object[0]); } else { var items = _bridge.Split('.'); if (items.Length < 2) { return(null); } var bridgeType = TypeFinder.GetType(string.Join(".", items.Take(items.Length - 1))); if (bridgeType == null) { return(null); } var methodInfo = bridgeType.GetMethod(items[items.Length - 1]); var args = methodInfo.GetParameters(); if (args.Length != 3 && typeof(Delegate).IsAssignableFrom(args[2].ParameterType)) { return(null); } invoke = (o, e) => methodInfo.Invoke(null, new object[] { o, e, target.DataContext.GetType().GetMethod(_path).CreateDelegate(args[2].ParameterType, target.DataContext) }); } var arguments = handlerType.GetMethod("Invoke").GetParameters().Select(e => e.ParameterType).ToArray(); var conType = typeof(Listener <,>).MakeGenericType(arguments[0], arguments[1]); return(conType.GetMethod("Connect").Invoke(null, new object[] { handlerType, invoke })); }
public void Get_ThrowsException_IfTypeNotFound() { Assert.Throws <UnableToReadXMLTextException>(() => typeFinder.GetType("NSerializer.UATs.BasicUsage"), "Unable to find type 'NSerializer.UATs.BasicUsage'."); }
/// <summary> /// create object. /// </summary> static ReturnInfo VarNew(IAsyncInvoke async, VarPool varManager, TypeFinder typeFinder, ProtocolInfo info) { Type type = typeFinder.GetType(info.TypeFullName); if (type == null) { throw new InformationException(string.Format(CultureInfo.CurrentCulture, ResourcesLocal.Instance.UnknownTypeInfoFormat, info.TypeFullName)); } object[] args; Type[] argTypesOri; ResolveArgs(varManager, info.Arguments, out args, out argTypesOri); Type[] argTypes = GetArgTypes(typeFinder, info.OperationTypeInfo, argTypesOri); //value type. if (argTypes.Length == 0 && type.IsValueType()) { return(new ReturnInfo(varManager.Add(Activator.CreateInstance(type)))); } //resolve overload. ConstructorInfo[] constructorInfos = type.GetConstructors(); List <ConstructorInfo> constructorList = new List <ConstructorInfo>(); bool isObjectArrayArg = false; for (int i = 0; i < constructorInfos.Length; i++) { ParameterInfo[] paramInfos = constructorInfos[i].GetParameters(); bool isPerfect; bool isObjectArrayArgTmp; if (IsMatchParameter(info.OperationTypeInfo != null, argTypes, paramInfos, out isPerfect, out isObjectArrayArgTmp)) { if (isPerfect) { constructorList.Clear(); constructorList.Add(constructorInfos[i]); break; } constructorList.Add(constructorInfos[i]); } if (isObjectArrayArgTmp) { isObjectArrayArg = true; } } //not found. if (constructorList.Count == 0) { if (isObjectArrayArg) { throw new InformationException(string.Format(CultureInfo.CurrentCulture, ResourcesLocal.Instance.ErrorNotFoundConstractorFormatForObjectArray, type.Name, MakeErrorInvokeArgInfo(argTypes))); } else { throw new InformationException(string.Format(CultureInfo.CurrentCulture, ResourcesLocal.Instance.ErrorNotFoundConstractorFormat, type.Name, MakeErrorInvokeArgInfo(argTypes))); } } if (constructorList.Count != 1) { //can't resolve overload. throw new InformationException(string.Format(CultureInfo.CurrentCulture, ResourcesLocal.Instance.ErrorManyFoundConstractorFormat, type.Name, MakeErrorInvokeArgInfo(argTypes))); } //create. bool isCreated = false;//TODO object instance = null; async.Execute(() => { instance = constructorList[0].Invoke(args); isCreated = true; }); while (!isCreated) { Thread.Sleep(0); } //resolve ref, out. ReflectArgsAfterInvoke(varManager, info.Arguments, args); //entry object. return(new ReturnInfo(varManager.Add(instance))); }