public override TypeDefinition Generate(IErrorReporter errorReporter) { Conditions.CheckNotNull(RuntimeModuleType, "RuntimeModuleType"); var providerType = new TypeDefinition( RuntimeModuleType.Namespace, "ProviderBinding_" + RuntimeModuleType.NestedTypes.Count, TypeAttributes.NestedPublic, References.Binding); providerType.CustomAttributes.Add(new CustomAttribute(References.CompilerGeneratedAttribute)); providerType.DeclaringType = RuntimeModuleType; IsSingleton = ProviderMethod.CustomAttributes.Any(Attributes.IsSingletonAttribute); var moduleField = new FieldDefinition("module", FieldAttributes.Private, ModuleType); providerType.Fields.Add(moduleField); var parameters = new List <ParameterDefinition>(); var fields = new List <FieldDefinition>(); foreach (var param in ProviderMethod.Parameters) { var field = new FieldDefinition(param.Name, FieldAttributes.Private, References.Binding); providerType.Fields.Add(field); parameters.Add(param); fields.Add(field); ParamKeys.Add(CompilerKeys.ForParam(param)); } EmitCtor(providerType, moduleField); EmitResolve(providerType, parameters, fields); EmitGetDependencies(providerType, fields); EmitGet(providerType, moduleField, parameters, fields); RuntimeModuleType.NestedTypes.Add(providerType); return(providerType); }
public override void Validate(IErrorReporter errorReporter) { ParamKeys = new List <string>(); foreach (var param in ProviderMethod.Parameters) { ParamKeys.Add(CompilerKeys.ForParam(param)); } if (ProviderMethod.HasGenericParameters) { errorReporter.LogError("Provider methods cannot be generic: " + ProviderMethod.FullName); } if (ProviderMethod.IsStatic) { errorReporter.LogError("Provider methods cannot be static: " + ProviderMethod.FullName); } if (ProviderMethod.MethodReturnType.ReturnType.Name == "Lazy`1") { errorReporter.LogError("Provider methods cannot return System.Lazy<T> directly: " + ProviderMethod.FullName); } if (ProviderMethod.ReturnType.Name == "IProvider`1") { errorReporter.LogError("Provider methods cannot return IProvider<T> directly: " + ProviderMethod.FullName); } if (ProviderMethod.IsPrivate) { errorReporter.LogError("Provider methods cannot be private: " + ProviderMethod.FullName); } if (ProviderMethod.IsAbstract) { errorReporter.LogError("Provider methods cannot be abstract: " + ProviderMethod.FullName); } }
public void ValidateCompleteness(ISet <string> injectableKeys, IErrorReporter errorReporter) { if (!IsComplete) { return; } foreach (var method in baseProvidesMethods) { foreach (var param in method.Parameters) { var name = param.Name; var key = CompilerKeys.ForParam(param); if (!injectableKeys.Contains(key)) { const string msg = "{0}: Module is a complete module but has an unsatisfied dependency on {1}{2}"; var nameDescr = name == null ? string.Empty : "[Named(\"" + name + "\")] "; errorReporter.LogError(string.Format(msg, moduleType.FullName, nameDescr, param.ParameterType.FullName)); } } } }
public InjectMemberInfo(ParameterDefinition param) : this(CompilerKeys.ForParam(param), param.ParameterType) { memberName = param.Name; }