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


C# CSharp.Struct类代码示例

本文整理汇总了C#中Mono.CSharp.Struct的典型用法代码示例。如果您正苦于以下问题:C# Struct类的具体用法?C# Struct怎么用?C# Struct使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Struct类属于Mono.CSharp命名空间,在下文中一共展示了Struct类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 (this, new MemberName ("$ArrayType=" + data.Length, loc), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null);
					size_type.CreateContainer ();
					size_type.DefineContainer ();

					size_types.Add (data.Length, size_type);

					// It has to work even if StructLayoutAttribute does not exist
					size_type.TypeBuilder.__SetLayout (1, data.Length);
				}

				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:nobled,项目名称:mono,代码行数:27,代码来源:module.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, 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

示例3: 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

示例4: CheckStructCycles

		bool CheckStructCycles (Struct s)
		{
			if (s.Fields == null)
				return true;

			if (s.InTransit)
				return false;

			s.InTransit = true;
			foreach (FieldBase field in s.Fields) {
				TypeSpec ftype = field.Spec.MemberType;
				if (!ftype.IsStruct)
					continue;

				if (ftype is BuiltinTypeSpec)
					continue;

				foreach (var targ in ftype.TypeArguments) {
					if (!CheckFieldTypeCycle (targ)) {
						Report.Error (523, field.Location,
							"Struct member `{0}' of type `{1}' causes a cycle in the struct layout",
							field.GetSignatureForError (), ftype.GetSignatureForError ());
						break;
					}
				}

				//
				// Static fields of exactly same type are allowed
				//
				if (field.IsStatic && ftype == s.CurrentType)
					continue;

				if (!CheckFieldTypeCycle (ftype)) {
					Report.Error (523, field.Location,
						"Struct member `{0}' of type `{1}' causes a cycle in the struct layout",
						field.GetSignatureForError (), ftype.GetSignatureForError ());
					break;
				}
			}

			s.InTransit = false;
			return true;
		}
开发者ID:jordanbtucker,项目名称:mono,代码行数:43,代码来源:class.cs

示例5: Visit

			public override void Visit (Struct s)
			{
				TypeDeclaration newType = new TypeDeclaration ();
				newType.ClassType = MonoDevelop.Projects.Dom.ClassType.Struct;
				
				var location = LocationsBag.GetMemberLocation (s);
				AddModifiers (newType, location);
				if (location != null)
					newType.AddChild (new CSharpTokenNode (Convert (location[0]), "struct".Length), TypeDeclaration.TypeKeyword);
				newType.AddChild (new Identifier (s.Name, Convert (s.MemberName.Location)), AbstractNode.Roles.Identifier);
				if (s.MemberName.TypeArguments != null)  {
					var typeArgLocation = LocationsBag.GetLocations (s.MemberName);
					if (typeArgLocation != null)
						newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
//					AddTypeArguments (newType, typeArgLocation, s.MemberName.TypeArguments);
					if (typeArgLocation != null)
						newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
					AddConstraints (newType, s);
				}
				if (location != null)
					newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AbstractCSharpNode.Roles.LBrace);
				typeStack.Push (newType);
				base.Visit (s);
				if (location != null)
					newType.AddChild (new CSharpTokenNode  (Convert (location[2]), 1), AbstractCSharpNode.Roles.RBrace);
				typeStack.Pop ();
				AddType (newType);
			}
开发者ID:pgoron,项目名称:monodevelop,代码行数:28,代码来源:CSharpParser.cs

示例6: Visit

			public override void Visit(Struct s)
			{
				var newType = new TypeDeclaration();
				newType.ClassType = ClassType.Struct;
				AddAttributeSection(newType, s);
				var location = LocationsBag.GetMemberLocation(s);
				AddModifiers(newType, location);
				int curLoc = 0;
				if (location != null && location.Count > 0)
					newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.StructKeyword), Roles.StructKeyword);
				newType.AddChild(Identifier.Create(s.MemberName.Name, Convert(s.MemberName.Location)), Roles.Identifier);
				AddTypeParameters(newType, s.MemberName);
				
				if (s.TypeBaseExpressions != null) {
					if (location != null && curLoc < location.Count)
						newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.Colon), Roles.Colon);
					var commaLocations = LocationsBag.GetLocations(s.TypeBaseExpressions);
					int i = 0;
					foreach (var baseTypes in s.TypeBaseExpressions) {
						newType.AddChild(ConvertToType(baseTypes), Roles.BaseType);
						if (commaLocations != null && i < commaLocations.Count) {
							newType.AddChild(new CSharpTokenNode(Convert(commaLocations [i]), Roles.Comma), Roles.Comma);
							i++;
						}
					}
				}
				
				AddConstraints(newType, s.CurrentTypeParameters);
				if (location != null && curLoc < location.Count)
					newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.LBrace), Roles.LBrace);
				typeStack.Push(newType);
				base.Visit(s);
				if (location != null && location.Count > 2) {
					if (location != null && curLoc < location.Count)
						newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.RBrace), Roles.RBrace);
					if (location != null && curLoc < location.Count)
						newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.Semicolon), Roles.Semicolon);
				} else {
					// parser error, set end node to max value.
					newType.AddChild(new ErrorNode(), Roles.Error);
				}
				typeStack.Pop();
				AddType(newType);
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:44,代码来源:CSharpParser.cs

示例7: Visit

			public override void Visit (Struct s)
			{
				VisitType (s, ClassType.Struct);
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:4,代码来源:McsParser.cs

示例8: Visit

		public virtual void Visit (Struct s)
		{
			VisitTypeDefinition (s);
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:4,代码来源:visit.cs

示例9: Visit

		public virtual void Visit (Struct s)
		{
			VisitTypeContainer (s);
		}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:4,代码来源:visit.cs

示例10: Visit

			public override void Visit (Struct s)
			{
				TypeDeclaration newType = new TypeDeclaration ();
				newType.ClassType = ClassType.Struct;
				AddAttributeSection (newType, s);
				var location = LocationsBag.GetMemberLocation (s);
				AddModifiers (newType, location);
				if (location != null)
					newType.AddChild (new CSharpTokenNode (Convert (location[0]), "struct".Length), TypeDeclaration.Roles.Keyword);
				newType.AddChild (Identifier.Create (s.MemberName.Name, Convert (s.MemberName.Location)), AstNode.Roles.Identifier);
				if (s.MemberName.TypeArguments != null)  {
					var typeArgLocation = LocationsBag.GetLocations (s.MemberName);
					if (typeArgLocation != null)
						newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
					AddTypeParameters (newType, typeArgLocation, s.MemberName.TypeArguments);
					if (typeArgLocation != null)
						newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
					AddConstraints (newType, s);
				}
				
				if (s.TypeBaseExpressions != null) {
					foreach (var baseTypes in s.TypeBaseExpressions) {
						newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole);
					}
				}
				
				if (location != null && location.Count > 1)
					newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace);
				typeStack.Push (newType);
				base.Visit (s);
				if (location != null && location.Count > 2) {
					newType.AddChild (new CSharpTokenNode  (Convert (location[2]), 1), AstNode.Roles.RBrace);
				} else {
					// parser error, set end node to max value.
					newType.AddChild (new ErrorNode (), AstNode.Roles.Error);
				}
				typeStack.Pop ();
				AddType (newType);
			}
开发者ID:aleksandersumowski,项目名称:monodevelop,代码行数:39,代码来源:CSharpParser.cs

示例11: CheckStructCycles

		bool CheckStructCycles (Struct s)
		{
			if (s.Fields == null)
				return true;

			if (s.InTransit)
				return false;

			s.InTransit = true;
			foreach (FieldBase field in s.Fields) {
				TypeSpec ftype = field.Spec.MemberType;
				if (!ftype.IsStruct)
					continue;

				if (ftype is PredefinedTypeSpec)
					continue;

				foreach (var targ in ftype.TypeArguments) {
					if (!CheckFieldTypeCycle (targ)) {
						Report.Error (523, field.Location,
							"Struct member `{0}' of type `{1}' causes a cycle in the struct layout",
							field.GetSignatureForError (), ftype.GetSignatureForError ());
						break;
					}
				}

				if ((field.IsStatic && (!ftype.IsGeneric || ftype == CurrentType)))
					continue;

				if (!CheckFieldTypeCycle (ftype)) {
					Report.Error (523, field.Location,
						"Struct member `{0}' of type `{1}' causes a cycle in the struct layout",
						field.GetSignatureForError (), ftype.GetSignatureForError ());
					break;
				}
			}

			s.InTransit = false;
			return true;
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:40,代码来源:class.cs

示例12: Visit

		public virtual void Visit (Struct s)
		{
			if (!AutoVisit)
				VisitTypeContainer (s);
		}
开发者ID:rlfqudxo,项目名称:playscript-mono,代码行数:5,代码来源:visit.cs

示例13: AddStruct

		public AdditionResult AddStruct (Struct s)
		{
			AdditionResult res;
			
			if ((res = IsValid (s.Basename)) != AdditionResult.Success)
				return res;

			DefineName (s.Name, s);
			types.Add (s);

			return AdditionResult.Success;
		}
开发者ID:emtees,项目名称:old-code,代码行数:12,代码来源:class.cs

示例14: Visit

			public override void Visit (Struct s)
			{
				TypeDeclaration newType = new TypeDeclaration ();
				newType.ClassType = ClassType.Struct;
				
				var location = LocationsBag.GetMemberLocation (s);
				AddModifiers (newType, location);
				if (location != null)
					newType.AddChild (new CSharpTokenNode (Convert (location[0]), "struct".Length), TypeDeclaration.Roles.Keyword);
				newType.AddChild (new Identifier (s.Basename, Convert (s.MemberName.Location)), AstNode.Roles.Identifier);
				if (s.MemberName.TypeArguments != null)  {
					var typeArgLocation = LocationsBag.GetLocations (s.MemberName);
					if (typeArgLocation != null)
						newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
					AddTypeParameters (newType, typeArgLocation, s.MemberName.TypeArguments);
					if (typeArgLocation != null)
						newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
					AddConstraints (newType, s);
				}
				if (location != null && location.Count > 1)
					newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace);
				typeStack.Push (newType);
				base.Visit (s);
				if (location != null && location.Count > 2)
					newType.AddChild (new CSharpTokenNode  (Convert (location[2]), 1), AstNode.Roles.RBrace);
				typeStack.Pop ();
				AddType (newType);
			}
开发者ID:madkat,项目名称:NRefactory,代码行数:28,代码来源:CSharpParser.cs


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