本文整理汇总了C#中IMetadataTokenProvider类的典型用法代码示例。如果您正苦于以下问题:C# IMetadataTokenProvider类的具体用法?C# IMetadataTokenProvider怎么用?C# IMetadataTokenProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMetadataTokenProvider类属于命名空间,在下文中一共展示了IMetadataTokenProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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);
}
示例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;
}
}
}
}
示例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);
}
示例5: ProcessProvider
void ProcessProvider (IMetadataTokenProvider provider)
{
if (!TunerAnnotations.IsInternalized (Context, provider))
return;
Console.WriteLine ("[internalized] {0}", provider);
}
示例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;
}
示例7: Mark
void Mark (IMetadataTokenProvider provider, CustomAttribute preserve_attribute)
{
if (IsConditionalAttribute (preserve_attribute)) {
PreserveConditional (provider);
return;
}
PreserveUnconditional (provider);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}