本文整理汇总了C#中Mono.CSharp.Report.Warning方法的典型用法代码示例。如果您正苦于以下问题:C# Report.Warning方法的具体用法?C# Report.Warning怎么用?C# Report.Warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.Report
的用法示例。
在下文中一共展示了Report.Warning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyClsParameterConflict
/// <summary>
/// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
/// </summary>
///
// TODO: refactor as method is always 'this'
public static void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder, Report Report)
{
EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
for (int i = 0; i < al.Count; ++i) {
MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
// skip itself
if (entry.Member == this_builder)
continue;
if ((entry.EntryType & tested_type) != tested_type)
continue;
MethodBase method_to_compare = (MethodBase)entry.Member;
AttributeTester.Result result = AttributeTester.AreOverloadedMethodParamsClsCompliant (
method.Parameters, TypeManager.GetParameterData (method_to_compare));
if (result == AttributeTester.Result.Ok)
continue;
IMethodData md = TypeManager.GetMethod (method_to_compare);
// TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
// However it is exactly what csc does.
if (md != null && !md.IsClsComplianceRequired ())
continue;
Report.SymbolRelatedToPreviousError (entry.Member);
switch (result) {
case AttributeTester.Result.RefOutArrayError:
Report.Warning (3006, 1, method.Location,
"Overloaded method `{0}' differing only in ref or out, or in array rank, is not CLS-compliant",
method.GetSignatureForError ());
continue;
case AttributeTester.Result.ArrayArrayError:
Report.Warning (3007, 1, method.Location,
"Overloaded method `{0}' differing only by unnamed array types is not CLS-compliant",
method.GetSignatureForError ());
continue;
}
throw new NotImplementedException (result.ToString ());
}
}
示例2: Normalize
private static void Normalize(MemberCore mc, ref string name, Report Report)
{
if (name.Length > 0 && name [0] == '@')
name = name.Substring (1);
else if (name == "this")
name = "Item";
else if (Tokenizer.IsKeyword (name) && !IsTypeName (name))
Report.Warning (1041, 1, mc.Location, "Identifier expected. `{0}' is a keyword", name);
}
示例3: Report419
static void Report419(MemberCore mc, string member_name, MemberSpec [] mis, Report Report)
{
Report.Warning (419, 3, mc.Location,
"Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched",
member_name,
TypeManager.GetFullNameSignature (mis [0]),
TypeManager.GetFullNameSignature (mis [1]));
}
示例4: HandleInclude
//
// Processes "include" element. Check included file and
// embed the document content inside this documentation node.
//
private static bool HandleInclude(MemberCore mc, XmlElement el, Report Report)
{
bool keep_include_node = false;
string file = el.GetAttribute ("file");
string path = el.GetAttribute ("path");
if (file == "") {
Report.Warning (1590, 1, mc.Location, "Invalid XML `include' element. Missing `file' attribute");
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (" Include tag is invalid "), el);
keep_include_node = true;
}
else if (path.Length == 0) {
Report.Warning (1590, 1, mc.Location, "Invalid XML `include' element. Missing `path' attribute");
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (" Include tag is invalid "), el);
keep_include_node = true;
}
else {
XmlDocument doc;
if (!RootContext.Documentation.StoredDocuments.TryGetValue (file, out doc)) {
try {
doc = new XmlDocument ();
doc.Load (file);
RootContext.Documentation.StoredDocuments.Add (file, doc);
} catch (Exception) {
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (String.Format (" Badly formed XML in at comment file `{0}': cannot be included ", file)), el);
Report.Warning (1592, 1, mc.Location, "Badly formed XML in included comments file -- `{0}'", file);
}
}
if (doc != null) {
try {
XmlNodeList nl = doc.SelectNodes (path);
if (nl.Count == 0) {
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (" No matching elements were found for the include tag embedded here. "), el);
keep_include_node = true;
}
foreach (XmlNode n in nl)
el.ParentNode.InsertBefore (el.OwnerDocument.ImportNode (n, true), el);
} catch (Exception ex) {
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (" Failed to insert some or all of included XML "), el);
Report.Warning (1589, 1, mc.Location, "Unable to include XML fragment `{0}' of file `{1}' ({2})", path, file, ex.Message);
}
}
}
return keep_include_node;
}
示例5: HandleXrefCommon
//
// Processes "see" or "seealso" elements.
// Checks cref attribute.
//
private static void HandleXrefCommon(MemberCore mc,
DeclSpace ds, XmlElement xref, Report Report)
{
string cref = xref.GetAttribute ("cref").Trim (wsChars);
// when, XmlReader, "if (cref == null)"
if (!xref.HasAttribute ("cref"))
return;
if (cref.Length == 0)
Report.Warning (1001, 1, mc.Location, "Identifier expected");
// ... and continue until CS1584.
string signature; // "x:" are stripped
string name; // method invokation "(...)" are removed
string parameters; // method parameter list
// When it found '?:' ('T:' 'M:' 'F:' 'P:' 'E:' etc.),
// MS ignores not only its member kind, but also
// the entire syntax correctness. Nor it also does
// type fullname resolution i.e. "T:List(int)" is kept
// as T:List(int), not
// T:System.Collections.Generic.List<System.Int32>
if (cref.Length > 2 && cref [1] == ':')
return;
else
signature = cref;
// Also note that without "T:" any generic type
// indication fails.
int parens_pos = signature.IndexOf ('(');
int brace_pos = parens_pos >= 0 ? -1 :
signature.IndexOf ('[');
if (parens_pos > 0 && signature [signature.Length - 1] == ')') {
name = signature.Substring (0, parens_pos).Trim (wsChars);
parameters = signature.Substring (parens_pos + 1, signature.Length - parens_pos - 2).Trim (wsChars);
}
else if (brace_pos > 0 && signature [signature.Length - 1] == ']') {
name = signature.Substring (0, brace_pos).Trim (wsChars);
parameters = signature.Substring (brace_pos + 1, signature.Length - brace_pos - 2).Trim (wsChars);
}
else {
name = signature;
parameters = null;
}
Normalize (mc, ref name, Report);
string identifier = GetBodyIdentifierFromName (name);
// Check if identifier is valid.
// This check is not necessary to mark as error, but
// csc specially reports CS1584 for wrong identifiers.
string [] name_elems = identifier.Split ('.');
for (int i = 0; i < name_elems.Length; i++) {
string nameElem = GetBodyIdentifierFromName (name_elems [i]);
if (i > 0)
Normalize (mc, ref nameElem, Report);
if (!Tokenizer.IsValidIdentifier (nameElem)
&& nameElem.IndexOf ("operator") < 0) {
Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
mc.GetSignatureForError (), cref);
xref.SetAttribute ("cref", "!:" + signature);
return;
}
}
// check if parameters are valid
AParametersCollection parameter_types;
if (parameters == null)
parameter_types = null;
else if (parameters.Length == 0)
parameter_types = ParametersCompiled.EmptyReadOnlyParameters;
else {
string [] param_list = parameters.Split (',');
var plist = new List<TypeSpec> ();
for (int i = 0; i < param_list.Length; i++) {
string param_type_name = param_list [i].Trim (wsChars);
Normalize (mc, ref param_type_name, Report);
TypeSpec param_type = FindDocumentedType (mc, param_type_name, ds, cref, Report);
if (param_type == null) {
Report.Warning (1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'",
(i + 1).ToString (), cref);
return;
}
plist.Add (param_type);
}
parameter_types = ParametersCompiled.CreateFullyResolved (plist.ToArray ());
}
TypeSpec type = FindDocumentedType (mc, name, ds, cref, Report);
if (type != null
// delegate must not be referenced with args
&& (!type.IsDelegate
|| parameter_types == null)) {
string result = GetSignatureForDoc (type)
+ (brace_pos < 0 ? String.Empty : signature.Substring (brace_pos));
//.........这里部分代码省略.........
示例6: OnMethodGenerateDocComment
//
// Raised (and passed an XmlElement that contains the comment)
// when GenerateDocComment is writing documentation expectedly.
//
// FIXME: with a few effort, it could be done with XmlReader,
// that means removal of DOM use.
//
internal static void OnMethodGenerateDocComment(
MethodCore mc, XmlElement el, Report Report)
{
var paramTags = new Dictionary<string, string> ();
foreach (XmlElement pelem in el.SelectNodes ("param")) {
string xname = pelem.GetAttribute ("name");
if (xname.Length == 0)
continue; // really? but MS looks doing so
if (xname != "" && mc.ParameterInfo.GetParameterIndexByName (xname) < 0)
Report.Warning (1572, 2, mc.Location, "XML comment on `{0}' has a param tag for `{1}', but there is no parameter by that name",
mc.GetSignatureForError (), xname);
else if (paramTags.ContainsKey (xname))
Report.Warning (1571, 2, mc.Location, "XML comment on `{0}' has a duplicate param tag for `{1}'",
mc.GetSignatureForError (), xname);
paramTags [xname] = xname;
}
IParameterData [] plist = mc.ParameterInfo.FixedParameters;
foreach (Parameter p in plist) {
if (paramTags.Count > 0 && !paramTags.ContainsKey (p.Name))
Report.Warning (1573, 4, mc.Location, "Parameter `{0}' has no matching param tag in the XML comment for `{1}'",
p.Name, mc.GetSignatureForError ());
}
}
示例7: VerifyClsCompliance
public void VerifyClsCompliance (Report report)
{
foreach (var c in constraints)
{
if (c == null)
continue;
if (!c.Type.IsCLSCompliant ()) {
report.SymbolRelatedToPreviousError (c.Type);
report.Warning (3024, 1, loc, "Constraint type `{0}' is not CLS-compliant",
c.Type.GetSignatureForError ());
}
}
}
示例8: Report_ObsoleteMessage
/// <summary>
/// Common method for Obsolete error/warning reporting.
/// </summary>
public static void Report_ObsoleteMessage (ObsoleteAttribute oa, string member, Location loc, Report Report)
{
if (oa.IsError) {
Report.Error (619, loc, "`{0}' is obsolete: `{1}'", member, oa.Message);
return;
}
if (oa.Message == null || oa.Message.Length == 0) {
Report.Warning (612, 1, loc, "`{0}' is obsolete", member);
return;
}
Report.Warning (618, 2, loc, "`{0}' is obsolete: `{1}'", member, oa.Message);
}
示例9: GenerateDocComment
//
// Generates xml doc comments (if any), and if required,
// handle warning report.
//
internal static void GenerateDocComment(MemberCore mc,
DeclSpace ds, Report Report)
{
if (mc.DocComment != null) {
string name = mc.GetDocCommentName (ds);
XmlNode n = GetDocCommentNode (mc, name, Report);
XmlElement el = n as XmlElement;
if (el != null) {
mc.OnGenerateDocComment (el);
// FIXME: it could be done with XmlReader
XmlNodeList nl = n.SelectNodes (".//include");
if (nl.Count > 0) {
// It could result in current node removal, so prepare another list to iterate.
var al = new List<XmlNode> (nl.Count);
foreach (XmlNode inc in nl)
al.Add (inc);
foreach (XmlElement inc in al)
if (!HandleInclude (mc, inc, Report))
inc.ParentNode.RemoveChild (inc);
}
// FIXME: it could be done with XmlReader
DeclSpace ds_target = mc as DeclSpace;
if (ds_target == null)
ds_target = ds;
foreach (XmlElement see in n.SelectNodes (".//see"))
HandleSee (mc, ds_target, see, Report);
foreach (XmlElement seealso in n.SelectNodes (".//seealso"))
HandleSeeAlso (mc, ds_target, seealso ,Report);
foreach (XmlElement see in n.SelectNodes (".//exception"))
HandleException (mc, ds_target, see, Report);
}
n.WriteTo (RootContext.Documentation.XmlCommentOutput);
}
else if (mc.IsExposedFromAssembly ()) {
Constructor c = mc as Constructor;
if (c == null || !c.IsDefault ())
Report.Warning (1591, 4, mc.Location,
"Missing XML comment for publicly visible type or member `{0}'", mc.GetSignatureForError ());
}
}
示例10: Define
public bool Define (DeclSpace parent, string method_full_name, Report Report)
{
TypeContainer container = parent.PartialContainer;
PendingImplementation pending = container.PendingImplementations;
MethodSpec ambig_iface_method;
if (pending != null) {
implementing = pending.IsInterfaceMethod (method.MethodName, member.InterfaceType, this, out ambig_iface_method);
if (member.InterfaceType != null) {
if (implementing == null) {
if (member is PropertyBase) {
Report.Error (550, method.Location, "`{0}' is an accessor not found in interface member `{1}{2}'",
method.GetSignatureForError (), TypeManager.CSharpName (member.InterfaceType),
member.GetSignatureForError ().Substring (member.GetSignatureForError ().LastIndexOf ('.')));
} else {
Report.Error (539, method.Location,
"`{0}.{1}' in explicit interface declaration is not a member of interface",
TypeManager.CSharpName (member.InterfaceType), member.ShortName);
}
return false;
}
if (implementing.IsAccessor && !method.IsAccessor) {
Report.SymbolRelatedToPreviousError (implementing);
Report.Error (683, method.Location, "`{0}' explicit method implementation cannot implement `{1}' because it is an accessor",
member.GetSignatureForError (), TypeManager.CSharpSignature (implementing));
return false;
}
} else {
if (implementing != null) {
if (!method.IsAccessor) {
if (implementing.IsAccessor) {
Report.SymbolRelatedToPreviousError (implementing);
Report.Error (470, method.Location, "Method `{0}' cannot implement interface accessor `{1}'",
method.GetSignatureForError (), TypeManager.CSharpSignature (implementing));
}
} else if (implementing.DeclaringType.IsInterface) {
if (!implementing.IsAccessor) {
Report.SymbolRelatedToPreviousError (implementing);
Report.Error (686, method.Location, "Accessor `{0}' cannot implement interface member `{1}' for type `{2}'. Use an explicit interface implementation",
method.GetSignatureForError (), TypeManager.CSharpSignature (implementing), container.GetSignatureForError ());
} else {
PropertyBase.PropertyMethod pm = method as PropertyBase.PropertyMethod;
if (pm != null && pm.HasCustomAccessModifier && (pm.ModFlags & Modifiers.PUBLIC) == 0) {
Report.SymbolRelatedToPreviousError (implementing);
Report.Error (277, method.Location, "Accessor `{0}' must be declared public to implement interface member `{1}'",
method.GetSignatureForError (), implementing.GetSignatureForError ());
}
}
}
}
}
} else {
ambig_iface_method = null;
}
//
// For implicit implementations, make sure we are public, for
// explicit implementations, make sure we are private.
//
if (implementing != null){
//
// Setting null inside this block will trigger a more
// verbose error reporting for missing interface implementations
//
// The "candidate" function has been flagged already
// but it wont get cleared
//
if (member.IsExplicitImpl){
if (method.ParameterInfo.HasParams && !implementing.Parameters.HasParams) {
Report.SymbolRelatedToPreviousError (implementing);
Report.Error (466, method.Location, "`{0}': the explicit interface implementation cannot introduce the params modifier",
method.GetSignatureForError ());
}
if (ambig_iface_method != null) {
Report.SymbolRelatedToPreviousError (ambig_iface_method);
Report.SymbolRelatedToPreviousError (implementing);
Report.Warning (473, 2, method.Location,
"Explicit interface implementation `{0}' matches more than one interface member. Consider using a non-explicit implementation instead",
method.GetSignatureForError ());
}
} else {
if (implementing.DeclaringType.IsInterface) {
//
// If this is an interface method implementation,
// check for public accessibility
//
if ((flags & MethodAttributes.MemberAccessMask) != MethodAttributes.Public)
{
implementing = null;
}
} else if ((flags & MethodAttributes.MemberAccessMask) == MethodAttributes.Private){
// We may never be private.
implementing = null;
} else if ((modifiers & Modifiers.OVERRIDE) == 0){
//
//.........这里部分代码省略.........
示例11: AddFile
// <summary>
// This must be called before parsing/tokenizing any files.
// </summary>
static public void AddFile (Report r, string name)
{
string path = Path.GetFullPath (name);
int id;
if (source_files.TryGetValue (path, out id)){
string other_name = source_list [id - 1].Name;
if (name.Equals (other_name))
r.Warning (2002, 1, "Source file `{0}' specified multiple times", other_name);
else
r.Warning (2002, 1, "Source filenames `{0}' and `{1}' both refer to the same file: {2}", name, other_name, path);
return;
}
source_files.Add (path, ++source_count);
CompilationUnit unit = new CompilationUnit (name, path, source_count);
source_list.Add (unit);
compile_units.Add (unit);
}
示例12: FindDocumentedMemberNoNest
private static MemberInfo FindDocumentedMemberNoNest (
MemberCore mc, Type type, string member_name,
Type [] param_list, DeclSpace ds, out int warning_type,
string cref, bool warn419, string name_for_error, Report Report)
{
warning_type = 0;
MemberInfo [] mis;
if (param_list == null) {
// search for fields/events etc.
mis = TypeManager.MemberLookup (type, null,
type, MemberTypes.All,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance,
member_name, null);
mis = FilterOverridenMembersOut (mis);
if (mis == null || mis.Length == 0)
return null;
if (warn419 && IsAmbiguous (mis))
Report419 (mc, name_for_error, mis, Report);
return mis [0];
}
MethodSignature msig = new MethodSignature (member_name, null, param_list);
mis = FindMethodBase (type,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance,
msig);
if (warn419 && mis.Length > 0) {
if (IsAmbiguous (mis))
Report419 (mc, name_for_error, mis, Report);
return mis [0];
}
// search for operators (whose parameters exactly
// matches with the list) and possibly report CS1581.
string oper = null;
string return_type_name = null;
if (member_name.StartsWith ("implicit operator ")) {
Operator.GetMetadataName (Operator.OpType.Implicit);
return_type_name = member_name.Substring (18).Trim (wsChars);
}
else if (member_name.StartsWith ("explicit operator ")) {
oper = Operator.GetMetadataName (Operator.OpType.Explicit);
return_type_name = member_name.Substring (18).Trim (wsChars);
}
else if (member_name.StartsWith ("operator ")) {
oper = member_name.Substring (9).Trim (wsChars);
switch (oper) {
// either unary or binary
case "+":
oper = param_list.Length == 2 ?
Operator.GetMetadataName (Operator.OpType.Addition) :
Operator.GetMetadataName (Operator.OpType.UnaryPlus);
break;
case "-":
oper = param_list.Length == 2 ?
Operator.GetMetadataName (Operator.OpType.Subtraction) :
Operator.GetMetadataName (Operator.OpType.UnaryNegation);
break;
default:
oper = Operator.GetMetadataName (oper);
if (oper != null)
break;
warning_type = 1584;
Report.Warning (1020, 1, mc.Location, "Overloadable {0} operator is expected", param_list.Length == 2 ? "binary" : "unary");
Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
mc.GetSignatureForError (), cref);
return null;
}
}
// here we still don't consider return type (to
// detect CS1581 or CS1002+CS1584).
msig = new MethodSignature (oper, null, param_list);
mis = FindMethodBase (type,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance,
msig);
if (mis.Length == 0)
return null; // CS1574
MemberInfo mi = mis [0];
Type expected = mi is MethodInfo ?
((MethodInfo) mi).ReturnType :
mi is PropertyInfo ?
((PropertyInfo) mi).PropertyType :
null;
if (return_type_name != null) {
Type returnType = FindDocumentedType (mc, return_type_name, ds, cref, Report);
if (returnType == null || returnType != expected) {
warning_type = 1581;
Report.Warning (1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref);
return null;
}
}
return mis [0];
}
示例13: WarningEnable
public void WarningEnable (Location location, int code, Report Report)
{
if (!Report.CheckWarningCode (code, location))
return;
if (Report.IsWarningDisabledGlobally (code))
Report.Warning (1635, 1, location, "Cannot restore warning `CS{0:0000}' because it was disabled globally", code);
regions.Add (new Enable (location.Row, code));
}
示例14: GetDocCommentNode
private static XmlNode GetDocCommentNode(MemberCore mc,
string name, Report Report)
{
// FIXME: It could be even optimizable as not
// to use XmlDocument. But anyways the nodes
// are not kept in memory.
XmlDocument doc = RootContext.Documentation.XmlDocumentation;
try {
XmlElement el = doc.CreateElement ("member");
el.SetAttribute ("name", name);
string normalized = mc.DocComment;
el.InnerXml = normalized;
// csc keeps lines as written in the sources
// and inserts formatting indentation (which
// is different from XmlTextWriter.Formatting
// one), but when a start tag contains an
// endline, it joins the next line. We don't
// have to follow such a hacky behavior.
string [] split =
normalized.Split ('\n');
int j = 0;
for (int i = 0; i < split.Length; i++) {
string s = split [i].TrimEnd ();
if (s.Length > 0)
split [j++] = s;
}
el.InnerXml = line_head + String.Join (
line_head, split, 0, j);
return el;
} catch (Exception ex) {
Report.Warning (1570, 1, mc.Location, "XML comment on `{0}' has non-well-formed XML ({1})", name, ex.Message);
XmlComment com = doc.CreateComment (String.Format ("FIXME: Invalid documentation markup was found for member {0}", name));
return com;
}
}
示例15: Warning_UselessOptionalParameter
public void Warning_UselessOptionalParameter (Report Report)
{
Report.Warning (1066, 1, Location,
"The default value specified for optional parameter `{0}' will never be used",
Name);
}