当前位置: 首页>>代码示例>>C#>>正文


C# IMessageSink.Write方法代码示例

本文整理汇总了C#中IMessageSink.Write方法的典型用法代码示例。如果您正苦于以下问题:C# IMessageSink.Write方法的具体用法?C# IMessageSink.Write怎么用?C# IMessageSink.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMessageSink的用法示例。


在下文中一共展示了IMessageSink.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: unroll

		public static LNode unroll(LNode var, LNode cases, LNode body, IMessageSink sink)
		{
			if (!cases.Calls(S.Tuple) && !cases.Calls(S.Braces))
				return Reject(sink, cases, "unroll: the right-hand side of 'in' should be a tuple");

			// Maps identifiers => replacements. The integer counts how many times replacement occurred.
			var replacements = InternalList<Triplet<Symbol, LNode, int>>.Empty;
			if (var.IsId && !var.HasPAttrs()) {
				replacements.Add(Pair.Create(var.Name, (LNode)LNode.Missing, 0));
			} else {
				var vars = var.Args;
				if ((var.Calls(S.Tuple) || var.Calls(S.Braces)) && vars.All(a => a.IsId && !a.HasPAttrs())) {
					replacements = new Triplet<Symbol, LNode, int>[vars.Count].AsInternalList();
					for (int i = 0; i < vars.Count; i++) {
						replacements.InternalArray[i].A = vars[i].Name;
						
						// Check for duplicate names
						for (int j = 0; j < i; j++)
							if (replacements[i].A == replacements[j].A && replacements[i].A.Name != "_")
								sink.Write(Severity.Error, vars[i], "unroll: duplicate name in the left-hand tuple"); // non-fatal
					}
				} else
					return Reject(sink, cases, "unroll: the left-hand side of 'in' should be a simple identifier or a tuple of simple identifiers.");
			}

			UnrollCtx ctx = new UnrollCtx { Replacements = replacements };
			WList<LNode> output = new WList<LNode>();
			int iteration = 0;
			foreach (LNode replacement in cases.Args)
			{
				iteration++;
				bool tuple = replacement.Calls(S.Tuple) || replacement.Calls(S.Braces);
				int count = tuple ? replacement.ArgCount : 1;
				if (replacements.Count != count)
				{
					sink.Write(Severity.Error, replacement, "unroll, iteration {0}: Expected {1} replacement items, got {2}", iteration, replacements.Count, count);
					if (count < replacements.Count)
						continue; // too few
				}
				for (int i = 0; i < replacements.Count; i++)
					replacements.InternalArray[i].B = tuple ? replacement.Args[i] : replacement;

				if (body.Calls(S.Braces)) {
					foreach (LNode stmt in body.Args)
						output.Add(ctx.Replace(stmt).Value);
				} else
					output.Add(ctx.Replace(body).Value);
			}

			foreach (var r in replacements)
				if (r.C == 0 && !r.A.Name.StartsWith("_"))
					sink.Write(Severity.Warning, var, "Replacement variable '{0}' was never used", r.A);
			
			return body.With(S.Splice, output.ToVList());
		}
开发者ID:jonathanvdc,项目名称:Loyc,代码行数:55,代码来源:UnrollMacro.cs

