Dreamine.MVVM.Locators 1.0.10
Dreamine.MVVM.Locators 프로젝트의 API와 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
Dreamine.MVVM.Locators.ViewModelLocator 클래스 참조

더 자세히 ...

정적 Public 멤버 함수

static void Register (Type viewType, Type viewModelType)
static void RegisterResolver (IViewModelResolver resolver)
static void ClearResolver ()
static void Clear ()
static void Reset ()
static ? object Resolve (Type viewType)
static ? object ResolveView (Type viewModelType)
static void RegisterAll (Assembly assembly)

정적 Private 멤버 함수

static ViewModelLocator ()
static ? Type FindViewModelType (Type viewType, Type[]? cachedTypes=null)
static Type[] GetAllLoadableTypes ()
static IEnumerable< Type > GetLoadableTypes (Assembly assembly)
static ? Type FindViewType (Type viewModelType)
static ? object CreateInstance (Type type)
static void ClearTypeCache ()

정적 Private 속성

static readonly object _syncRoot = new()
static readonly Dictionary< Type, Type > _map = new(32)
static readonly Dictionary< Type, Type?> _viewModelTypeCache = new(32)
static readonly Dictionary< Type, Type?> _viewTypeCache = new(32)
static ? IViewModelResolver _resolver
static ? Type[] _allLoadableTypesCache

상세한 설명

View와 ViewModel 간의 타입 매핑 및 인스턴스 생성을 이름과 네임스페이스 규칙으로 지원합니다.

ViewModelLocator.cs 파일의 14 번째 라인에서 정의되었습니다.

생성자 & 소멸자 문서화

◆ ViewModelLocator()

Dreamine.MVVM.Locators.ViewModelLocator.ViewModelLocator ( )
inlinestaticprivate

어셈블리 로드 시 타입 검색 캐시가 초기화되도록 로케이터를 구성합니다.

ViewModelLocator.cs 파일의 79 번째 라인에서 정의되었습니다.

80 {
81 AppDomain.CurrentDomain.AssemblyLoad += (_, _) => ClearTypeCache();
82 }

다음을 참조함 : ClearTypeCache().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 함수 문서화

◆ Clear()

void Dreamine.MVVM.Locators.ViewModelLocator.Clear ( )
inlinestatic

구성된 확인자는 유지하고 등록된 매핑과 타입 검색 캐시를 지웁니다.

ViewModelLocator.cs 파일의 186 번째 라인에서 정의되었습니다.

187 {
188 lock (_syncRoot)
189 {
190 _map.Clear();
191 _viewModelTypeCache.Clear();
192 _viewTypeCache.Clear();
193 _allLoadableTypesCache = null;
194 }
195 }

다음을 참조함 : _allLoadableTypesCache, _map, _syncRoot, _viewModelTypeCache, _viewTypeCache.

◆ ClearResolver()

void Dreamine.MVVM.Locators.ViewModelLocator.ClearResolver ( )
inlinestatic

구성된 ViewModel 확인자를 제거합니다.

ViewModelLocator.cs 파일의 170 번째 라인에서 정의되었습니다.

171 {
172 lock (_syncRoot)
173 {
174 _resolver = null;
175 }
176 }

다음을 참조함 : _resolver, _syncRoot.

◆ ClearTypeCache()

void Dreamine.MVVM.Locators.ViewModelLocator.ClearTypeCache ( )
inlinestaticprivate

View 및 ViewModel 타입 검색 캐시를 지웁니다.

ViewModelLocator.cs 파일의 669 번째 라인에서 정의되었습니다.

670 {
671 lock (_syncRoot)
672 {
673 _viewModelTypeCache.Clear();
674 _viewTypeCache.Clear();
675 _allLoadableTypesCache = null;
676 }
677 }

다음을 참조함 : _allLoadableTypesCache, _syncRoot, _viewModelTypeCache, _viewTypeCache.

