Dreamine.PLC.Omron.CxComponent 1.0.1
Dreamine.PLC.Omron.CxComponent 산업 자동화 및 I/O 기능을 제공합니다.
로딩중...
검색중...
일치하는것 없음
ComInvoker.cs
이 파일의 문서화 페이지로 가기
1using System.Globalization;
2using System.Reflection;
3using System.Text;
4
6
15internal static class ComInvoker
16{
65 public static void SetProperty(object target, string name, object? value)
66 {
67 try
68 {
69 target.GetType().InvokeMember(
70 name,
71 BindingFlags.SetProperty,
72 binder: null,
73 target,
74 [value],
75 CultureInfo.InvariantCulture);
76 }
77 catch (TargetInvocationException ex) when (ex.InnerException is not null)
78 {
79 throw CreateDetailedException($"CX-Compolet property '{name}'", ex);
80 }
81 }
82
139 public static object? Invoke(object target, string name, params object?[] args)
140 {
141 try
142 {
143 return target.GetType().InvokeMember(
144 name,
145 BindingFlags.InvokeMethod,
146 binder: null,
147 target,
148 args,
149 CultureInfo.InvariantCulture);
150 }
151 catch (TargetInvocationException ex) when (ex.InnerException is not null)
152 {
153 throw CreateDetailedException($"CX-Compolet method '{name}'", ex);
154 }
155 }
156
189 private static InvalidOperationException CreateDetailedException(
190 string operation,
191 TargetInvocationException exception)
192 {
193 var message = new StringBuilder(operation);
194 message.Append(" failed.");
195
196 for (Exception? current = exception.InnerException; current is not null; current = current.InnerException)
197 {
198 message.Append(' ')
199 .Append(current.GetType().Name)
200 .Append(": ")
201 .Append(current.Message);
202 }
203
204 return new InvalidOperationException(message.ToString(), exception.InnerException);
205 }
206}