當前位置: 首頁>>代碼示例>>C#>>正文


C# AttributeEncoder.EncodeNamedArguments方法代碼示例

本文整理匯總了C#中Mono.CSharp.AttributeEncoder.EncodeNamedArguments方法的典型用法代碼示例。如果您正苦於以下問題:C# AttributeEncoder.EncodeNamedArguments方法的具體用法?C# AttributeEncoder.EncodeNamedArguments怎麽用?C# AttributeEncoder.EncodeNamedArguments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.CSharp.AttributeEncoder的用法示例。


在下文中一共展示了AttributeEncoder.EncodeNamedArguments方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DefineInitializedData

			public FieldSpec DefineInitializedData (byte[] data, Location loc)
			{
				Struct size_type;
				if (!size_types.TryGetValue (data.Length, out size_type)) {
					//
					// Build common type for this data length. We cannot use
					// DefineInitializedData because it creates public type,
					// and its name is not unique among modules
					//
					size_type = new Struct (null, this, new MemberName ("$ArrayType=" + data.Length, Location), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null);
					size_type.CreateType ();
					size_type.DefineType ();

					size_types.Add (data.Length, size_type);

					var pa = Module.PredefinedAttributes.StructLayout;
					if (pa.Constructor != null || pa.ResolveConstructor (Location, TypeManager.short_type)) {
						var argsEncoded = new AttributeEncoder (false);
						argsEncoded.Encode ((short) LayoutKind.Explicit);

						var field_size = pa.GetField ("Size", TypeManager.int32_type, Location);
						var pack = pa.GetField ("Pack", TypeManager.int32_type, Location);
						if (field_size != null) {
							argsEncoded.EncodeNamedArguments (
								new[] { field_size, pack },
								new[] { new IntConstant ((int) data.Length, Location), new IntConstant (1, Location) }
							);
						}

						pa.EmitAttribute (size_type.TypeBuilder, argsEncoded);
					}
				}

				var name = "$field-" + fields.ToString ("X");
				++fields;
				const Modifiers fmod = Modifiers.STATIC | Modifiers.INTERNAL;
				var fbuilder = TypeBuilder.DefineField (name, size_type.CurrentType.GetMetaInfo (), ModifiersExtensions.FieldAttr (fmod) | FieldAttributes.HasFieldRVA);
#if STATIC
				fbuilder.__SetDataAndRVA (data);
#else
				if (set_data == null)
					set_data = typeof (FieldBuilder).GetMethod ("SetRVAData", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

				try {
					set_data.Invoke (fbuilder, new object[] { data });
				} catch {
					Report.RuntimeMissingSupport (loc, "SetRVAData");
				}
#endif

				return new FieldSpec (CurrentType, null, size_type.CurrentType, fbuilder, fmod);
			}
開發者ID:hindlemail,項目名稱:mono,代碼行數:52,代碼來源:roottypes.cs

示例2: DefineInitializedData

			public FieldSpec DefineInitializedData (byte[] data, Location loc)
			{
				Struct size_type;
				if (!size_types.TryGetValue (data.Length, out size_type)) {
					//
					// Build common type for this data length. We cannot use
					// DefineInitializedData because it creates public type,
					// and its name is not unique among modules
					//
					size_type = new Struct (null, this, new MemberName ("$ArrayType=" + data.Length, Location), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null);
					size_type.CreateType ();
					size_type.DefineType ();

					size_types.Add (data.Length, size_type);

					var pa = Module.PredefinedAttributes.StructLayout;
					if (pa.Constructor != null || pa.ResolveConstructor (Location, Compiler.BuildinTypes.Short)) {
						var argsEncoded = new AttributeEncoder ();
						argsEncoded.Encode ((short) LayoutKind.Explicit);

						var field_size = pa.GetField ("Size", Compiler.BuildinTypes.Int, Location);
						var pack = pa.GetField ("Pack", Compiler.BuildinTypes.Int, Location);
						if (field_size != null) {
							argsEncoded.EncodeNamedArguments (
								new[] { field_size, pack },
								new[] { new IntConstant (Compiler.BuildinTypes, (int) data.Length, Location), new IntConstant (Compiler.BuildinTypes, 1, Location) }
							);
						}

						pa.EmitAttribute (size_type.TypeBuilder, argsEncoded);
					}
				}

				var name = "$field-" + fields.ToString ("X");
				++fields;
				const Modifiers fmod = Modifiers.STATIC | Modifiers.INTERNAL;
				var fbuilder = TypeBuilder.DefineField (name, size_type.CurrentType.GetMetaInfo (), ModifiersExtensions.FieldAttr (fmod) | FieldAttributes.HasFieldRVA);
				fbuilder.__SetDataAndRVA (data);

				return new FieldSpec (CurrentType, null, size_type.CurrentType, fbuilder, fmod);
			}
開發者ID:charles-cai,項目名稱:mono,代碼行數:41,代碼來源:roottypes.cs

示例3: EmitFieldSize

		void EmitFieldSize (int buffer_size)
		{
			int type_size = BuiltinTypeSpec.GetSize (MemberType);

			if (buffer_size > int.MaxValue / type_size) {
				Report.Error (1664, Location, "Fixed size buffer `{0}' of length `{1}' and type `{2}' exceeded 2^31 limit",
					GetSignatureForError (), buffer_size.ToString (), TypeManager.CSharpName (MemberType));
				return;
			}

			AttributeEncoder encoder;

			var ctor = Module.PredefinedMembers.StructLayoutAttributeCtor.Resolve (Location);
			if (ctor == null)
				return;

			var field_size = Module.PredefinedMembers.StructLayoutSize.Resolve (Location);
			var field_charset = Module.PredefinedMembers.StructLayoutCharSet.Resolve (Location);
			if (field_size == null || field_charset == null)
				return;

			var char_set = CharSet ?? Module.DefaultCharSet ?? 0;

			encoder = new AttributeEncoder ();
			encoder.Encode ((short)LayoutKind.Sequential);
			encoder.EncodeNamedArguments (
				new [] { field_size, field_charset },
				new Constant [] { 
					new IntConstant (Compiler.BuiltinTypes, buffer_size * type_size, Location),
					new IntConstant (Compiler.BuiltinTypes, (int) char_set, Location)
				}
			);

			fixed_buffer_type.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), encoder.ToArray ());

			//
			// Don't emit FixedBufferAttribute attribute for private types
			//
			if ((ModFlags & Modifiers.PRIVATE) != 0)
				return;

			ctor = Module.PredefinedMembers.FixedBufferAttributeCtor.Resolve (Location);
			if (ctor == null)
				return;

			encoder = new AttributeEncoder ();
			encoder.EncodeTypeName (MemberType);
			encoder.Encode (buffer_size);
			encoder.EncodeEmptyNamedArguments ();

			FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), encoder.ToArray ());
		}
