• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IMetadataTokenProvider类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



IMetadataTokenProvider类属于命名空间,在下文中一共展示了IMetadataTokenProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Inject

        public void Inject(ICSharpCode.ILSpy.TreeNodes.ILSpyTreeNode node, string name, IMetadataTokenProvider member)
        {
            //Type
            var type = ((IMemberTreeNode)node).Member as TypeDefinition;

            //Creates the method definition
            var method = new MethodDefinition(
                name,
                MethodAttributes.Public,
                type.Module.TypeSystem.Void
            )
            {
                MetadataToken = new MetadataToken(TokenType.Method, ILEdit.GlobalContainer.GetFreeRID(type.Module))
            };

            //Checks if the destination type is an interface
            if (type.IsInterface)
                method.Attributes |= MethodAttributes.NewSlot | MethodAttributes.CheckAccessOnOverride | MethodAttributes.Abstract | MethodAttributes.Virtual;

            //Adds the method to the type
            type.Methods.Add(method);
            method.Overrides.Clear();
            if (node is TypeTreeNode)
            {
                node.Children.Add(new ILEditTreeNode(method, false));
                Helpers.Tree.SortChildren((TypeTreeNode)node);
            }
            else if (node is ILEditTreeNode)
            {
                ((ILEditTreeNode)node).RefreshChildren();
            }
        }
开发者ID:95ulisse,项目名称:ILEdit,代码行数:32,代码来源:MethodInjector.cs


示例2: Equals

        /// <summary>
        /// Compare IMetadataTokenProvider instances based on their metadata token and their
        /// assembly.
        /// </summary>
        /// <param name="self">The IMetadataTokenProvider instance where the method is applied.</param>
        /// <param name="other">The IMetadataTokenProvider instance to compare to</param>
        /// <returns>True if the metadata tokens and assembly are identical, False otherwise</returns>
        public static bool Equals(this IMetadataTokenProvider self, IMetadataTokenProvider other)
        {
            if (self == other)
                return true;
            if (other == null)
                return (self == null);

            MetadataToken token = self.MetadataToken;
            if (!token.Equals(other.MetadataToken))
                return false;

            // metadata token is unique per assembly
            AssemblyDefinition self_assembly = GetAssembly(self);
            if (self_assembly == null)
            {
                // special case for Namespace (where GetAssembly would return null)
                if (token.TokenType == NamespaceDefinition.NamespaceTokenType)
                    return (self as NamespaceDefinition).Name == (other as NamespaceDefinition).Name;
                else
                    return false;
            }
            AssemblyDefinition other_assembly = GetAssembly(other);
            // compare assemblies tokens (but do not recurse)
            return other == null ? false : self_assembly.MetadataToken.Equals(other_assembly.MetadataToken);
        }
开发者ID:mdabbagh88,项目名称:arrayslice,代码行数:32,代码来源:CecilRocks.cs


示例3: CheckParametersAndValues

		void CheckParametersAndValues (IMetadataTokenProvider provider, IMethodSignature constructor, IList<CustomAttributeArgument> arguments)
		{
			for (int index = 0; index < arguments.Count; index++) {
				ParameterDefinition parameter = constructor.Parameters[index];
				if (parameter.ParameterType.IsNamed ("System", "String")) {
					string value = (string) arguments [index].Value;
					if (Contains (parameter.Name, "version")) {
						Version v = null;
						if (!Version.TryParse (value, out v)) {
							string msg = String.Format (CultureInfo.InvariantCulture, "The value passed: {0} can't be parsed to a valid Version.", value);
							Runner.Report (provider, Severity.High, Confidence.High, msg);
						}
						continue;
					}
					if (Contains (parameter.Name, "url") ||
						Contains (parameter.Name, "uri") ||
						Contains (parameter.Name, "urn")) {
						Uri parsed = null;
						if (!Uri.TryCreate (value, UriKind.Absolute, out parsed)) {
							string msg = String.Format (CultureInfo.InvariantCulture, "The valued passed {0} can't be parsed to a valid Uri.", value);
							Runner.Report (provider, Severity.High, Confidence.High, msg);
						}
						continue;
					}
					if (Contains (parameter.Name, "guid")) {
						Guid g;
						if (!Guid.TryParse (value, out g)) {
							string msg = String.Format (CultureInfo.InvariantCulture, "The valued passed {0} can't be parsed to a valid Guid.", value);
							Runner.Report (provider, Severity.High, Confidence.High, msg);
						}
						continue;
					}
				}
			}
		}