다음에 의해서 참조됨 : ViewModelLocator().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ CreateInstance()

? object Dreamine.MVVM.Locators.ViewModelLocator.CreateInstance ( Type type)
inlinestaticprivate

구성된 확인자를 사용해 지정한 타입의 인스턴스를 생성합니다.

매개변수
type생성할 타입입니다.
반환값
확인자가 생성한 인스턴스입니다.
예외
InvalidOperationException확인자가 구성되지 않았거나 타입을 확인하지 못한 경우 발생합니다.

ViewModelLocator.cs 파일의 632 번째 라인에서 정의되었습니다.

633 {
634 System.Diagnostics.Debug.WriteLine($"[ViewModelLocator] CreateInstance: {type.FullName}");
635
636 IViewModelResolver? resolver;
637 lock (_syncRoot)
638 {
639 resolver = _resolver;
640 }
641
642 if (resolver is null)
643 {
644 throw new InvalidOperationException(
645 $"Cannot resolve ViewModel [{type.FullName}] because no ViewModel resolver is configured. " +
646 "Call ViewModelLocator.RegisterResolver(...) or configure DreamineAppBuilder to use the default DMContainer resolver.");
647 }
648
649 var resolved = resolver.Resolve(type);
650 if (resolved is not null)
651 {
652 return resolved;
653 }
654
655 throw new InvalidOperationException(
656 $"Cannot resolve ViewModel [{type.FullName}]. " +
657 "The type was not resolved by the configured resolver. " +
658 "Register the ViewModel in the configured container or replace the ViewModelLocator resolver.");
659 }

다음을 참조함 : _resolver, _syncRoot.

다음에 의해서 참조됨 : Resolve().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ FindViewModelType()

? Type Dreamine.MVVM.Locators.ViewModelLocator.FindViewModelType ( Type viewType,
Type?[] cachedTypes = null )
inlinestaticprivate

이름 규칙과 선택적 타입 목록을 사용해 View에 대응하는 ViewModel 타입을 찾습니다.

매개변수
viewTypeView 타입입니다.
cachedTypes선택적으로 미리 확보한 검색 타입 목록입니다.
반환값
대응하는 ViewModel 타입이며, 찾지 못하면 null입니다.

ViewModelLocator.cs 파일의 411 번째 라인에서 정의되었습니다.

412 {
413 if (cachedTypes is null)
414 {
415 lock (_syncRoot)
416 {
417 if (_viewModelTypeCache.TryGetValue(viewType, out Type? cachedViewModelType))
418 {
419 return cachedViewModelType;
420 }
421 }
422 }
423
424 Type[] allTypes = cachedTypes ?? GetAllLoadableTypes();
425 string[] candidateNames = ViewNamingConvention.GetViewModelTypeNameCandidates(viewType);
426
427 foreach (string candidateName in candidateNames)
428 {
429 Type? match = allTypes.FirstOrDefault(t =>
430 t.FullName == candidateName ||
431 t.Name == candidateName);
432
433 if (match != null)
434 {
435 if (cachedTypes is null)
436 {
437 lock (_syncRoot)
438 {
439 _viewModelTypeCache[viewType] = match;
440 }
441 }
442
443 return match;
444 }
445 }
446
447 if (cachedTypes is null)
448 {
449 lock (_syncRoot)
450 {
451 _viewModelTypeCache[viewType] = null;
452 }
453 }
454
455 return null;
456 }

다음을 참조함 : _syncRoot, _viewModelTypeCache, GetAllLoadableTypes(), Dreamine.MVVM.Locators.ViewNamingConvention.GetViewModelTypeNameCandidates().

다음에 의해서 참조됨 : RegisterAll(), Resolve().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ FindViewType()

? Type Dreamine.MVVM.Locators.ViewModelLocator.FindViewType ( Type viewModelType)
inlinestaticprivate

