Dreamine.PLC.Mitsubishi.MxComponent 1.0.1
Dreamine.PLC.Mitsubishi.MxComponent 산업 자동화 및 I/O 기능을 제공합니다.
로딩중...
검색중...
일치하는것 없음
ComInvoker.cs
이 파일의 문서화 페이지로 가기
1using System.Globalization;
2using System.Reflection;
3using System.Text;
4
6
15internal static class ComInvoker
16{
73 public static void SetProperty(object target, string name, object? value)
74 {
75 try
76 {
77 target.GetType().InvokeMember(
78 name,
79 BindingFlags.SetProperty,
80 binder: null,
81 target,
82 [value],
83 CultureInfo.InvariantCulture);
84 }
85 catch (TargetInvocationException ex) when (ex.InnerException is not null)
86 {
87 throw CreateDetailedException($"MX Component property '{name}'", ex);
88 }
89 }
90
147 public static object? Invoke(object target, string name, params object?[] args)
148 {
149 try
150 {
151 return target.GetType().InvokeMember(
152 name,
153 BindingFlags.InvokeMethod,
154 binder: null,
155 target,
156 args,
157 CultureInfo.InvariantCulture);
158 }
159 catch (TargetInvocationException ex) when (ex.InnerException is not null)
160 {
161 throw CreateDetailedException($"MX Component method '{name}'", ex);
162 }
163 }
164
237 public static object? InvokeWithByRef(object target, string name, object?[] args, params int[] byRefIndexes)
238 {
239 var modifiers = new ParameterModifier(args.Length);
240 foreach (var index in byRefIndexes)
241 {
242 modifiers[index] = true;
243 }
244
245 try
246 {
247 return target.GetType().InvokeMember(
248 name,
249 BindingFlags.InvokeMethod,
250 binder: null,
251 target,
252 args,
253 [modifiers],
254 CultureInfo.InvariantCulture,
255 namedParameters: null);
256 }
257 catch (TargetInvocationException ex) when (ex.InnerException is not null)
258 {
259 throw CreateDetailedException($"MX Component method '{name}'", ex);
260 }
261 }
262
303 public static int ToReturnCode(object? value)
304 {
305 return value is null ? 0 : Convert.ToInt32(value, CultureInfo.InvariantCulture);
306 }
307
340 private static InvalidOperationException CreateDetailedException(string operation, TargetInvocationException exception)
341 {
342 var message = new StringBuilder(operation);
343 message.Append(" failed.");
344
345 for (Exception? current = exception.InnerException; current is not null; current = current.InnerException)
346 {
347 message.Append(' ')
348 .Append(current.GetType().Name)
349 .Append(": ")
350 .Append(current.Message);
351 }
352
353 if (message.ToString().Contains("System.ServiceModel.AddressAlreadyInUseException", StringComparison.Ordinal))
354 {
355 message.Append(" Mitsubishi MX Component 64-bit DotUtlType64 wrapper depends on legacy .NET Framework WCF types that are not available in this .NET runtime. Run the sample as x86 with ProgID 'ActUtlType.ActUtlType', or host the MX 64-bit wrapper from a .NET Framework process.");
356 }
357
358 return new InvalidOperationException(message.ToString(), exception.InnerException);
359 }
360}