開發者ID:agallero,項目名稱:mono,代碼行數:52,代碼來源:field.cs

示例4: EmitFieldSize

        void EmitFieldSize(int buffer_size)
        {
            PredefinedAttribute pa;
            AttributeEncoder encoder;

            pa = Module.PredefinedAttributes.StructLayout;
            if (pa.Constructor == null && !pa.ResolveConstructor (Location, TypeManager.short_type))
                return;

            var char_set_type = Module.PredefinedTypes.CharSet.Resolve (Location);
            if (char_set_type == null)
                return;

            var field_size = pa.GetField ("Size", TypeManager.int32_type, Location);
            var field_charset = pa.GetField ("CharSet", char_set_type, Location);
            if (field_size == null || field_charset == null)
                return;

            var char_set = CharSet ?? Module.DefaultCharSet ?? 0;

            encoder = new AttributeEncoder ();
            encoder.Encode ((short)LayoutKind.Sequential);
            encoder.EncodeNamedArguments (
                new [] { field_size, field_charset },
                new Constant [] { new IntConstant (buffer_size, Location), new IntConstant ((int) char_set, Location) }
            );

            pa.EmitAttribute (fixed_buffer_type, encoder);

            //
            // Don't emit FixedBufferAttribute attribute for private types
            //
            if ((ModFlags & Modifiers.PRIVATE) != 0)
                return;

            pa = Module.PredefinedAttributes.FixedBuffer;
            if (pa.Constructor == null && !pa.ResolveConstructor (Location, TypeManager.type_type, TypeManager.int32_type))
                return;

            encoder = new AttributeEncoder ();
            encoder.EncodeTypeName (MemberType);
            encoder.Encode (buffer_size);
            encoder.EncodeEmptyNamedArguments ();

            pa.EmitAttribute (FieldBuilder, encoder);
        }
開發者ID:RainsSoft,項目名稱:MonoCompilerAsAService,代碼行數:46,代碼來源:field.cs

