本文整理汇总了C#中IErrorReporter.LogError方法的典型用法代码示例。如果您正苦于以下问题:C# IErrorReporter.LogError方法的具体用法?C# IErrorReporter.LogError怎么用?C# IErrorReporter.LogError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IErrorReporter
的用法示例。
在下文中一共展示了IErrorReporter.LogError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompilerLoader
public CompilerLoader(
IEnumerable<InjectBindingGenerator> bindings,
IEnumerable<LazyBindingGenerator> lazyBindings,
IEnumerable<ProviderBindingGenerator> providerBindings,
IErrorReporter errorReporter)
{
var comparer = StringComparer.Ordinal;
this.bindings = new Dictionary<string, Binding>(comparer);
foreach (var gen in bindings)
{
try
{
this.bindings.Add(gen.Key, new CompilerBinding(gen));
}
catch (ArgumentException)
{
const string format = "The inject binding {0} is erroneously duplicated - please report this, with a repro if possible!";
errorReporter.LogError(string.Format(format, gen.Key));
HasError = true;
}
}
this.lazyBindings = new Dictionary<string, CompilerParameterizedBinding>(comparer);
foreach (var gen in lazyBindings)
{
try
{
this.lazyBindings.Add(gen.Key, new CompilerParameterizedBinding(gen));
}
catch (ArgumentException)
{
var message = string.Format("The lazy binding {0} is erroneously duplicated - please report this, with a repro if possible!", gen.Key);
errorReporter.LogError(message);
HasError = true;
}
}
this.providerBindings = new Dictionary<string, CompilerParameterizedBinding>(comparer);
foreach (var gen in providerBindings)
{
try
{
this.providerBindings.Add(gen.Key, new CompilerParameterizedBinding(gen));
}
catch (ArgumentException)
{
var message = string.Format("The IProvider binding {0} is erroneously duplicated - please report this, with a repro if possible!", gen.Key);
errorReporter.LogError(message);
HasError = true;
}
}
}
示例2: Validate
public override void Validate(IErrorReporter errorReporter)
{
if (injectedType.HasGenericParameters) {
errorReporter.LogError("Open generic types may not be injected: " + injectedType.FullName);
return;
}
switch (injectedType.Attributes & TypeAttributes.VisibilityMask) {
case TypeAttributes.NestedFamily:
case TypeAttributes.NestedFamANDAssem:
case TypeAttributes.NestedPrivate:
case TypeAttributes.NotPublic:
// This type is not externally visible and can't be included in a compiled plugin.
// It can still be loaded reflectively.
IsVisibleToPlugin = false;
errorReporter.LogWarning(injectedType.FullName + ": This type is private, and will be loaded reflectively. Consider making it internal or public.");
break;
}
Key = CompilerKeys.ForType(injectedType);
MembersKey = CompilerKeys.GetMemberKey(injectedType);
IsSingleton = injectedType.CustomAttributes.Any(Attributes.IsSingletonAttribute);
var injectableCtors = injectedType
.GetConstructors()
.Where(ctor => ctor.CustomAttributes.Any(Attributes.IsInjectAttribute))
.ToList();
foreach (var ctor in injectableCtors) {
if (InjectableCtor != null) {
errorReporter.LogError(string.Format("{0} has more than one injectable constructor.", injectedType.FullName));
}
if (!ctor.Attributes.IsVisible()) {
errorReporter.LogError("{0} has an injectable constructor, but it is not accessible. Consider making it public.");
}
InjectableCtor = ctor;
}
InjectableProperties = injectedType
.Properties
.Where(p => p.DeclaringType == injectedType)
.Where(p => p.CustomAttributes.Any(Attributes.IsInjectAttribute))
.Select(p => new PropertyInfo(p))
.ToList();
foreach (var p in InjectableProperties) {
if (p.Setter == null) {
errorReporter.LogError(string.Format("{0} is marked [Inject] but has no setter.", p.MemberName));
continue;
}
if (!p.Setter.Attributes.IsVisible()) {
const string msg = "{0}.{1} is marked [Inject], but has no visible setter. Consider adding a public setter.";
errorReporter.LogError(string.Format(msg, injectedType.FullName, p.PropertyName));
}
}
if (InjectableCtor == null) {
if (InjectableProperties.Count == 0 && !IsEntryPoint) {
errorReporter.LogError("No injectable constructors or properties found on " + injectedType.FullName);
}
var defaultCtor = injectedType.GetConstructors().FirstOrDefault(ctor => !ctor.HasParameters);
if (defaultCtor == null) {
errorReporter.LogError("Type " + injectedType.FullName + " has no [Inject] constructors and no default constructor.");
return;
}
InjectableCtor = defaultCtor;
}
CtorParams = InjectableCtor.Parameters.Select(p => new InjectMemberInfo(p)).ToList();
var baseType = injectedType.BaseType;
var baseTypeAsmName = baseType.Maybe(type => type.Scope)
.Maybe(scope => scope.Name);
if (baseType == null
|| baseTypeAsmName == null
|| baseTypeAsmName.StartsWith("mscorlib")
|| baseTypeAsmName.StartsWith("System")
|| baseTypeAsmName.StartsWith("Microsoft")
|| baseTypeAsmName.StartsWith("Mono")) {
// We can safely skip types known not to have [Inject] bindings, i.e. types
// from the BCL, etc.
BaseTypeKey = null;
} else {
// Otherwise, base types might have [Inject] properties that we'll need
// to account for.
BaseTypeKey = Weaver.EnqueueBaseTypeBinding(baseType)
? CompilerKeys.ForType(baseType)
: null;
}
}
示例3: Validate
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);
}
}
示例4: Validate
public override void Validate(IErrorReporter errorReporter)
{
if (injectedType.HasGenericParameters)
{
if (genericInstanceType == null ||
genericInstanceType.GenericArguments.Count != injectedType.GenericParameters.Count)
{
errorReporter.LogError("Open generic types may not be injected: " + injectedType.FullName);
return;
}
}
if (!injectedType.IsVisible())
{
// This type is not externally visible and can't be included in a compiled loader.
// It can still be loaded reflectively.
IsVisibleToLoader = false;
errorReporter.LogWarning(injectedType.FullName + ": This type is private, and will be loaded reflectively. Consider making it internal or public.");
}
Key = CompilerKeys.ForType(injectedType);
MembersKey = CompilerKeys.GetMemberKey(injectedType);
IsSingleton = injectedType.CustomAttributes.Any(Attributes.IsSingletonAttribute);
var injectableCtors = injectedType
.GetConstructors()
.Where(ctor => ctor.CustomAttributes.Any(Attributes.IsInjectAttribute))
.ToList();
foreach (var ctor in injectableCtors)
{
if (InjectableCtor != null)
{
errorReporter.LogError(string.Format("{0} has more than one injectable constructor.", injectedType.FullName));
}
if (!ctor.IsVisible())
{
errorReporter.LogError(string.Format("{0} has an injectable constructor, but it is not accessible. Consider making it public.", injectedType.FullName));
}
InjectableCtor = ctor;
}
InjectableProperties = injectedType
.Properties
.Where(p => p.DeclaringType == injectedType)
.Where(p => p.CustomAttributes.Any(Attributes.IsInjectAttribute))
.Select(p => new PropertyInfo(p))
.ToList();
foreach (var p in InjectableProperties)
{
if (p.Setter == null)
{
errorReporter.LogError(string.Format("{0} is marked [Inject] but has no setter.", p.MemberName));
continue;
}
if (!p.Setter.IsVisible())
{
const string msg = "{0}.{1} is marked [Inject], but has no visible setter. Consider adding a public setter.";
errorReporter.LogError(string.Format(msg, injectedType.FullName, p.PropertyName));
}
}
if (InjectableCtor == null)
{
if (InjectableProperties.Count == 0 && !IsModuleInjectable)
{
errorReporter.LogError("No injectable constructors or properties found on " + injectedType.FullName);
}
// XXX ben: this is wrong, I think - entry points with no ctor will still fail.
var defaultCtor = injectedType.GetConstructors().FirstOrDefault(ctor => !ctor.HasParameters && ctor.IsVisible());
if (defaultCtor == null && !IsModuleInjectable)
{
errorReporter.LogError("Type " + injectedType.FullName + " has no [Inject] constructors and no default constructor.");
return;
}
InjectableCtor = defaultCtor;
}
// InjectableCtor is null iff this is a value-type entry-point with no default ctor.
// It's OK, such types never get constructed, only "provided".
CtorParams = InjectableCtor == null
? new List<InjectMemberInfo>()
: InjectableCtor.Parameters.Select(p => new InjectMemberInfo(p)).ToList();
var baseType = injectedType.BaseType;
var baseTypeAsmName = baseType.Maybe(type => type.Scope)
.Maybe(scope => scope.Name);
if (baseType == null
|| baseTypeAsmName == null
|| baseTypeAsmName.StartsWith("mscorlib")
|| baseTypeAsmName.StartsWith("System")
|| baseTypeAsmName.StartsWith("Microsoft")
|| baseTypeAsmName.StartsWith("Mono"))
{
//.........这里部分代码省略.........