本文整理汇总了C#中Mono.Cecil.TypeDefinition类的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition类的具体用法?C# TypeDefinition怎么用?C# TypeDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeDefinition类属于Mono.Cecil命名空间,在下文中一共展示了TypeDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SwapParameterTypes
private static void SwapParameterTypes(MethodDefinition method,
TypeDefinition targetDependency,
TypeReference interfaceType,
HashSet<MethodReference> modifiedMethods)
{
if (method.IsAbstract || !method.HasBody)
return;
bool modified = false;
var parameters = method.Parameters.Cast<ParameterDefinition>();
foreach (var parameter in parameters)
{
var parameterType = parameter.ParameterType;
if (parameterType != targetDependency)
continue;
parameter.ParameterType = interfaceType;
modified = true;
}
if (!modified)
return;
modifiedMethods.Add(method);
}
开发者ID:philiplaureano,项目名称:Taiji,代码行数:25,代码来源:SwapEmbeddedMethodTypeReferences.cs
示例2: IsCastTo
private static bool IsCastTo(TypeDefinition castTarget, Instruction instruction)
{
if (instruction.OpCode != OpCodes.Castclass) return false;
TypeReference typeReference = (TypeReference)instruction.Operand;
return typeReference.Resolve() == castTarget;
}
开发者ID:Galigator,项目名称:db4o,代码行数:7,代码来源:StackAnalyzerTestCase.Helper.cs
示例3: CreateDefaultCtor
/// <summary>
/// Create the Ctor
/// </summary>
private static void CreateDefaultCtor(ReachableContext reachableContext, TypeDefinition type)
{
var typeSystem = type.Module.TypeSystem;
var ctor = new MethodDefinition(".ctor", MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, typeSystem.Void);
ctor.DeclaringType = type;
var body = new MethodBody(ctor);
body.InitLocals = true;
ctor.Body = body;
// Prepare code
var seq = new ILSequence();
seq.Emit(OpCodes.Nop);
seq.Emit(OpCodes.Ret);
// Append ret sequence
seq.AppendTo(body);
// Update offsets
body.ComputeOffsets();
// Add ctor
type.Methods.Add(ctor);
ctor.SetReachable(reachableContext);
}
开发者ID:Xtremrules,项目名称:dot42,代码行数:28,代码来源:StructDefaultCtorsAndDefaultField.cs
示例4: TypeWriterBase
public TypeWriterBase(TypeDefinition typeDefinition, int indentCount, TypeCollection typeCollection, ConfigBase config)
{
this.TypeDefinition = typeDefinition;
this.IndentCount = indentCount;
this.TypeCollection = typeCollection;
this.Config = config;
}
开发者ID:sumitkm,项目名称:ToTypeScriptD,代码行数:7,代码来源:TypeWriterBase.cs
示例5: FindReferencesInType
private IEnumerable<AnalyzerTreeNode> FindReferencesInType(TypeDefinition type)
{
foreach (MethodDefinition method in type.Methods) {
bool found = false;
if (!method.HasBody)
continue;
// ignore chained constructors
// (since object is the root of everything, we can short circuit the test in this case)
if (method.Name == ".ctor" &&
(isSystemObject || analyzedType == type || TypesHierarchyHelpers.IsBaseType(analyzedType, type, false)))
continue;
foreach (Instruction instr in method.Body.Instructions) {
MethodReference mr = instr.Operand as MethodReference;
if (mr != null && mr.Name == ".ctor") {
if (Helpers.IsReferencedBy(analyzedType, mr.DeclaringType)) {
found = true;
break;
}
}
}
method.Body = null;
if (found) {
var node = new AnalyzedMethodTreeNode(method);
node.Language = this.Language;
yield return node;
}
}
}
开发者ID:FaceHunter,项目名称:ILSpy,代码行数:32,代码来源:AnalyzedTypeInstantiationsTreeNode.cs
示例6: GetValues
private void GetValues (TypeDefinition type)
{
values.Clear ();
Type ftype = null;
foreach (FieldDefinition field in type.Fields) {
if (field.IsStatic) {
if (ftype == null)
ftype = field.Constant.GetType ();
ulong value;
if (ftype == typeof (ulong)) {
value = (ulong) field.Constant;
if (value != 0 && !values.Contains (value))
values.Add (value);
} else {
long v = Convert.ToInt64 (field.Constant);
if (v > 0) {
value = (ulong) v;
if (!values.Contains (value))
values.Add (value);
} else if (v < 0) {
values.Clear ();
break;
}
}
}
}
}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:32,代码来源:UseFlagsAttributeRule.cs
示例7: ProcessType
private void ProcessType(bool? assemblyConfigureAwaitValue, TypeDefinition type)
{
if (type.IsCompilerGenerated() && type.IsIAsyncStateMachine())
{
return;
}
var configureAwaitValue = (bool?)type.GetConfigureAwaitAttribute()?.ConstructorArguments[0].Value;
configureAwaitValue = configureAwaitValue ?? assemblyConfigureAwaitValue;
foreach (var method in type.Methods)
{
var localConfigureAwaitValue = (bool?)method.GetConfigureAwaitAttribute()?.ConstructorArguments[0].Value;
var localConfigWasSet = localConfigureAwaitValue.HasValue;
localConfigureAwaitValue = localConfigureAwaitValue ?? configureAwaitValue;
if (localConfigureAwaitValue == null)
continue;
var asyncStateMachineType = method.GetAsyncStateMachineType();
if (asyncStateMachineType != null)
{
AddAwaitConfigToAsyncMethod(asyncStateMachineType, localConfigureAwaitValue.Value);
}
else if (localConfigWasSet)
{
LogWarning($"ConfigureAwaitAttribue applied to non-async method '{method.FullName}'.");
continue;
}
}
}
开发者ID:caesay,项目名称:ConfigureAwait,代码行数:30,代码来源:ModuleWeaver.cs
示例8: CheckType
public RuleResult CheckType (TypeDefinition type)
{
// rule applies only to types, interfaces and structures (value types)
if (type.IsEnum || type.IsDelegate () || type.IsGeneratedCode ())
return RuleResult.DoesNotApply;
// rule onyly applies to type that implements IDisposable
if (!type.Implements ("System.IDisposable"))
return RuleResult.DoesNotApply;
// no problem is a finalizer is found
if (type.HasMethod (MethodSignatures.Finalize))
return RuleResult.Success;
// otherwise check for native types
foreach (FieldDefinition field in type.Fields) {
// we can't dispose static fields in IDisposable
if (field.IsStatic)
continue;
if (!field.FieldType.GetElementType ().IsNative ())
continue;
Runner.Report (field, Severity.High, Confidence.High);
}
// special case: a struct cannot define a finalizer so it's a
// bad candidate to hold references to unmanaged resources
if (type.IsValueType && (Runner.CurrentRuleResult == RuleResult.Failure))
Runner.Report (type, Severity.High, Confidence.High, Struct);
return Runner.CurrentRuleResult;
}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:31,代码来源:DisposableTypesShouldHaveFinalizerRule.cs
示例9: VisitType
public void VisitType(TypeDefinition type)
{
Log.DebugLine(this, "-----------------------------------");
Log.DebugLine(this, "{0}", type);
string names = string.Empty;
foreach (PropertyDefinition prop in type.Properties)
{
string name = prop.Name;
MethodDefinition[] methods1 = type.Methods.GetMethod("Get" + name);
MethodDefinition[] methods2 = type.Methods.GetMethod("Set" + name);
if (methods1.Length > 0 && methods1[0].IsPublic)
names += name + " ";
else if (methods2.Length > 0 && methods2[0].IsPublic)
names += name + " ";
}
if (names.Length > 0)
{
Log.DebugLine(this, "names: {0}", names);
Reporter.TypeFailed(type, CheckID, "Properties: " + names);
}
}
开发者ID:dbremner,项目名称:smokey,代码行数:25,代码来源:PropertyMatchesAccessorRule.cs
示例10: CheckType
public MessageCollection CheckType(TypeDefinition type, Runner runner)
{
MessageCollection messageCollection = new MessageCollection();
foreach (MethodDefinition method in type.Methods)
{
if (!method.IsStatic)
{
return null;
}
}
foreach (FieldDefinition field in type.Fields)
{
if (!field.IsStatic)
{
return null;
}
}
foreach (MethodDefinition ctor in type.Constructors)
{
if (!ctor.IsStatic && (ctor.Attributes & MethodAttributes.Public) == MethodAttributes.Public)
{
Location location = new Location(type.Name, ctor.Name, 0);
Message message = new Message(MessageString, location, MessageType.Error);
messageCollection.Add(message);
}
}
return messageCollection.Count > 0 ? messageCollection : null;
}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:33,代码来源:AvoidConstructorsInStaticTypesRule.cs
示例11: OfType
public IEnumerable<TypeReference> OfType(TypeDefinition definition)
{
if (definition == null)
throw new ArgumentNullException("definition");
return definition.Methods.SelectMany(m => OfMethod(m));
}
开发者ID:scaredfinger,项目名称:SharpDependencies,代码行数:7,代码来源:FindTypeReferencesInMethods.cs
示例12: CheckType
public RuleResult CheckType (TypeDefinition type)
{
//type does not apply if not an interface or is an empty interface
if (!type.IsInterface || !type.HasMethods)
return RuleResult.DoesNotApply;
//TODO: take into account [InternalsVisibleTo] on iface's assembly
AssemblyDefinition current_assembly = type.Module.Assembly;
if (type.IsVisible ()) {
// We should not, by default, promote the implementation of interfaces in assemblies that
// do not, already, refer to the current one because:
// (a) we could be suggesting circular references (solvable, or not, by refactoring)
// (b) it has a very HIGH performance cost, with verry LITTLE value (in # of defects)
string current_assembly_name = current_assembly.Name.Name;
foreach (AssemblyDefinition assembly in Runner.Assemblies) {
// by default only process assemblies (from the set) that refers to the current one
// or the current one itself
if (!ReferencesOnly || (current_assembly_name == assembly.Name.Name) ||
assembly.References (current_assembly_name)) {
CheckAssemblyTypes (assembly, type);
}
}
} else {
// if the interface is not visible then we only check this assembly
CheckAssemblyTypes (current_assembly, type);
}
return Runner.CurrentRuleResult;
}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:29,代码来源:ConsiderAddingInterfaceRule.cs
示例13: addMainMethod
public MethodDefinition addMainMethod(TypeDefinition tdTargetType)
{
MethodDefinition mainMethod = createMethod_StaticVoid("Main");
tdTargetType.Methods.Add(mainMethod);
assemblyDefinition.EntryPoint = mainMethod;
return mainMethod;
}
开发者ID:o2platform,项目名称:O2.Platform.Projects.Misc_and_Legacy,代码行数:7,代码来源:CecilAssemblyBuilder.cs
示例14: addType
public TypeDefinition addType(String sTypeNameSpace, String sTypeName, TypeAttributes taTypeAttributes,
TypeReference trTypeReference)
{
var tdNewType = new TypeDefinition(sTypeName, sTypeNameSpace, taTypeAttributes, trTypeReference);
mainModule.Types.Add(tdNewType);
return tdNewType;
}
开发者ID:o2platform,项目名称:O2.Platform.Projects.Misc_and_Legacy,代码行数:7,代码来源:CecilAssemblyBuilder.cs
示例15: GetInjecteeCecilType
internal virtual TypeDefinition GetInjecteeCecilType(ModuleDefinition module)
{
if (_injecteeCecilDef == null)
_injecteeCecilDef = module.FindMatchingType(InjecteeType, true);
return _injecteeCecilDef;
}
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:7,代码来源:TypeInjecteeBase.cs
示例16: AddGetServiceHashMethodTo
/// <summary>
/// Adds a GetServiceHashCode method to a target type.
/// </summary>
/// <param name="targetType">The target type.</param>
/// <param name="shouldBeVisible">A boolean flag that indicates whether or not the method should be public.</param>
/// <returns>The GetServiceHashCode method.</returns>
public MethodDefinition AddGetServiceHashMethodTo(TypeDefinition targetType, bool shouldBeVisible)
{
var options = new MethodBuilderOptions();
DefineOptions(targetType, shouldBeVisible, options);
var module = targetType.Module;
var methodBuilder = new MethodBuilder();
var method = methodBuilder.CreateMethod(options);
var body = method.Body;
var il = body.GetILProcessor ();
var getHashCodeMethod = module.ImportMethod<object>("GetHashCode");
var hashVariable = EmitGetServiceTypeHashCode(module, body, il, getHashCodeMethod);
// Calculate the hash code for the service name
// if it isn't null
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldnull);
il.Emit(OpCodes.Ceq);
var skipNameHash = il.Create(OpCodes.Nop);
il.Emit(OpCodes.Brtrue, skipNameHash);
EmitGetServiceNameHashCode(il, getHashCodeMethod, hashVariable);
il.Append(skipNameHash);
il.Emit(OpCodes.Ldloc, hashVariable);
il.Emit(OpCodes.Ret);
return method;
}
开发者ID:unintelligible,项目名称:Hiro,代码行数:40,代码来源:ServiceHashEmitter.cs
示例17: CheckType
public RuleResult CheckType (TypeDefinition type)
{
//does rule apply?
if (type.IsEnum || type.IsInterface || type.IsAbstract || type.IsDelegate () || type.IsGeneratedCode ())
return RuleResult.DoesNotApply;
if (!type.HasFields || (type.Fields.Count < MinimumFieldCount))
return RuleResult.DoesNotApply;
if (!type.HasMethods || (type.Methods.Count < MinimumMethodCount))
return RuleResult.DoesNotApply;
//yay! rule do apply!
double coh = GetCohesivenessForType (type);
if (coh >= SuccessLowerLimit)
return RuleResult.Success;
if (0 == coh)
return RuleResult.DoesNotApply;
//how's severity?
Severity sev = GetCohesivenessSeverity(coh);
string msg = String.Format (CultureInfo.CurrentCulture, "Type cohesiveness : {0}%", (int) (coh * 100));
Runner.Report (type, sev, Confidence.Normal, msg);
return RuleResult.Failure;
}
开发者ID:col42dev,项目名称:mono-tools,代码行数:25,代码来源:AvoidLackOfCohesionOfMethodsRule.cs
示例18: CreateUsage
private MethodUsage CreateUsage(MemberReference operand, ModuleDefinition assembly, TypeDefinition type, MethodDefinition method, string testAssemblyPath)
{
if (operand == null)
return null;
Test test = new Test
{
PathToAssembly = Path.GetDirectoryName(testAssemblyPath),
AssemblyName = assembly.Assembly.Name.Name,
NamespaceName = type.Namespace,
ClassName = type.Name,
MethodName = method.Name
};
var instructionCall = new MethodUsage
{
AssemblyName = operand.DeclaringType.Scope.Name + ".dll",
NamespaceName = operand.DeclaringType.Namespace,
ClassName = operand.DeclaringType.Name,
MethodName = operand.Name,
TestCoverage = new List<Test> {test}
};
return instructionCall;
}
开发者ID:BenHall,项目名称:Seacrest,代码行数:25,代码来源:TestFinder.cs
示例19: FindReferencesInType
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{
if (analyzedType.IsEnum && type == analyzedType)
yield break;
if (!this.Language.ShowMember(type))
yield break;
foreach (FieldDefinition field in type.Fields) {
if (TypeIsExposedBy(field))
yield return new AnalyzedFieldTreeNode(field);
}
foreach (PropertyDefinition property in type.Properties) {
if (TypeIsExposedBy(property))
yield return new AnalyzedPropertyTreeNode(property);
}
foreach (EventDefinition eventDef in type.Events) {
if (TypeIsExposedBy(eventDef))
yield return new AnalyzedEventTreeNode(eventDef);
}
foreach (MethodDefinition method in type.Methods) {
if (TypeIsExposedBy(method))
yield return new AnalyzedMethodTreeNode(method);
}
}
开发者ID:keremkusmezer,项目名称:ILSpy,代码行数:28,代码来源:AnalyzedTypeExposedByTreeNode.cs
示例20: DerivedTypesTreeNode
public DerivedTypesTreeNode(AssemblyList list, TypeDefinition type)
{
this.list = list;
this.type = type;
this.LazyLoading = true;
this.threading = new ThreadingSupport();
}
开发者ID:arturek,项目名称:ILSpy,代码行数:7,代码来源:DerivedTypesTreeNode.cs
注:本文中的Mono.Cecil.TypeDefinition类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论