이름 규칙에 따라 ViewModel 타입에 대응하는 View 타입을 찾습니다.

매개변수
viewModelTypeViewModel 타입입니다.
반환값
대응하는 View 타입이며, 찾지 못하면 null입니다.

ViewModelLocator.cs 파일의 562 번째 라인에서 정의되었습니다.

563 {
564 lock (_syncRoot)
565 {
566 if (_viewTypeCache.TryGetValue(viewModelType, out Type? cachedViewType))
567 {
568 return cachedViewType;
569 }
570 }
571
572 Type[] allTypes = GetAllLoadableTypes();
573 string[] candidateNames = ViewNamingConvention.GetViewTypeNameCandidates(viewModelType);
574
575 foreach (string candidateName in candidateNames)
576 {
577 Type? match = allTypes.FirstOrDefault(t =>
578 t.FullName == candidateName ||
579 t.Name == candidateName);
580
581 if (match != null)
582 {
583 lock (_syncRoot)
584 {
585 _viewTypeCache[viewModelType] = match;
586 }
587
588 return match;
589 }
590 }
591
592 lock (_syncRoot)
593 {
594 _viewTypeCache[viewModelType] = null;
595 }
596
597 return null;
598 }

다음을 참조함 : _syncRoot, _viewTypeCache, GetAllLoadableTypes(), Dreamine.MVVM.Locators.ViewNamingConvention.GetViewTypeNameCandidates().

다음에 의해서 참조됨 : ResolveView().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GetAllLoadableTypes()

Type[] Dreamine.MVVM.Locators.ViewModelLocator.GetAllLoadableTypes ( )
inlinestaticprivate

현재 AppDomain의 모든 비동적 어셈블리에서 로드 가능한 구체 클래스 타입을 가져옵니다.

반환값
캐시된 로드 가능 타입 배열입니다.

ViewModelLocator.cs 파일의 474 번째 라인에서 정의되었습니다.

475 {
476 lock (_syncRoot)
477 {
478 if (_allLoadableTypesCache is not null)
479 {
480 return _allLoadableTypesCache;
481 }
482 }
483
484 Type[] types = AppDomain.CurrentDomain
485 .GetAssemblies()
486 .Where(assembly => !assembly.IsDynamic)
487 .SelectMany(GetLoadableTypes)
488 .Where(type => type is { IsClass: true, IsAbstract: false })
489 .ToArray();
490
491 lock (_syncRoot)
492 {
493 _allLoadableTypesCache ??= types;
494 return _allLoadableTypesCache;
495 }
496 }

다음을 참조함 : _allLoadableTypesCache, _syncRoot, GetLoadableTypes().

다음에 의해서 참조됨 : FindViewModelType(), FindViewType().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GetLoadableTypes()

IEnumerable< Type > Dreamine.MVVM.Locators.ViewModelLocator.GetLoadableTypes ( Assembly assembly)
inlinestaticprivate

지정한 어셈블리에서 로드 가능한 타입만 가져옵니다.

매개변수
assembly검색할 어셈블리입니다.
반환값
로드 가능한 타입 시퀀스이며, 조회 실패 시 빈 시퀀스입니다.

ViewModelLocator.cs 파일의 522 번째 라인에서 정의되었습니다.

523 {
524 try
525 {
526 return assembly.GetTypes();
527 }
528 catch (ReflectionTypeLoadException ex)
529 {
530 return ex.Types.Where(type => type != null)!;
531 }
532 catch
533 {
534 return Array.Empty<Type>();
535 }
536 }

다음에 의해서 참조됨 : GetAllLoadableTypes(), RegisterAll().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ Register()

void Dreamine.MVVM.Locators.ViewModelLocator.Register ( Type viewType,
Type viewModelType )
inlinestatic

View와 ViewModel 타입 매핑을 수동으로 등록합니다.