示例2: BackingField

		public static LNode BackingField(LNode prop, IMessageSink sink)
		{
			LNode type, name, body;
			if (prop.ArgCount != 3 || !(body = prop.Args[2]).Calls(S.Braces))
				return null;

			LNode fieldAttr = null, fieldVarAttr = null;
			LNode fieldName;
			bool autoType = false;
			int i;
			for (i = 0; i < prop.Attrs.Count; i++)
			{
				LNode attr = prop.Attrs[i];
				if (attr.IsIdNamed(_field)
					|| attr.Calls(S.Var, 2) 
						&& ((autoType = attr.Args[0].IsIdNamed(_field)) ||
							(fieldVarAttr = attr.AttrNamed(_field)) != null && fieldVarAttr.IsId))
				{
					fieldAttr = attr;
					break;
				}
			}
			if (fieldAttr == null)
				return null;

			LNode field = fieldAttr;
			type = prop.Args[0];
			if (field.IsId) {
				name = prop.Args[1];
				fieldName = F.Id(ChooseFieldName(Ecs.EcsNodePrinter.KeyNameComponentOf(name)));
				field = F.Call(S.Var, type, fieldName).WithAttrs(fieldAttr.Attrs);
			} else {
				fieldName = field.Args[1];
				if (fieldName.Calls(S.Assign, 2))
					fieldName = fieldName.Args[0];
			}
			if (autoType)
				field = field.WithArgChanged(0, type);
			if (fieldVarAttr != null)
				field = field.WithoutAttrNamed(_field);

			LNode newBody = body.WithArgs(body.Args.SmartSelect(stmt =>
			{
				var attrs = stmt.Attrs;
				if (stmt.IsIdNamed(S.get)) {
					stmt = F.Call(stmt.WithoutAttrs(), F.Braces(F.Call(S.Return, fieldName))).WithAttrs(attrs);
					stmt.BaseStyle = NodeStyle.Special;
				}
				if (stmt.IsIdNamed(S.set)) {
					stmt = F.Call(stmt.WithoutAttrs(), F.Braces(F.Call(S.Assign, fieldName, F.Id(S.value)))).WithAttrs(attrs);
					stmt.BaseStyle = NodeStyle.Special;
				}
				return stmt;
			}));
			if (newBody == body)
				sink.Write(Severity.Warning, fieldAttr, "The body of the property does not contain a 'get;' or 'set;' statement without a body, so no code was generated to get or set the backing field.");

			prop = prop.WithAttrs(prop.Attrs.RemoveAt(i)).WithArgChanged(2, newBody);
			return F.Call(S.Splice, new RVList<LNode>(field, prop));
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:60,代码来源:BackingFieldMacro.cs

示例3: CompileTimeValidate

        public override void CompileTimeValidate(INamedMetadataDeclaration metadata, Type typeValidated, IMessageSink messages)
        {
            base.CompileTimeValidate(metadata, typeValidated, messages);

            if (typeValidated.IsValueType && null == Nullable.GetUnderlyingType(typeValidated))
            {
                messages.Write(
                    new Message(MessageLocation.Of(metadata),
                                SeverityType.Error,
                                Strings.ErrorNotNullNonNullableMessageId,
                                String.Format(CultureInfo.InvariantCulture,
                                              Strings.ErrorNotNullNonNullableMessageFormat,
                                              typeValidated.Name),
                                String.Empty,
                                Assembly.GetCallingAssembly().FullName,
                                null));
            }
        }
开发者ID:chester89,项目名称:PostSharpValidation,代码行数:18,代码来源:NotNullAttribute.cs

示例4: CompileTimeValidate

        public override void CompileTimeValidate(ParameterDeclaration parameter, Type memberType, IMessageSink messages)
        {
            base.CompileTimeValidate(parameter, memberType, messages);

            bool isNullable =
                !memberType.IsValueType ||
                (memberType.IsGenericType && memberType.GetGenericTypeDefinition() == typeof(Nullable<>));

            if (!isNullable)
            {
                messages.Write(new Message(
                    SeverityType.Error,
                    "NotNullAttribute_TypeNotNullable",
                    string.Format(CultureInfo.InvariantCulture, "The type '{0}' is not nullable.", memberType.Name),
                    GetType().FullName
                ));
            }
        }
开发者ID:zevinganez,项目名称:code-o-matic,代码行数:18,代码来源:NotNullAttribute.cs

示例5: CompileTimeValidateParameters

        protected override void CompileTimeValidateParameters(MethodDefDeclaration method, IMessageSink messages, ParameterDeclaration firstParameter, ParameterDeclaration secondParameter)
        {
            base.CompileTimeValidateParameters(method, messages, firstParameter, secondParameter);

            if(typeof(IComparable).IsAssignableFrom(firstParameter.ParameterType.GetSystemType(null, null)))
            {
                firstParameterIsComparable = true;
            }
            else if(typeof(IComparable).IsAssignableFrom(secondParameter.ParameterType.GetSystemType(null, null)))
            {
                firstParameterIsComparable = false;
            }
            else
            {
                messages.Write(new Message(
                    SeverityType.Error,
                    "ComparisonValidatorAttribute_ParametersCantBeCompared",
                    string.Format(CultureInfo.InvariantCulture, "None of the parameters '{0}' and '{1}' implements IComparable.", firstParameter.Name, secondParameter.Name),
                    GetType().FullName
                ));
            }
        }
开发者ID:zevinganez,项目名称:code-o-matic,代码行数:22,代码来源:ComparisonValidatorAttribute.cs

示例6: ValidateNonNullMetadata

        /// <summary>
        /// Validates that the provided metadata is not null.
        /// </summary>
        /// <param name="metadata">The metadata to do a null check on.</param>
        /// <param name="messages">An <see cref="IMessageSink"/> instance, used to write messages.</param>
        /// <returns>True if <c>metadata</c> is not null; otherwise, false.</returns>
        private static bool ValidateNonNullMetadata(INamedMetadataDeclaration metadata, IMessageSink messages)
        {
            bool isNotNull = null != metadata;

            if (!isNotNull)
            {
                messages.Write(
                    new Message(MessageLocation.Of(metadata),
                                SeverityType.Fatal,
                                Strings.ErrorNullMetadataMessageId,
                                Strings.ErrorNullMetadataMessage,
                                String.Empty,
                                Assembly.GetCallingAssembly().FullName,
                                null));
            }

            return isNotNull;
        }
开发者ID:chester89,项目名称:PostSharpValidation,代码行数:24,代码来源:ValidationAttribute.cs

示例7: OpenSourceFiles

		public static List<InputOutput> OpenSourceFiles(IMessageSink sink, IEnumerable<string> fileNames)
		{
			var openFiles = new List<InputOutput>();
			foreach (var filename in fileNames) {
				try {
					// TODO: switch to a streaming file reader
					var text = File.ReadAllText(filename, Encoding.UTF8);
					openFiles.Add(new InputOutput(new UString(text), filename));
				} catch (Exception ex) {
					sink.Write(Severity.Error, filename, ex.GetType().Name + ": " + ex.Message);
				}
			}
			return openFiles;
		}
开发者ID:Shaykh,项目名称:Loyc,代码行数:14,代码来源:Compiler.cs

示例8: OpenSourceFiles

		/// <summary>Opens a set of source files by file name, and creates a text file for each.</summary>
		/// <param name="sink"></param>
		/// <param name="fileNames"></param>
		/// <returns></returns>
		public static List<InputOutput> OpenSourceFiles(IMessageSink sink, IEnumerable<string> fileNames)
		{
			var openFiles = new List<InputOutput>();
			foreach (var filename in fileNames) {
				try {
					var stream = File.OpenRead(filename);
					var text = File.ReadAllText(filename, Encoding.UTF8);
					var io = new InputOutput(new StreamCharSource(stream), filename);
					openFiles.Add(io);
				} catch (Exception ex) {
					sink.Write(Severity.Error, filename, ex.GetType().Name + ": " + ex.Message);
				}
			}
			return openFiles;
		}
开发者ID:jonathanvdc,项目名称:Loyc,代码行数:19,代码来源:Compiler.cs

示例9: TryCatch

		static bool TryCatch(object context, IMessageSink sink, Action action)
		{
			try {
				action();
				return true;
			} catch (Exception ex) {
				sink.Write(Severity.Error, context, "{0} ({1})", ex.Message, ex.GetType().Name);
				return false;
			}
		}
开发者ID:Shaykh,项目名称:Loyc,代码行数:10,代码来源:Compiler.cs

示例10: WarnAboutUnknownOptions

		public static void WarnAboutUnknownOptions(BMultiMap<string, string> options, IMessageSink sink, IDictionary<string, Pair<string, string>> knownOptions)
		{
			foreach (var opt in options.Keys) {
				if (!knownOptions.ContainsKey(opt))
					sink.Write(Severity.Warning, "Command line", "Unrecognized option '--{0}'", opt);
			}
		}
开发者ID:Shaykh,项目名称:Loyc,代码行数:7,代码来源:Compiler.cs

示例11: Reject

		static LNode Reject(IMessageSink error, LNode at, string msg, params object[] args)
		{
			error.Write(Severity.Note, at, msg, args);
			return null;
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:5,代码来源:Prelude.cs

示例12: ValidateInitializableExceptionType

        /// <summary>
        /// Validates that the configured validation failure exception is able to be initialized by the aspect.
        /// </summary>
        /// <param name="messages">An <see cref="IMessageSink"/> instance, used to write messages.</param>
        /// <returns>True if the configured exception can be instantiated by this aspect; otherwise, false.</returns>
        /// <remarks>
        /// A properly implemented exception will additionally declare constructors that match the signatures of the base
        /// <see cref="Exception"/> type. This aspect relies particularly on the presence of a constructor overload
        /// that accepts a single string parameter (the exception message).
        /// </remarks>
        private bool ValidateInitializableExceptionType(IMessageSink messages)
        {
            ConstructorInfo constructor = Exception.GetConstructor(BindingFlags.Public | BindingFlags.Instance,
                                                                   null,
                                                                   new[] { typeof(string) },
                                                                   null);
            bool isInstantiable = null != constructor;

            if (!isInstantiable)
            {
                messages.Write(
                    new Message(MessageLocation.Of(Exception),
                                SeverityType.Fatal,
                                Strings.ErrorValidationExceptionImproperTypeMessageId,
                                String.Format(CultureInfo.InvariantCulture,
                                              Strings.ErrorValidationExceptionImproperTypeMessageFormat,
                                              Exception.Name),
                                String.Empty,
                                Assembly.GetCallingAssembly().FullName,
                                null));
            }

            return isInstantiable;
        }
开发者ID:chester89,项目名称:PostSharpValidation,代码行数:34,代码来源:ValidationAttribute.cs

示例13: CompileTimeValidate

        public override void CompileTimeValidate(MethodDefDeclaration method, IMessageSink messages)
        {
            base.CompileTimeValidate(method, messages);

            ParameterDeclaration firstParameter = null;
            ParameterDeclaration secondParameter = null;

            foreach(var parameter in method.Parameters)
            {
                if(parameter.Name == firstParameterName)
                {
                    firstParameter = parameter;
                }
                if(parameter.Name == secondParameterName)
                {
                    secondParameter = parameter;
                }
            }

            if(firstParameter == null)
            {
                messages.Write(new Message(
                    SeverityType.Error,
                    "TwoParametersValidatorAttribute_ParameterNotFound",
                    string.Format(CultureInfo.InvariantCulture,
                        "The parameter '{0}' does not exist in method '{1}'.",
                        firstParameterName,
                        method.Name),
                    GetType().FullName
                ));
            }

            if(secondParameter == null)
            {
                messages.Write(new Message(
                    SeverityType.Error,
                    "TwoParametersValidatorAttribute_ParameterNotFound",
                    string.Format(CultureInfo.InvariantCulture,
                        "The parameter '{0}' does not exist in method '{1}'.",
                        secondParameterName,
                        method.Name),
                    GetType().FullName
                ));
            }

            if(firstParameter != null && secondParameter != null)
            {
                if(firstParameterName == secondParameterName)
                {
                    {
                        messages.Write(new Message(
                            SeverityType.Error,
                            "TwoParametersValidatorAttribute_CantSpecifyTheSameParameter",
                            "The same name has been specified for both parameters.",
                            GetType().FullName
                        ));
                    }
                }
                else
                {
                    CompileTimeValidateParameters(method, messages, firstParameter, secondParameter);
                }
            }
        }
开发者ID:zevinganez,项目名称:code-o-matic,代码行数:64,代码来源:TwoParametersValidatorAttribute.cs

示例14: if

		public static LNode @try(LNode node, IMessageSink sink)
		{
			if (!node.IsCall)
				return null;

			// try(code, catch, Exception::e, handler, catch, ..., finally, handler)
			// ...becomes...
			// #try(#{ stmt1; stmt2; ... }, #catch(#var(Exception, e), handler), #finally(handler))
			LNode finallyCode = null;
			RWList<LNode> clauses = new RWList<LNode>();
			var parts = node.Args;
			
			for (int i = parts.Count-2; i >= 1; i -= 2)
			{
				var p = parts[i];
				if (p.IsIdNamed(_finally)) {
					if (clauses.Count != 0 || finallyCode != null)
						sink.Write(Severity.Error, p, "The «finally» clause must come last, there can only be one of them.");
					finallyCode = parts[i+1];
				} else if (p.Name == _catch) {
					if (p.ArgCount > 0) {
						// This is a normal catch clause
						clauses.Insert(0, F.Call(S.Catch, F.Call(S.Splice, p.Args), parts[i + 1]));
					} else {
						// This is a catch-all clause (the type argument is missing)
						if (clauses.Count != 0)
							sink.Write(Severity.Error, p, "The catch-all clause must be the last «catch» clause.");
						clauses.Add(F.Call(S.Catch, F._Missing, parts[i + 1]));
					}
				} else if (i > 1 && parts[i-1].IsIdNamed(_catch)) {
					// This is a normal catch clause
					clauses.Insert(0, F.Call(S.Catch, AutoRemoveParens(p), parts[i+1]));
					i--;
				} else {
					return Reject(sink, p, "Expected «catch» or «finally» clause here. Clause is missing or malformed.");
				}
				if (i == 2)
					return Reject(sink, parts[1], "Expected «catch» or «finally» clause here. Clause is missing or malformed.");
			}
			if (clauses.Count == 0 && finallyCode == null) {
				Debug.Assert(node.ArgCount <= 1);
				return Reject(sink, node, "Missing «catch, Type, Code» or «finally, Code» clause");
			}
			if (finallyCode != null)
				clauses.Add(F.Call(S.Finally, finallyCode));
			clauses.Insert(0, node.Args[0]);
			return node.With(S.Try, clauses.ToRVList());
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:48,代码来源:Prelude.cs

示例15: ValidateExceptionTypeCanBeInstantiated

        private bool ValidateExceptionTypeCanBeInstantiated(IMessageSink messages)
        {
            ConstructorInfo constructor = exception.GetConstructor(
                BindingFlags.Public | BindingFlags.Instance,
                null,
                new[] {typeof(string)},
                null
            );

            bool isValid = constructor != null;
            if(!isValid)
            {
                messages.Write(new Message(
                    SeverityType.Error,
                    "SpecificExceptionParameterValidatorAttribute_ExceptionTypeCanotBeInstantiated",
                    string.Format(CultureInfo.InvariantCulture, "The exception '{0}' does not have a public constructor that takes a string as parameter.", exception.Name),
                    GetType().FullName
                ));
            }
            return isValid;
        }
开发者ID:zevinganez,项目名称:code-o-matic,代码行数:21,代码来源:SpecificExceptionParameterValidatorAttribute.cs


注:本文中的IMessageSink.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。