示例5: EmitFieldSize

		void EmitFieldSize (int buffer_size)
		{
			int type_size = BuiltinTypeSpec.GetSize (MemberType);

			if (buffer_size > int.MaxValue / type_size) {
				Report.Error (1664, Location, "Fixed size buffer `{0}' of length `{1}' and type `{2}' exceeded 2^31 limit",
					GetSignatureForError (), buffer_size.ToString (), MemberType.GetSignatureForError ());
				return;
			}

			AttributeEncoder encoder;
			MethodSpec ctor;

			var char_set = CharSetValue ?? Module.DefaultCharSet ?? 0;
#if STATIC
			//
			// Set struct layout without resolving StructLayoutAttribute which is not always available
			//

			TypeAttributes attribs = TypeAttributes.SequentialLayout;
			switch (char_set) {
			case CharSet.None:
			case CharSet.Ansi:
				attribs |= TypeAttributes.AnsiClass;
				break;
			case CharSet.Auto:
				attribs |= TypeAttributes.AutoClass;
				break;
			case CharSet.Unicode:
				attribs |= TypeAttributes.UnicodeClass;
				break;
			}

			fixed_buffer_type.__SetAttributes (fixed_buffer_type.Attributes | attribs);
			fixed_buffer_type.__SetLayout (0, buffer_size * type_size);
#else
			ctor = Module.PredefinedMembers.StructLayoutAttributeCtor.Resolve (Location);
			if (ctor == null)
				return;

			var field_size = Module.PredefinedMembers.StructLayoutSize.Resolve (Location);
			var field_charset = Module.PredefinedMembers.StructLayoutCharSet.Resolve (Location);
			if (field_size == null || field_charset == null)
				return;

			encoder = new AttributeEncoder ();
			encoder.Encode ((short)LayoutKind.Sequential);
			encoder.EncodeNamedArguments (
				new [] { field_size, field_charset },
				new Constant [] { 
					new IntConstant (Compiler.BuiltinTypes, buffer_size * type_size, Location),
					new IntConstant (Compiler.BuiltinTypes, (int) char_set, Location)
				}
			);

			fixed_buffer_type.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), encoder.ToArray ());
#endif
			//
			// Don't emit FixedBufferAttribute attribute for private types
			//
			if ((ModFlags & Modifiers.PRIVATE) != 0)
				return;

			ctor = Module.PredefinedMembers.FixedBufferAttributeCtor.Resolve (Location);
			if (ctor == null)
				return;

			encoder = new AttributeEncoder ();
			encoder.EncodeTypeName (MemberType);
			encoder.Encode (buffer_size);
			encoder.EncodeEmptyNamedArguments ();

			FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), encoder.ToArray ());
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:74,代碼來源:field.cs

示例6: EmitFieldSize

		void EmitFieldSize (int buffer_size)
		{
			int type_size = Expression.GetTypeSize (MemberType);

			if (buffer_size > int.MaxValue / type_size) {
				Report.Error (1664, Location, "Fixed size buffer `{0}' of length `{1}' and type `{2}' exceeded 2^31 limit",
					GetSignatureForError (), buffer_size.ToString (), TypeManager.CSharpName (MemberType));
				return;
			}
			
			PredefinedAttribute pa;
			AttributeEncoder encoder;

			pa = Module.PredefinedAttributes.StructLayout;
			if (pa.Constructor == null && !pa.ResolveConstructor (Location, TypeManager.short_type))
				return;

			var char_set_type = Module.PredefinedTypes.CharSet.Resolve (Location);
			if (char_set_type == null)
				return;

			var field_size = pa.GetField ("Size", TypeManager.int32_type, Location);
			var field_charset = pa.GetField ("CharSet", char_set_type, Location);
			if (field_size == null || field_charset == null)
				return;

			var char_set = CharSet ?? Module.DefaultCharSet;

			encoder = new AttributeEncoder ();
			encoder.Encode ((short)LayoutKind.Sequential);
			encoder.EncodeNamedArguments (
				new [] { field_size, field_charset },
				new Constant [] { new IntConstant (buffer_size * type_size, Location), new IntConstant ((int) char_set, Location) }
			);

			pa.EmitAttribute (fixed_buffer_type, encoder);

			//
			// Don't emit FixedBufferAttribute attribute for private types
			//
			if ((ModFlags & Modifiers.PRIVATE) != 0)
				return;

			pa = Module.PredefinedAttributes.FixedBuffer;
			if (pa.Constructor == null && !pa.ResolveConstructor (Location, TypeManager.type_type, TypeManager.int32_type))
				return;

			encoder = new AttributeEncoder ();
			encoder.EncodeTypeName (MemberType);
			encoder.Encode (buffer_size);
			encoder.EncodeEmptyNamedArguments ();

			pa.EmitAttribute (FieldBuilder, encoder);
		}
開發者ID:wamiq,項目名稱:debian-mono,代碼行數:54,代碼來源:field.cs


注:本文中的Mono.CSharp.AttributeEncoder.EncodeNamedArguments方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。