매개변수
viewTypeView 타입입니다.
viewModelTypeViewModel 타입입니다.
예외
ArgumentNullException인수 중 하나가 null인 경우 발생합니다.

ViewModelLocator.cs 파일의 116 번째 라인에서 정의되었습니다.

117 {
118 ArgumentNullException.ThrowIfNull(viewType);
119 ArgumentNullException.ThrowIfNull(viewModelType);
120
121 lock (_syncRoot)
122 {
123 _map[viewType] = viewModelType;
124 _viewModelTypeCache[viewType] = viewModelType;
125 }
126 }

다음을 참조함 : _map, _syncRoot, _viewModelTypeCache.

다음에 의해서 참조됨 : RegisterAll(), Resolve().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ RegisterAll()

void Dreamine.MVVM.Locators.ViewModelLocator.RegisterAll ( Assembly assembly)
inlinestatic

지정된 어셈블리에서 View와 ViewModel 매핑을 자동으로 등록합니다.

매개변수
assembly검색할 어셈블리입니다.
예외
ArgumentNullExceptionassemblynull인 경우 발생합니다.

ViewModelLocator.cs 파일의 348 번째 라인에서 정의되었습니다.

349 {
350 ArgumentNullException.ThrowIfNull(assembly);
351
352 Type[] allTypes = GetLoadableTypes(assembly)
353 .Where(t => t is { IsClass: true, IsAbstract: false })
354 .ToArray();
355
356 IEnumerable<Type> viewCandidates = allTypes.Where(ViewNamingConvention.IsLikelyViewType);
357
358 foreach (Type viewType in viewCandidates)
359 {
360 bool alreadyRegistered;
361 lock (_syncRoot)
362 {
363 alreadyRegistered = _map.ContainsKey(viewType);
364 }
365
366 if (alreadyRegistered)
367 {
368 continue;
369 }
370
371 Type? viewModelType = FindViewModelType(viewType, allTypes);
372 if (viewModelType != null)
373 {
374 Register(viewType, viewModelType);
375 }
376 }
377 }

다음을 참조함 : _map, _syncRoot, FindViewModelType(), GetLoadableTypes(), Dreamine.MVVM.Locators.ViewNamingConvention.IsLikelyViewType(), Register().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ RegisterResolver()

void Dreamine.MVVM.Locators.ViewModelLocator.RegisterResolver ( IViewModelResolver resolver)
inlinestatic

외부 ViewModel 확인자를 등록합니다.

매개변수
resolver등록할 확인자 구현입니다.
예외
ArgumentNullExceptionresolvernull인 경우 발생합니다.

ViewModelLocator.cs 파일의 152 번째 라인에서 정의되었습니다.

153 {
154 ArgumentNullException.ThrowIfNull(resolver);
155
156 lock (_syncRoot)
157 {
158 _resolver = resolver;
159 }
160 }

다음을 참조함 : _resolver, _syncRoot.

◆ Reset()

void Dreamine.MVVM.Locators.ViewModelLocator.Reset ( )
inlinestatic

등록된 매핑, 타입 검색 캐시 및 확인자를 포함한 모든 로케이터 상태를 초기화합니다.

ViewModelLocator.cs 파일의 205 번째 라인에서 정의되었습니다.

206 {
207 lock (_syncRoot)
208 {
209 _map.Clear();
210 _viewModelTypeCache.Clear();
211 _viewTypeCache.Clear();
212 _allLoadableTypesCache = null;
213 _resolver = null;
214 }
215 }

다음을 참조함 : _allLoadableTypesCache, _map, _resolver, _syncRoot, _viewModelTypeCache, _viewTypeCache.

◆ Resolve()

? object Dreamine.MVVM.Locators.ViewModelLocator.Resolve ( Type viewType)
inlinestatic

View 타입에 대응하는 ViewModel 인스턴스를 확인합니다.