开发者ID:alfredodev,项目名称:mono-tools,代码行数:35,代码来源:AttributeStringLiteralsShouldParseCorrectlyRule.cs


示例4: Inject

        public void Inject(ICSharpCode.ILSpy.TreeNodes.ILSpyTreeNode node, string name, IMetadataTokenProvider member)
        {
            //Name and namespace
            var typeName = node is ModuleTreeNode ? (name.Substring(name.Contains(".") ? name.LastIndexOf('.') + 1 : 0)) : name;
            var typeNamespace = node is ModuleTreeNode ? (name.Substring(0, name.Contains(".") ? name.LastIndexOf('.') : 0)) : string.Empty;

            //Checks that the typename isn't empty
            if (string.IsNullOrEmpty(typeName))
            {
                MessageBox.Show("Please, specify the name of the type", "Type name required", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            //Creates a new class definition
            var c = new TypeDefinition(
                typeNamespace,
                typeName,
                TypeAttributes.Class | TypeAttributes.Interface | TypeAttributes.Public | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.Abstract
            )
            {
                IsAnsiClass = true,
            };

            //Adds to the node
            Helpers.Tree.AddTreeNode(node, c, null, null);
        }
开发者ID:95ulisse,项目名称:ILEdit,代码行数:26,代码来源:InterfaceInjector.cs


示例5: ProcessProvider

		void ProcessProvider (IMetadataTokenProvider provider)
		{
			if (!TunerAnnotations.IsInternalized (Context, provider))
				return;

			Console.WriteLine ("[internalized] {0}", provider);
		}
开发者ID:Zman0169,项目名称:mono,代码行数:7,代码来源:PrintStatus.cs


示例6: GetReference

 static TypeReference GetReference(Type type, IMetadataTokenProvider metadata)
 {
     ModuleDefinition module = metadata.GetAssembly().MainModule;
     TypeReference tr;
     if (!module.TryGetTypeReference(type.FullName, out tr))
         tr = module.Import(type);
     return tr;
 }
开发者ID:mdabbagh88,项目名称:arrayslice,代码行数:8,代码来源:PrimitiveReferences.cs


示例7: Mark

		void Mark (IMetadataTokenProvider provider, CustomAttribute preserve_attribute)
		{
			if (IsConditionalAttribute (preserve_attribute)) {
				PreserveConditional (provider);
				return;
			}

			PreserveUnconditional (provider);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:9,代码来源:ApplyPreserveAttributeBase.cs


示例8: Add

		public void Add (string rule, IMetadataTokenProvider metadata)
		{
			HashSet<IMetadataTokenProvider> list;
			if (!ignore.TryGetValue (rule, out list)) {
				list = new HashSet<IMetadataTokenProvider> ();
				ignore.Add (rule, list);
			}
			list.Add (metadata);
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:9,代码来源:BasicIgnoreList.cs


示例9: CheckReturnVoid

		private bool CheckReturnVoid (IMetadataTokenProvider eventType, IMethodSignature invoke)
		{
			string full_name = invoke.ReturnType.FullName;
			if (String.Compare (full_name, "System.Void") == 0)
				return true;

			string msg = String.Format ("The delegate should return void, not {0}", full_name);
			Runner.Report (eventType, Severity.Medium, Confidence.High, msg);
			return false;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:10,代码来源:DeclareEventHandlersCorrectlyRule.cs


示例10: MemberImporter

        /// <summary>
        /// Creates a new instance of this MemberImporter
        /// </summary>
        /// <param name="member">Member to import</param>
        /// <param name="destination">Destination of the importing</param>
        /// <param name="session">Importing session</param>
        public MemberImporter(IMetadataTokenProvider member, IMetadataTokenProvider destination, MemberImportingSession session)
        {
            //Checks if the member can be imported (and that member and destination aren't null)
            if (!CanImport(member, destination))
                throw new ArgumentException(string.Format("{0} cannot import '{1}' into '{2}'", this.GetType().Name, member, destination));

            //Stores member and destination
            _member = member;
            _destination = destination;
            _Session = session;
        }
开发者ID:95ulisse,项目名称:ILEdit,代码行数:17,代码来源:MemberImporter.cs


示例11: ILEditTreeNode

        /// <summary>
        /// Creates a new instance of the class ILEditTreeNode
        /// </summary>
        /// <param name="tokenProvider"></param>
        public ILEditTreeNode(IMetadataTokenProvider tokenProvider, bool manuallyFilledChildren)
        {
            //Stores the parameters
            language = MainWindow.Instance.CurrentLanguage;
            _tokenProvider = tokenProvider;
            this.LazyLoading = !manuallyFilledChildren;
            _manuallyFilledChildren = manuallyFilledChildren;

            //Sets the foreground
            this.Foreground = GlobalContainer.NewNodesBrush;
        }
开发者ID:95ulisse,项目名称:ILEdit,代码行数:15,代码来源:ILEditTreeNode.cs


示例12: Inject

        public void Inject(ICSharpCode.ILSpy.TreeNodes.ILSpyTreeNode node, string name, IMetadataTokenProvider member)
        {
            //Gets the parent module
            var moduleNode = Helpers.Tree.GetModuleNode(node);

            //Injects the assembly reference
            moduleNode.Module.AssemblyReferences.Add(AssemblyNameReference.Parse(name));

            //Adds the node
            node.Children.Add(new AssemblyReferenceTreeNode(AssemblyNameReference.Parse(name), Helpers.Tree.GetAssemblyNode(moduleNode)) { Foreground = GlobalContainer.NewNodesBrush });
            Helpers.Tree.SortChildren((ReferenceFolderTreeNode)node);
        }
开发者ID:95ulisse,项目名称:ILEdit,代码行数:12,代码来源:AssemblyReferenceInjector.cs


示例13: FindMethodFromLocation

		private static MethodDefinition FindMethodFromLocation (IMetadataTokenProvider location)
		{
			ParameterDefinition parameter = (location as ParameterDefinition);
			if (parameter != null)
				return (parameter.Method as MethodDefinition);

			MethodReturnType return_type = (location as MethodReturnType);
			if (return_type != null)
				return (return_type.Method as MethodDefinition);

			return (location as MethodDefinition);
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:12,代码来源:Symbols.cs


示例14: IsIgnored

		// AssemblyDefinition						AttributeTargets.Assembly
		//	ModuleDefinition					AttributeTargets.Module
		//		TypeDefinition					AttributeTargets.Class | Delegate | Enum | Interface | Struct
		//			EventDefinition				AttributeTargets.Event
		//			FieldDefinition				AttributeTargets.Field
		//			GenericParameterDefinition		AttributeTargets.GenericParameter
		//			PropertyDefinition			AttributeTargets.Property
		//			MethodDefinition			AttributeTargets.Constructor | Method
		//				GenericParameterDefinition	AttributeTargets.GenericParameter
		//				ParameterDefinition		AttributeTargets.Parameter
		//				MethodReturnType		AttributeTargets.ReturnValue
		// NamespaceDefinition						special case
		public bool IsIgnored (IRule rule, IMetadataTokenProvider metadata)
		{
			// Note that the Runner tearing_down code may call us with nulls.
			if (metadata == null)
				return false;

			if ((rule == null) || !rule.Active)
				return true;

			HashSet<IMetadataTokenProvider> list;
			if (!ignore.TryGetValue (rule.FullName, out list))
				return false; // nothing is ignored for this rule

			return IsIgnored (list, metadata);
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:27,代码来源:BasicIgnoreList.cs


示例15: Defect

		public Defect (IRule rule, IMetadataTokenProvider target, IMetadataTokenProvider location, Severity severity, Confidence confidence, string text)
		{
			if (rule == null)
				throw new ArgumentNullException ("rule");
			if (target == null)
				throw new ArgumentNullException ("target");
			if (location == null)
				throw new ArgumentNullException ("location");

			Rule = rule;
			Target = target;
			Location = location;
			Confidence = confidence;
			Severity = severity;
			Text = text;
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:16,代码来源:Defect.cs


示例16: FindTypeFromLocation

		private static TypeDefinition FindTypeFromLocation (IMetadataTokenProvider location)
		{
			MethodDefinition method = (location as MethodDefinition);
			if (method != null)
				return (method.DeclaringType as TypeDefinition);

			FieldDefinition field = (location as FieldDefinition);
			if (field != null)
				return (field.DeclaringType as TypeDefinition);

			ParameterDefinition parameter = (location as ParameterDefinition);
			if (parameter != null)
				return FindTypeFromLocation (parameter.Method);

			return (location as TypeDefinition);
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:16,代码来源:Symbols.cs


示例17: Inject

        public void Inject(ICSharpCode.ILSpy.TreeNodes.ILSpyTreeNode node, string name, IMetadataTokenProvider member)
        {
            //Name and namespace
            var typeName = node is ModuleTreeNode ? (name.Substring(name.Contains(".") ? name.LastIndexOf('.') + 1 : 0)) : name;
            var typeNamespace = node is ModuleTreeNode ? (name.Substring(0, name.Contains(".") ? name.LastIndexOf('.') : 0)) : string.Empty;

            //Checks that the typename isn't empty
            if (string.IsNullOrEmpty(typeName))
            {
                MessageBox.Show("Please, specify the name of the type", "Type name required", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            //Creates a new class definition
            var c = new TypeDefinition(
                typeNamespace,
                typeName,
                TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.Sealed
            )
            {
                IsAnsiClass = true,
            };

            //Destination module
            ModuleDefinition module = null;

            //Adds to the node and specifies the base class
            Helpers.Tree.AddTreeNode(node, c,
                m => { module = m; c.BaseType = new TypeReference("System", "Enum", m, m.TypeSystem.Corlib, true); },
                t => { module = t.Module; c.BaseType = new TypeReference("System", "Enum", t.Module, t.Module.TypeSystem.Corlib, true); }
            );

            //Injects the field value___
            c.Fields.Add(new FieldDefinition(
                "value__",
                FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName,
                module.TypeSystem.Int32
            ));
        }
开发者ID:95ulisse,项目名称:ILEdit,代码行数:39,代码来源:EnumInjector.cs


示例18: CheckParameterTypes

		private bool CheckParameterTypes (IMetadataTokenProvider eventType, IMethodSignature invoke)
		{
			bool ok = true;
			if (!invoke.HasParameters)
				return ok;

			IList<ParameterDefinition> pdc = invoke.Parameters;
			if (pdc.Count >= 1) {
				string type_name = pdc [0].ParameterType.FullName;
				if (String.Compare (type_name, "System.Object") != 0) {
					Runner.Report (eventType, Severity.Medium, Confidence.High, String.Format ("The first parameter should have an object, not {0}", type_name));
					ok = false;
				}
			}
			if (pdc.Count >= 2) {
				if (!pdc [1].ParameterType.Inherits ("System.EventArgs")) {
					Runner.Report (eventType, Severity.Medium, Confidence.High, "The second parameter should be a subclass of System.EventArgs");
					ok = false;
				}
			}
			return ok;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:22,代码来源:DeclareEventHandlersCorrectlyRule.cs


示例19: LoadChildren

        /// <summary>
        /// Loads the children
        /// </summary>
        protected override void LoadChildren()
        {
            //Checks if the children must be filled manually
            if (ManuallyFilledChildren)
                return;

            //IEnumerable containing the childrenot the node
            IEnumerable<IMetadataTokenProvider> children = null;

            //Assembly
            if (_tokenProvider is AssemblyDefinition)
                children = ((AssemblyDefinition)_tokenProvider).Modules;
            //Module
            else if (_tokenProvider is ModuleDefinition)
            {
                //Types
                IEnumerable<TypeDefinition> types = ((ModuleDefinition)_tokenProvider).Types;
                if (this.ChildrenFilter != null)
                    types = types.Where(x => this.ChildrenFilter(x));

                //Groups the types by namespace and adds
                foreach (var node in types.GroupBy(x => x.Namespace)
                                     .OrderBy(x => x.Key)
                                     .Select(x =>
                                     {
                                         var n = new NamespaceTreeNode(x.Key);
                                         foreach (var t in x.OrderBy(y => y.Name))
                                             n.Children.Add(new ILEditTreeNode(t, false) { ChildrenFilter = this.ChildrenFilter, Foreground = this.Foreground });
                                         return n;
                                     })) 
                {
                    this.Children.Add(node);
                }

                //Returns
                return;
            }
            //Type
            else if (_tokenProvider is TypeDefinition)
            {
                var type = (TypeDefinition)_tokenProvider;
                children =
                    type.NestedTypes.Cast<IMetadataTokenProvider>()
                    .Concat(type.Fields)
                    .Concat(type.Methods.Where(x => !(x.IsGetter || x.IsSetter || x.IsAddOn || x.IsRemoveOn || x.IsFire)))
                    .Concat(type.Properties)
                    .Concat(type.Events);
            }
            //Property
            else if (_tokenProvider is PropertyDefinition)
            {
                var prop = (PropertyDefinition)_tokenProvider;
                children =
                    new IMetadataTokenProvider[] { prop.GetMethod, prop.SetMethod }
                    .Where(x => x != null)
                    .Concat(prop.HasOtherMethods ? prop.OtherMethods.Cast<IMetadataTokenProvider>() : new IMetadataTokenProvider[] { });
            }
            //Event
            else if (_tokenProvider is EventDefinition)
            {
                var evt = (EventDefinition)_tokenProvider;
                children =
                    new IMetadataTokenProvider[] { evt.AddMethod, evt.RemoveMethod, evt.InvokeMethod }
                    .Where(x => x != null)
                    .Concat(evt.HasOtherMethods ? evt.OtherMethods.Cast<IMetadataTokenProvider>() : new IMetadataTokenProvider[] { });
            }

            //If there are no children returns
            if (children == null)
                return;

            //Applies the filtering
            if (ChildrenFilter != null)
                children = children.Where(x => ChildrenFilter(x));

            //Adds the children
            foreach (var x in children)
                this.Children.Add(new ILEditTreeNode(x, false) { ChildrenFilter = this.ChildrenFilter, Foreground = this.Foreground });
        }
开发者ID:95ulisse,项目名称:ILEdit,代码行数:82,代码来源:ILEditTreeNode.cs


示例20: GetMetadataToken

 private UInt32 GetMetadataToken(
     IMetadataTokenProvider token)
 {
     UInt16 referenceId;
     switch (token.MetadataToken.TokenType)
     {
         case TokenType.TypeRef:
             _context.TypeReferencesTable.TryGetTypeReferenceId((TypeReference)token, out referenceId);
             return (UInt32)0x01000000 | referenceId;
         case TokenType.TypeDef:
             _context.TypeDefinitionTable.TryGetTypeReferenceId((TypeDefinition)token, out referenceId);
             return (UInt32)0x04000000 | referenceId;
         case TokenType.TypeSpec:
             _context.TypeSpecificationsTable.TryGetTypeReferenceId((TypeReference) token, out referenceId);
             return (UInt32)0x08000000 | referenceId;
         case TokenType.Field:
             _context.FieldsTable.TryGetFieldReferenceId((FieldDefinition) token, false, out referenceId);
             return (UInt32)0x05000000 | referenceId;
     }
     return 0U;
 }
开发者ID:Roddoric,项目名称:Monkey.Robotics,代码行数:21,代码来源:CodeWriter.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IMetadataVisitor类代码示例发布时间:2022-05-24
下一篇:
C# IMetadataScope类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap