public void ExecuteEncryptedBytes(Type encryptorType) { var encryptor = (ISymmetricEncryptor)ActivatorTool.CreateInstance(encryptorType); var adapter = GetDataServiceAdapter(ba => { ba.DataService = GetDataService(); ba.RequestSerializer = new EncryptSerializer <RequestMessage>( GetRequestSerializer(), encryptor); ba.ResponseSerializer = new EncryptSerializer <ResponseMessage>(GetResponseSerializer(), encryptor); return(ba); }); var requestMsg = BuildRequest(); var requestBytes = adapter.RequestSerializer.Serialize(requestMsg); requestBytes.Should().Not.Be.Null(); var responseBytes = adapter.Execute(requestBytes); responseBytes.Should().Not.Be.Null(); var responseMsg = adapter.ResponseSerializer.Deserialize(responseBytes); VerifyResponseMessage(responseMsg); }
public void ExecuteEncryptedText(Type encryptorType) { var encryptor = (ISymmetricEncryptor)ActivatorTool.CreateInstance(encryptorType); var adapter = GetXmlDataManagerAdapter(ba => { ba.XmlDataManager = GetXmlDataManager(); ba.RequestSerializer = new EncryptSerializer <XdsRequestDocument>(GetRequestSerializer(), encryptor); ba.ResponseSerializer = new EncryptSerializer <XdsResponseDocument>(GetResponseSerializer(), encryptor); return(ba); }); var requestMsg = BuildRequest(); var requestBytes = adapter.RequestSerializer.Serialize(requestMsg); var responseBytes = adapter.Execute(requestBytes.Base64Encode()).Base64Decode(); responseBytes.Should().Not.Be.Null(); var responseMsg = adapter.ResponseSerializer.Deserialize(responseBytes); VerifyXdsResponseDocument(responseMsg); }
public void Serialized_Caching(Type serializerType) { var serializer = (ISerializer)ActivatorTool.CreateInstance(serializerType); var repository = new SharedCacheRepository(serializer); var tasks = new List <TaskCacheItem>(); var cachedTasks = new List <TaskCacheItem>(); for (var i = 0; i < 10; i++) { var task = new TaskCacheItem() { IsDone = false, Summary = "Task " + i + " to cached.", Data = ArrayTool.GetRandomBytes(0x2000) }; tasks.Add(task); repository.Set(task.Id.ToString(), task); } foreach (var task in tasks) { var cachedTask = repository.Get(task.Id.ToString()) as TaskCacheItem; cachedTask.Should().Not.Be.Null(); cachedTasks.Add(cachedTask); } }
public void ExecuteCompressedText(Type compressorType) { var compressor = (ICompressor)ActivatorTool.CreateInstance(compressorType); var adapter = GetDataServiceAdapter(ba => { ba.DataService = GetDataService(); ba.RequestSerializer = new CompressSerializer <RequestMessage>( GetRequestSerializer(), compressor); ba.ResponseSerializer = new CompressSerializer <ResponseMessage>(GetResponseSerializer(), compressor); return(ba); }); var requestMsg = BuildRequest(); var requestBytes = adapter.RequestSerializer.Serialize(requestMsg); var responseBytes = adapter.Execute(requestBytes.Base64Encode()).Base64Decode(); responseBytes.Should().Not.Be.Null(); var responseMsg = adapter.ResponseSerializer.Deserialize(responseBytes); VerifyResponseMessage(responseMsg); }
/// <summary> /// Castle.Windsor 환경설정 정보에 있는 속성정보를 Instance의 속성 값으로 매핑한다. /// </summary> /// <param name="configuration">Castle configuration object</param> /// <param name="targetType">target type</param> /// <returns></returns> public override object PerformConversion(IConfiguration configuration, Type targetType) { configuration.ShouldNotBeNull("configuration"); targetType.ShouldNotBeNull("targetType"); if (IsDebugEnabled) { log.Debug("Perform conversion configuration value to property. configuration={0}, targetType={1}", configuration, targetType); } var instance = ActivatorTool.CreateInstance(targetType); var accessor = DynamicAccessorFactory.CreateDynamicAccessor(targetType, false); const BindingFlags flags = BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; foreach (var itemConfig in configuration.Children) { var propInfo = targetType.GetProperty(itemConfig.Name, flags); // convert from string to object var value = Context.Composition.PerformConversion(itemConfig.Value, propInfo.PropertyType); accessor.SetPropertyValue(instance, itemConfig.Name, value); } return(instance); }
/// <summary> /// <see cref="Periods"/>들의 Gap 부분들만을 기간 컬렉션으로 반환합니다. /// </summary> /// <returns>Gap 기간들의 컬렉션</returns> public ITimePeriodCollection CalcuateGaps() { if (IsDebugEnabled) { log.Debug("ITimePeriod 사이의 Gap들을 계산하여 ITimePeriod 컬렉션으로 반환합니다..."); } // exclude periods // var gapPeriods = new TimePeriodCollection(); foreach (var period in Periods.Where(p => Limits.IntersectsWith(p))) { gapPeriods.Add(new TimeRange(period)); } var timeLineMoments = GetTimeLineMoments(gapPeriods); if (timeLineMoments.Count == 0) { return new TimePeriodCollection { Limits } } ; var range = ActivatorTool.CreateInstance <T>(); range.Setup(MapPeriodStart(Limits.Start), MapPeriodEnd(Limits.End)); return(timeLineMoments.CalculateGaps <T>(range)); }
/// <summary> /// NHibernate ResultSet으로부터 나온 object[]를 지정된 형식의 인스턴스의 속성값에 매칭시킨다. /// </summary> /// <param name="tuple">결과 값</param> /// <param name="aliases">컬럼 명</param> /// <returns></returns> public object TransformTuple(object[] tuple, string[] aliases) { if (IsDebugEnabled) { log.Debug("결과값을 새로운 인스턴스의 속성값으로 설정합니다. Target Type=[{0}], tuple=[{1}], aliases=[{2}]", _entityType.FullName, tuple.CollectionToString(), aliases.CollectionToString()); } T result; try { result = ActivatorTool.CreateInstance <T>(); for (var i = 0; i < aliases.Length; i++) { DynamicAccessor.SetPropertyValue(result, aliases[i], tuple[i]); } if (IsDebugEnabled) { log.Debug("새로운 엔티티를 생성하고, NHibernate ResultSet을 엔티티의 속성 값에 설정했습니다. result=[{0}]", result); } } catch (Exception ex) { if (log.IsErrorEnabled) { log.Error("Fail to transform to instance. type=[{0}]", _entityType.FullName); log.Error(ex); } return(tuple); } return(result); }
/// <summary> /// Resolves singly registered services that support arbitrary object creation. /// </summary> /// <returns> The requested service or object. </returns> /// <param name="serviceType"> The type of the requested service or object. </param> public object GetService(Type serviceType) { if (IsDebugEnabled) { log.Debug("Service를 생성합니다... serviceType=[{0}]", serviceType.FullName); } if (serviceType.IsInterface || serviceType.IsAbstract) { return(null); } // Contructor 가 없다면 null 을 반환한다. var ciArray = serviceType.GetConstructors(); if (ciArray.Length == 0) { return(null); } // 동적으로 생성되는 View 용 Class에 대해서는 Service를 제공할 수 없다. if (serviceType.IsSubclassOf(typeof(System.Web.Mvc.WebViewPage)) || serviceType.IsSubclassOf(typeof(System.Web.Mvc.WebViewPage <>))) { return(null); } return(IoC.TryResolve(() => ActivatorTool.CreateInstance(serviceType), true, LifestyleType.Transient)); }
public byte[] GetDecompressData() { if (CompressedData == null) { return(EmptyData); } if (CompressorType == null) { return(EmptyData); } try { var compressor = ActivatorTool.CreateInstance(CompressorType) as ICompressor; if (compressor == null) { return(EmptyData); } return(compressor.Decompress(CompressedData)); } catch (Exception ex) { if (log.IsErrorEnabled) { log.ErrorException("압축하여 저장한 정보를 압축 해제하는데 실패했습니다", ex); } } return(EmptyData); }
public void ExecuteCompressedBytes(Type compressorType) { var compressor = (ICompressor)ActivatorTool.CreateInstance(compressorType); var adapter = GetXmlDataManagerAdapter(ba => { ba.XmlDataManager = GetXmlDataManager(); ba.RequestSerializer = new CompressSerializer <XdsRequestDocument>(GetRequestSerializer(), compressor); ba.ResponseSerializer = new CompressSerializer <XdsResponseDocument>(GetResponseSerializer(), compressor); return(ba); }); var requestMsg = BuildRequest(); var requestData = adapter.RequestSerializer.Serialize(requestMsg); requestData.Should().Not.Be.Null(); var responseData = adapter.Execute(requestData); responseData.Should().Not.Be.Null(); var responseMsg = adapter.ResponseSerializer.Deserialize(responseData); VerifyXdsResponseDocument(responseMsg); }
public void InvokeMethodAsParallel() { var person = ActivatorTool.CreateInstance(typeof(Person), new object[] { 0, "John" }); PersonType.InvokeMethodAsParallel(0, RunCount, null, (i, invoker) => invoker(person, 1), "Walk", typeof(int)); Assert.AreEqual(RunCount, person.GetField("milesTraveled").AsInt()); }
public static void Assert <TException>(bool condition, string fmt, params object[] args) where TException : Exception { if (condition) { return; } throw ActivatorTool.CreateInstance <TException>(new[] { string.Format(fmt, args) }); }
public static void Assert <TException>(bool condition) where TException : Exception { if (condition) { return; } throw ActivatorTool.CreateInstance <TException>(); }
private static IValidator CreateValidatorInstance(Type concreteType) { if (concreteType != null) { return(ActivatorTool.CreateInstance(concreteType) as IValidator); } return(null); }
/// <summary> /// ITimeLineMomentCollection으로부터 교집합에 해당하는 기간들을 구합니다 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="timeLineMoments"></param> /// <returns></returns> public static ITimePeriodCollection IntersectPeriods <T>(this ITimeLineMomentCollection timeLineMoments) where T : ITimePeriod { if (IsDebugEnabled) { log.Debug("ITimeLineMomentCollection으로부터 교집합에 해당하는 기간들을 구합니다..."); } var periods = new TimePeriodCollection(); if (timeLineMoments.IsEmpty) { return(periods); } // search for periods var intersectionStart = -1; var balance = 0; for (var i = 0; i < timeLineMoments.Count; i++) { var moment = timeLineMoments[i]; balance += moment.StartCount; balance -= moment.EndCount; // intersection is starting by a period start if (moment.StartCount > 0 && balance > 1 && intersectionStart < 0) { intersectionStart = i; continue; } // intersection is starting by a period end if (moment.EndCount > 0 && balance <= 1 && intersectionStart >= 0) { var period = ActivatorTool.CreateInstance <T>(); period.Setup(timeLineMoments[intersectionStart].Moment, moment.Moment); if (IsDebugEnabled) { log.Debug("Intersect Period를 추가합니다. period=[{0}]", period); } periods.Add(period); intersectionStart = -1; } } if (IsDebugEnabled) { log.Debug("ITimeLineMomentCollection으로부터 교집합에 해당하는 기간들을 구했습니다. periods=[{0}]", periods.CollectionToString()); } return(periods); }
/// <summary> /// AdoResultSet의 Value인 <see cref="AdoResultRow"/>의 정보를 바탕으로 <paramref name="targetType"/>로 매핑합니다. /// </summary> /// <param name="targetType">매핑할 수형</param> /// <returns>AdoResultRow의 값으로 매핑된 <see cref="targetType"/> 수형의 인스턴스의 컬렉션.</returns> public virtual IEnumerable <object> GetMappedObjects(Type targetType) { targetType.ShouldNotBeNull("targetType"); if (IsDebugEnabled) { log.Debug("Row 값들을 이용하여, ResultRow를 [{0}] 수형으로 Mapping 합니다.", targetType.FullName); } return(Values.Select(r => ObjectMapper.Map(r, () => ActivatorTool.CreateInstance(targetType, true)))); }
public void InvokeMethod() { var person = ActivatorTool.CreateInstance(PersonType, new object[] { 0, "John" }); for (int i = 0; i < RunCount; i++) { PersonType.InvokeMethod(invoker => invoker(person, 1), "Walk", typeof(int)); } Assert.AreEqual(RunCount, person.GetField("milesTraveled").AsInt()); }
/// <summary> /// Castle.Windsor 환경설정 정보에 있는 값을 해당 형식의 생성자에 제공하여 인스턴스를 빌드한다. /// </summary> /// <param name="value">인스턴싱할때 생성자에 제공할 인자 값</param> /// <param name="targetType">인스턴싱할 형식</param> /// <returns></returns> public override object PerformConversion(string value, Type targetType) { targetType.ShouldNotBeNull("targetType"); if (IsDebugEnabled) { log.Debug("Perform conversion configuration value to property. value:{0}, targetType:{1}", value, targetType); } return(ActivatorTool.CreateInstance(targetType, new object[] { value })); }
public static void Assert <TException>(this Expression <Func <bool> > expression, string fmt, params object[] args) where TException : Exception { expression.ShouldNotBeNull("expression"); if (expression.Compile().Invoke()) { return; } throw ActivatorTool.CreateInstance <TException>(new[] { string.Format(fmt, args) }); }
/// <summary> /// 결과 정보를 가지고, 지정된 형식의 인스턴스를 생성해서 반환한다. /// </summary> /// <param name="tuple">쿼리 실행 결과 배열</param> /// <param name="aliases"></param> /// <returns>쿼리 실행결과를 인자로 한 인스턴스</returns> public object TransformTuple(object[] tuple, string[] aliases) { if (tuple.Length == 1) { return(tuple[0]); } // T 형식의 생성자가 tuple에 해당하는 모든 인자를 받아들이는 생성자가 있어야 한다. // return(ActivatorTool.CreateInstance(_entityType, tuple)); // return Activator.CreateInstance(typeof(T), tuple); }
/// <summary> /// 지정한 AppDomain에서 비동기 호출을 수행하는 <see cref="AsyncCall{T}"/>를 생성합니다. /// </summary> public static AsyncCall <T> CreateInTargetAppDomain <T>(AppDomain targetDomain, Action <T> actionHandler, int maxDegreeOfParallelism = 1, int maxItemsPerTask = Int32.MaxValue, TaskScheduler scheduler = null) { targetDomain.ShouldNotBeNull("targetDomain"); actionHandler.ShouldNotBeNull("actionHandler"); return(ActivatorTool.CreateInstance <AsyncCall <T> >(new object[] { actionHandler, maxDegreeOfParallelism, maxItemsPerTask, scheduler })); }
public void ExecuteEncryptedCompressedBytes([Values(typeof(GZipCompressor), //typeof(SharpGZipCompressor), typeof(SharpBZip2Compressor), typeof(DeflateCompressor), typeof(SevenZipCompressor), typeof(IonicBZip2Compressor), typeof(IonicDeflateCompressor), typeof(IonicGZipCompressor), typeof(IonicZlibCompressor))] Type compressorType, [Values(typeof(AriaSymmetricEncryptor), typeof(RC2SymmetricEncryptor), typeof(RijndaelSymmetricEncryptor), typeof(TripleDESSymmetricEncryptor))] Type encryptorType) { var compressor = (ICompressor)ActivatorTool.CreateInstance(compressorType); var encryptor = (ISymmetricEncryptor)ActivatorTool.CreateInstance(encryptorType); var adapter = GetXmlDataManagerAdapter(ba => { ba.XmlDataManager = GetXmlDataManager(); ba.RequestSerializer = new EncryptSerializer <XdsRequestDocument>( new CompressSerializer <XdsRequestDocument>(GetRequestSerializer(), compressor), encryptor); ba.ResponseSerializer = new EncryptSerializer <XdsResponseDocument>( new CompressSerializer <XdsResponseDocument>(GetResponseSerializer(), compressor), encryptor); return(ba); }); var requestMsg = BuildRequest(); var requestBytes = adapter.RequestSerializer.Serialize(requestMsg); requestBytes.Should().Not.Be.Null(); var responseBytes = adapter.Execute(requestBytes); responseBytes.Should().Not.Be.Null(); var responseMsg = adapter.ResponseSerializer.Deserialize(responseBytes); VerifyXdsResponseDocument(responseMsg); }
public void ExecuteCompressedEncryptedText([Values(typeof(GZipCompressor), //typeof(SharpGZipCompressor), typeof(SharpBZip2Compressor), typeof(DeflateCompressor), typeof(SevenZipCompressor), typeof(IonicBZip2Compressor), typeof(IonicDeflateCompressor), typeof(IonicGZipCompressor), typeof(IonicZlibCompressor))] Type compressorType, [Values(typeof(AriaSymmetricEncryptor), typeof(RC2SymmetricEncryptor), typeof(RijndaelSymmetricEncryptor), typeof(TripleDESSymmetricEncryptor))] Type encryptorType) { var compressor = (ICompressor)ActivatorTool.CreateInstance(compressorType); var encryptor = (ISymmetricEncryptor)ActivatorTool.CreateInstance(encryptorType); var adapter = GetDataServiceAdapter(ba => { ba.DataService = GetDataService(); ba.RequestSerializer = new CompressSerializer <RequestMessage>( new EncryptSerializer <RequestMessage>(GetRequestSerializer(), encryptor), compressor); ba.ResponseSerializer = new CompressSerializer <ResponseMessage>( new EncryptSerializer <ResponseMessage>(GetResponseSerializer(), encryptor), compressor); return(ba); }); var requestMsg = BuildRequest(); var requestBytes = adapter.RequestSerializer.Serialize(requestMsg); var responseBytes = adapter.Execute(requestBytes.Base64Encode()).Base64Decode(); responseBytes.Should().Not.Be.Null(); var responseMsg = adapter.ResponseSerializer.Deserialize(responseBytes); VerifyResponseMessage(responseMsg); }
/// <summary> /// 기본 Localization Object를 생성합니다. /// </summary> /// <returns></returns> protected virtual TLocale CreateDefaultLocale() { if (IsDebugEnabled) { log.Debug("기본 Locale 정보가 없습니다. 엔티티 [{0}] 속성으로 기본 Locale [{1}] 정보를 생성합니다...", GetType().Name, typeof(TLocale).Name); } try { return(this.MapProperty(() => ActivatorTool.CreateInstance <TLocale>(), MapPropertyOptions.Safety)); } catch (Exception ex) { if (log.IsErrorEnabled) { log.ErrorException("기본 Locale 정보를 엔티티의 속성으로부터 생성하는데 실패했습니다!!!", ex); } throw; } }
public void XmlSerialize_With_Encryption_Compress([Values(typeof(SharpBZip2Compressor), typeof(GZipCompressor), typeof(DeflateCompressor), typeof(SevenZipCompressor))] Type compressorType, [Values(typeof(AriaSymmetricEncryptor), typeof(RC2SymmetricEncryptor), typeof(TripleDESSymmetricEncryptor))] Type encryptorType) { var xmlSerializer = XmlSerializer <List <User> > .Instance; var compressor = (ICompressor)ActivatorTool.CreateInstance(compressorType); var encryptor = (ISymmetricEncryptor)ActivatorTool.CreateInstance(encryptorType); var serializer = new CompressSerializer <List <User> >(new EncryptSerializer <List <User> >(xmlSerializer, encryptor), compressor); var users = GetSampleUsers(10); var usersData = serializer.Serialize(users); var deserializedUsers = serializer.Deserialize(usersData); CollectionAssert.AreEqual(users, deserializedUsers); }
/// <summary> /// 생성자 /// </summary> public SqlCommandSet() { if (IsDebugEnabled) { log.Debug("{0}를 동적으로 생성하고, 내부 함수를 Delegate로 이용하여, 노출시킵니다.", SqlCommandSetTypeName); } _sqlCommandSetInstance = ActivatorTool.CreateInstance(_sqlCommandSetType, true); _sqlCommandSetInstance.ShouldNotBeNull(SqlCommandSetTypeName); _connectionSettter = (PropertySetter <SqlConnection>)CreateDelegate(typeof(PropertySetter <SqlConnection>), _sqlCommandSetInstance, "set_Connection"); _transactionSetter = (PropertySetter <SqlTransaction>)CreateDelegate(typeof(PropertySetter <SqlTransaction>), _sqlCommandSetInstance, "set_Transaction"); _commandTimeoutSetter = (PropertySetter <int>)CreateDelegate(typeof(PropertySetter <int>), _sqlCommandSetInstance, "set_CommandTimeout"); _connectionGetter = (PropertyGetter <SqlConnection>)CreateDelegate(typeof(PropertyGetter <SqlConnection>), _sqlCommandSetInstance, "get_Connection"); _batchCommandGetter = (PropertyGetter <SqlCommand>)CreateDelegate(typeof(PropertyGetter <SqlCommand>), _sqlCommandSetInstance, "get_BatchCommand"); _doAppend = (AppendCommand)CreateDelegate(typeof(AppendCommand), _sqlCommandSetInstance, "Append"); _doExecuteNonQuery = (ExecuteNonQueryCommand)CreateDelegate(typeof(ExecuteNonQueryCommand), _sqlCommandSetInstance, "ExecuteNonQuery"); _doDispose = (DisposeCommand)CreateDelegate(typeof(DisposeCommand), _sqlCommandSetInstance, "Dispose"); }
public void GetMethodInvoker() { var person = ActivatorTool.CreateInstance(PersonType, new object[] { 0, "John" }); var methodInvoker = PersonType.GetMethodInvoker("Walk", typeof(int)); for (int i = 0; i < RunCount; i++) { methodInvoker(person, 1); } Assert.AreEqual(RunCount, person.GetField("milesTraveled").AsInt()); person = ActivatorTool.CreateInstance(PersonType, new object[] { 1, "Merry" }); methodInvoker = PersonType.GetMethodInvoker("Walk"); for (int i = 0; i < RunCount; i++) { methodInvoker(person); } Assert.AreEqual(RunCount, person.GetField("milesTraveled").AsInt()); }
/// <summary> /// <paramref name="timeLineMoments"/>가 가진 모든 ITimePeriod 들의 Gap을 계산합니다. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="timeLineMoments"></param> /// <param name="range"></param> /// <returns></returns> public static ITimePeriodCollection CalculateGaps <T>(this ITimeLineMomentCollection timeLineMoments, ITimePeriod range) where T : ITimePeriod { if (IsDebugEnabled) { log.Debug("ITimeLineMomentCollection의 Gap들을 계산합니다..."); } var gaps = new TimePeriodCollection(); if (timeLineMoments.IsEmpty) { return(gaps); } // find leading gap // var periodStart = timeLineMoments.Min; if (periodStart != null && range.Start < periodStart.Moment) { var startingGap = ActivatorTool.CreateInstance <T>(); startingGap.Setup(range.Start, periodStart.Moment); if (IsDebugEnabled) { log.Debug("Starting Gap을 추가합니다... startingGap=[{0}]", startingGap); } gaps.Add(startingGap); } // find intermediated gap // var itemIndex = 0; while (itemIndex < timeLineMoments.Count) { var moment = timeLineMoments[itemIndex]; Guard.Assert(moment.StartCount != 0, "monent.StartCount 값은 0이 아니여야 합니다. moment=[{0}]", moment); // search next gap start // use balancing to handle overlapping periods var balance = moment.StartCount; ITimeLineMoment gapStart = null; while (itemIndex < timeLineMoments.Count - 1 && balance > 0) { itemIndex++; gapStart = timeLineMoments[itemIndex]; balance += gapStart.StartCount; balance -= gapStart.EndCount; } gapStart.ShouldNotBeNull("gapStart"); if (gapStart.StartCount > 0) // touching { itemIndex++; continue; } // found a gap if (itemIndex < timeLineMoments.Count - 1) { var gap = ActivatorTool.CreateInstance <T>(); gap.Setup(gapStart.Moment, timeLineMoments[itemIndex + 1].Moment); if (IsDebugEnabled) { log.Debug("Intermediated Gap을 추가합니다. gap=[{0}]", gap); } gaps.Add(gap); } itemIndex++; } // find ending gap // var periodEnd = timeLineMoments.Max; if (periodEnd != null && range.End > periodEnd.Moment) { var endingGap = ActivatorTool.CreateInstance <T>(); endingGap.Setup(periodEnd.Moment, range.End); if (IsDebugEnabled) { log.Debug("Ending Gap을 추가합니다. endingGap=[{0}]", endingGap); } gaps.Add(endingGap); } if (IsDebugEnabled) { log.Debug("기간들의 Gap에 해당하는 부분을 계산했습니다!!! gaps=[{0}]", gaps.CollectionToString()); } return(gaps); }
public void Can_Create_EditableObject_Proxy_Factory() { var proxy = (SimpleViewModel)DynamicProxyTool.CreateEditableObject(() => ActivatorTool.CreateInstance <SimpleViewModel>()); VerifyEditableObject(proxy); }
/// <summary> /// ITimeLineMoment 컬렉션의 모든 기간의 합집합을 구합니다. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="timeLineMoments">결합할 기간들</param> /// <returns></returns> public static ITimePeriodCollection CombinePeriods <T>(this ITimeLineMomentCollection timeLineMoments) where T : ITimePeriod { if (IsDebugEnabled) { log.Debug("ITimeLineMoment 컬렉션의 모든 기간의 합집합을 구합니다..."); } var periods = new TimePeriodCollection(); if (timeLineMoments.IsEmpty) { return(periods); } // search for periods var itemIndex = 0; while (itemIndex < timeLineMoments.Count) { var periodStart = timeLineMoments[itemIndex]; Guard.Assert(periodStart.StartCount != 0, "StartCount 값은 0이 아니여야 합니다. periodStart.StartCount=[{0}]", periodStart.StartCount); // search next period end // use balancing to handle overlapping periods var balance = periodStart.StartCount; ITimeLineMoment periodEnd = null; while (itemIndex < timeLineMoments.Count - 1 && balance > 0) { itemIndex++; periodEnd = timeLineMoments[itemIndex]; balance += periodEnd.StartCount; balance -= periodEnd.EndCount; } periodEnd.ShouldNotBeNull("periodEnd"); if (periodEnd.StartCount > 0) // touching { itemIndex++; continue; } // found a period if (itemIndex < timeLineMoments.Count) { var period = ActivatorTool.CreateInstance <T>(); period.Setup(periodStart.Moment, periodEnd.Moment); if (IsDebugEnabled) { log.Debug("Combine Period를 추가합니다. period=[{0}]" + period); } periods.Add(period); } itemIndex++; } if (IsDebugEnabled) { log.Debug("기간들을 결합했습니다. periods=[{0}]", periods.CollectionToString()); } return(periods); }