매개변수
viewTypeView 타입입니다.
반환값
확인된 ViewModel 인스턴스이며, 타입을 찾지 못하면 null입니다.
예외
ArgumentNullExceptionviewTypenull인 경우 발생합니다.
InvalidOperationException확인자가 없거나 일치하는 인스턴스를 만들지 못한 경우 발생합니다.

ViewModelLocator.cs 파일의 257 번째 라인에서 정의되었습니다.

258 {
259 ArgumentNullException.ThrowIfNull(viewType);
260
261 Type? mappedType;
262 lock (_syncRoot)
263 {
264 _map.TryGetValue(viewType, out mappedType);
265 }
266
267 if (mappedType is not null)
268 {
269 return CreateInstance(mappedType);
270 }
271
272 Type? resolvedType = FindViewModelType(viewType);
273 if (resolvedType is null)
274 {
275 return null;
276 }
277
278 Register(viewType, resolvedType);
279 return CreateInstance(resolvedType);
280 }

다음을 참조함 : _map, _syncRoot, CreateInstance(), FindViewModelType(), Register().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ ResolveView()

? object Dreamine.MVVM.Locators.ViewModelLocator.ResolveView ( Type viewModelType)
inlinestatic

ViewModel 타입에 대응하는 View 인스턴스를 생성합니다.

매개변수
viewModelTypeViewModel 타입입니다.
반환값
생성된 View 인스턴스이며, 타입을 찾지 못하면 null입니다.
예외
ArgumentNullExceptionviewModelTypenull인 경우 발생합니다.

ViewModelLocator.cs 파일의 314 번째 라인에서 정의되었습니다.

315 {
316 ArgumentNullException.ThrowIfNull(viewModelType);
317
318 Type? viewType = FindViewType(viewModelType);
319 return viewType != null
320 ? Activator.CreateInstance(viewType)
321 : null;
322 }

다음을 참조함 : FindViewType().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ _allLoadableTypesCache

? Type [] Dreamine.MVVM.Locators.ViewModelLocator._allLoadableTypesCache
staticprivate

all Loadable Types Cache 값을 보관합니다.

ViewModelLocator.cs 파일의 69 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Clear(), ClearTypeCache(), GetAllLoadableTypes(), Reset().

◆ _map

readonly Dictionary<Type, Type> Dreamine.MVVM.Locators.ViewModelLocator._map = new(32)
staticprivate

map 값을 보관합니다.

ViewModelLocator.cs 파일의 33 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Clear(), Register(), RegisterAll(), Reset(), Resolve().

◆ _resolver

? IViewModelResolver Dreamine.MVVM.Locators.ViewModelLocator._resolver
staticprivate

resolver 값을 보관합니다.

ViewModelLocator.cs 파일의 60 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ClearResolver(), CreateInstance(), RegisterResolver(), Reset().

◆ _syncRoot

readonly object Dreamine.MVVM.Locators.ViewModelLocator._syncRoot = new()
staticprivate

sync Root 값을 보관합니다.

ViewModelLocator.cs 파일의 24 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Clear(), ClearResolver(), ClearTypeCache(), CreateInstance(), FindViewModelType(), FindViewType(), GetAllLoadableTypes(), Register(), RegisterAll(), RegisterResolver(), Reset(), Resolve().

◆ _viewModelTypeCache

readonly Dictionary<Type, Type?> Dreamine.MVVM.Locators.ViewModelLocator._viewModelTypeCache = new(32)
staticprivate

view Model Type Cache 값을 보관합니다.

ViewModelLocator.cs 파일의 42 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Clear(), ClearTypeCache(), FindViewModelType(), Register(), Reset().

◆ _viewTypeCache

readonly Dictionary<Type, Type?> Dreamine.MVVM.Locators.ViewModelLocator._viewTypeCache = new(32)
staticprivate

view Type Cache 값을 보관합니다.

ViewModelLocator.cs 파일의 51 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : Clear(), ClearTypeCache(), FindViewType(), Reset().


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: