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


C# TypeDefinition.HasInterface方法代码示例

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


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

示例1: WeaveTypeProperties

        protected void WeaveTypeProperties(TypeDefinition type)
        {
            var properties = type.Properties.Where(
                p => p.CustomAttributes.Any(
                    a => a.AttributeType.FullName == typeof (PropertyAttribute).FullName));

            if(!properties.Any())
                return;

            if(!type.HasInterface(typeof(IPropertyNotifier).FullName))
                throw new Exception(string.Format("Type {0} has properties but does not implement {1}", type.FullName, typeof(IPropertyNotifier).FullName));

            Console.WriteLine(type.FullName);

            var weaver = new TypeWeaver(originType, type);

            foreach(var property in properties)
            {

                weaver.NamePrefix = "<$" + property.Name + "$>";

                var desNotifierMethod =  type.GetMethod(tNotifierMethod.Name);

                weaver.Map(tNotifierMethod, desNotifierMethod);

                var propField = weaver.AddDefinition(tPropertyField);
                propField.FieldType = property.PropertyType;

                weaver.AddConstant(tPropertyNameC,property.Name);

                //TODO delete property generated field
                weaver.Merge(tPropertyProperty, property);

                weaver.ProcessInstructions();
            }
        }
开发者ID:tritao,项目名称:flood,代码行数:36,代码来源:NotifierWeaver.cs

示例2: EnsureTypeImplementsIDisposable

        /// <summary>
        /// Method verifies that the type implements IDisposable and emits
        /// IL to implement it if necessary.
        /// </summary>
        /// <param name="type">The type that needs to be checked and potentially modified.</param>
        private void EnsureTypeImplementsIDisposable(TypeDefinition type)
        {
            // Verify whether the class already implements IDisposable. If not then
             // implement it.
             if (!type.HasInterface("System.IDisposable"))
             {
            type.Interfaces.Add(type.Module.ImportReference(typeof(IDisposable)));

            // Verify whether the type already has a public Dipose method. If not then add a shell.
            if (!type.HasDisposeMethod())
            {
               var disposeMethodAttribs =
                  Mono.Cecil.MethodAttributes.Public |
                  Mono.Cecil.MethodAttributes.Final |
                  Mono.Cecil.MethodAttributes.HideBySig |
                  Mono.Cecil.MethodAttributes.NewSlot |
                  Mono.Cecil.MethodAttributes.Virtual;

               var disposeDefinition =
                  new MethodDefinition("Dispose", disposeMethodAttribs, ModuleDefinition.TypeSystem.Void);

               // Empty method shell that only returns void.
               disposeDefinition.Body.Instructions.Add(Instruction.Create(OpCodes.Nop));
               disposeDefinition.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));

               type.Methods.Add(disposeDefinition);
            }
             }
        }
开发者ID:DbTestMonkey,项目名称:DbTestMonkey,代码行数:34,代码来源:ModuleWeaver.cs


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