public RegistryKey InitializeRegistryKey(WindowsRegistryAccess windowsRegistryAccess) { _rootKey = windowsRegistryAccess.RootKey; _registryKeyInitializer = _implementationFactory.Create <IRegistryKeyInitializer, RegistryAccessAttribute>(IdentifierFunc); return(_registryKeyInitializer.InitializeRegistryKey(windowsRegistryAccess)); }
private void ResolveInvocation(IInvocation invocation, GlassFactoryTypeAttribute glassFactoryTypeAttribute) { var glassType = glassFactoryTypeAttribute.Type; var sitecoreAttribute = glassType.GetCustomAttribute <SitecoreTypeAttribute>(); // If this is a final fallback type that is not associated with a direct Sitecore template if (sitecoreAttribute == null) { return; } var templateId = new Guid(sitecoreAttribute.TemplateId); var matchingType = _templateCache.GetFallbackImplementingTypeForTemplate(templateId, _interfaceType); // This can happen if we fail to find an eligible base template with a corresponding implementation // In this case, don't do anything -> invocation maps to default value if (matchingType == null) { return; } var fallbackImpl = _implementationFactory.Create(matchingType, _interfaceType, _model); var invocationTarget = invocation.MethodInvocationTarget; var targetMethod = invocationTarget.IsGenericMethod ? invocationTarget.GetGenericMethodDefinition() : invocationTarget; var fallbackMethod = GetFallbackInterfaceMethod(invocation, _interfaceType, invocationTarget, targetMethod); if (fallbackMethod != null) { invocation.ReturnValue = fallbackMethod.Invoke(fallbackImpl, invocation.Arguments); } }
public T GetItem <T>(IGlassBase model) where T : class { var implType = GetItemFromInterface(model, typeof(T)); return(implType != null ? _factory.Create <T, IGlassBase>(implType, model) : default(T)); }
public object Create(Type t, Type asType, object glassModel) { var typeAttribute = t.GetCustomAttribute <GlassFactoryTypeAttribute>(); var exactGenericGlassType = typeAttribute.Type; // Assert that we are able to construct the Glass Factory type with the given Glass model if (!exactGenericGlassType.IsInstanceOfType(glassModel)) { if (!IsDebuggingEnabled) { return(null); } // Otherwise, throw an exception throw new ImplementationMismatchException(exactGenericGlassType, glassModel); } return(_innerFactory.Create(t, asType, glassModel)); }