Add StickGame Assets

This commit is contained in:
Dzejkobik007
2024-03-24 22:21:16 +01:00
parent 5a5812c0c7
commit 6c8b523d1f
6643 changed files with 596260 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
using System.Text;
using System.Threading;
using MD = MonoFN.Cecil.Metadata;
namespace MonoFN.Cecil {
public struct ArrayDimension {
int? lower_bound;
int? upper_bound;
public int? LowerBound {
get { return lower_bound; }
set { lower_bound = value; }
}
public int? UpperBound {
get { return upper_bound; }
set { upper_bound = value; }
}
public bool IsSized {
get { return lower_bound.HasValue || upper_bound.HasValue; }
}
public ArrayDimension (int? lowerBound, int? upperBound)
{
this.lower_bound = lowerBound;
this.upper_bound = upperBound;
}
public override string ToString ()
{
return !IsSized
? string.Empty
: lower_bound + "..." + upper_bound;
}
}
public sealed class ArrayType : TypeSpecification {
Collection<ArrayDimension> dimensions;
public Collection<ArrayDimension> Dimensions {
get {
if (dimensions != null)
return dimensions;
var empty_dimensions = new Collection<ArrayDimension> ();
empty_dimensions.Add (new ArrayDimension ());
Interlocked.CompareExchange (ref dimensions, empty_dimensions, null);
return dimensions;
}
}
public int Rank {
get { return dimensions == null ? 1 : dimensions.Count; }
}
public bool IsVector {
get {
if (dimensions == null)
return true;
if (dimensions.Count > 1)
return false;
var dimension = dimensions [0];
return !dimension.IsSized;
}
}
public override bool IsValueType {
get { return false; }
set { throw new InvalidOperationException (); }
}
public override string Name {
get { return base.Name + Suffix; }
}
public override string FullName {
get { return base.FullName + Suffix; }
}
string Suffix {
get {
if (IsVector)
return "[]";
var suffix = new StringBuilder ();
suffix.Append ("[");
for (int i = 0; i < dimensions.Count; i++) {
if (i > 0)
suffix.Append (",");
suffix.Append (dimensions [i].ToString ());
}
suffix.Append ("]");
return suffix.ToString ();
}
}
public override bool IsArray {
get { return true; }
}
public ArrayType (TypeReference type)
: base (type)
{
Mixin.CheckType (type);
this.etype = MD.ElementType.Array;
}
public ArrayType (TypeReference type, int rank)
: this (type)
{
Mixin.CheckType (type);
if (rank == 1)
return;
dimensions = new Collection<ArrayDimension> (rank);
for (int i = 0; i < rank; i++)
dimensions.Add (new ArrayDimension ());
this.etype = MD.ElementType.Array;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7add098db82a032428c139b59f0878be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,189 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
using System.IO;
using System.Threading;
namespace MonoFN.Cecil {
public sealed class AssemblyDefinition : ICustomAttributeProvider, ISecurityDeclarationProvider, IDisposable {
AssemblyNameDefinition name;
internal ModuleDefinition main_module;
Collection<ModuleDefinition> modules;
Collection<CustomAttribute> custom_attributes;
Collection<SecurityDeclaration> security_declarations;
public AssemblyNameDefinition Name {
get { return name; }
set { name = value; }
}
public string FullName {
get { return name != null ? name.FullName : string.Empty; }
}
public MetadataToken MetadataToken {
get { return new MetadataToken (TokenType.Assembly, 1); }
set { }
}
public Collection<ModuleDefinition> Modules {
get {
if (modules != null)
return modules;
if (main_module.HasImage)
return main_module.Read (ref modules, this, (_, reader) => reader.ReadModules ());
Interlocked.CompareExchange (ref modules, new Collection<ModuleDefinition> (1) { main_module }, null);
return modules;
}
}
public ModuleDefinition MainModule {
get { return main_module; }
}
public MethodDefinition EntryPoint {
get { return main_module.EntryPoint; }
set { main_module.EntryPoint = value; }
}
public bool HasCustomAttributes {
get {
if (custom_attributes != null)
return custom_attributes.Count > 0;
return this.GetHasCustomAttributes (main_module);
}
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, main_module)); }
}
public bool HasSecurityDeclarations {
get {
if (security_declarations != null)
return security_declarations.Count > 0;
return this.GetHasSecurityDeclarations (main_module);
}
}
public Collection<SecurityDeclaration> SecurityDeclarations {
get { return security_declarations ?? (this.GetSecurityDeclarations (ref security_declarations, main_module)); }
}
internal AssemblyDefinition ()
{
}
public void Dispose ()
{
if (this.modules == null) {
main_module.Dispose ();
return;
}
var modules = this.Modules;
for (int i = 0; i < modules.Count; i++)
modules [i].Dispose ();
}
public static AssemblyDefinition CreateAssembly (AssemblyNameDefinition assemblyName, string moduleName, ModuleKind kind)
{
return CreateAssembly (assemblyName, moduleName, new ModuleParameters { Kind = kind });
}
public static AssemblyDefinition CreateAssembly (AssemblyNameDefinition assemblyName, string moduleName, ModuleParameters parameters)
{
if (assemblyName == null)
throw new ArgumentNullException ("assemblyName");
if (moduleName == null)
throw new ArgumentNullException ("moduleName");
Mixin.CheckParameters (parameters);
if (parameters.Kind == ModuleKind.NetModule)
throw new ArgumentException ("kind");
var assembly = ModuleDefinition.CreateModule (moduleName, parameters).Assembly;
assembly.Name = assemblyName;
return assembly;
}
public static AssemblyDefinition ReadAssembly (string fileName)
{
return ReadAssembly (ModuleDefinition.ReadModule (fileName));
}
public static AssemblyDefinition ReadAssembly (string fileName, ReaderParameters parameters)
{
return ReadAssembly (ModuleDefinition.ReadModule (fileName, parameters));
}
public static AssemblyDefinition ReadAssembly (Stream stream)
{
return ReadAssembly (ModuleDefinition.ReadModule (stream));
}
public static AssemblyDefinition ReadAssembly (Stream stream, ReaderParameters parameters)
{
return ReadAssembly (ModuleDefinition.ReadModule (stream, parameters));
}
static AssemblyDefinition ReadAssembly (ModuleDefinition module)
{
var assembly = module.Assembly;
if (assembly == null)
throw new ArgumentException ();
return assembly;
}
public void Write (string fileName)
{
Write (fileName, new WriterParameters ());
}
public void Write (string fileName, WriterParameters parameters)
{
main_module.Write (fileName, parameters);
}
public void Write ()
{
main_module.Write ();
}
public void Write (WriterParameters parameters)
{
main_module.Write (parameters);
}
public void Write (Stream stream)
{
Write (stream, new WriterParameters ());
}
public void Write (Stream stream, WriterParameters parameters)
{
main_module.Write (stream, parameters);
}
public override string ToString ()
{
return this.FullName;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1c1ac0fc48f2d424f9c0d9fa74b16b07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
[Flags]
public enum AssemblyAttributes : uint {
PublicKey = 0x0001,
SideBySideCompatible = 0x0000,
Retargetable = 0x0100,
WindowsRuntime = 0x0200,
DisableJITCompileOptimizer = 0x4000,
EnableJITCompileTracking = 0x8000,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 257c8151138cda34dafbe0ca56ebedf4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public enum AssemblyHashAlgorithm : uint {
None = 0x0000,
MD5 = 0x8003,
SHA1 = 0x8004,
SHA256 = 0x800C,
SHA384 = 0x800D,
SHA512 = 0x800E,
Reserved = 0x8003, // MD5
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b200bdec09584af41bd3f656e091cccf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Cecil;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle (Consts.AssemblyName)]
[assembly: Guid ("fd225bb4-fa53-44b2-a6db-85f5e48dcb54")]
[assembly: InternalsVisibleTo ("MonoFN.Cecil.Tests, PublicKey=" + Consts.PublicKey)]
[assembly: InternalsVisibleTo ("MonoFN.Cecil.Pdb, PublicKey=" + Consts.PublicKey)]
[assembly: InternalsVisibleTo ("MonoFN.Cecil.Mdb, PublicKey=" + Consts.PublicKey)]
[assembly: InternalsVisibleTo ("MonoFN.Cecil.Rocks, PublicKey=" + Consts.PublicKey)]

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ff23d7231ddfa574b816532360874834
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,37 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public sealed class AssemblyLinkedResource : Resource {
AssemblyNameReference reference;
public AssemblyNameReference Assembly {
get { return reference; }
set { reference = value; }
}
public override ResourceType ResourceType {
get { return ResourceType.AssemblyLinked; }
}
public AssemblyLinkedResource (string name, ManifestResourceAttributes flags)
: base (name, flags)
{
}
public AssemblyLinkedResource (string name, ManifestResourceAttributes flags, AssemblyNameReference reference)
: base (name, flags)
{
this.reference = reference;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c3d5a207fc55ac5419e42c86cef15db0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
public sealed class AssemblyNameDefinition : AssemblyNameReference {
public override byte [] Hash {
get { return Empty<byte>.Array; }
}
internal AssemblyNameDefinition ()
{
this.token = new MetadataToken (TokenType.Assembly, 1);
}
public AssemblyNameDefinition (string name, Version version)
: base (name, version)
{
this.token = new MetadataToken (TokenType.Assembly, 1);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 68b90f4f023a67e4db7ddb52802ca21e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,269 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
namespace MonoFN.Cecil {
public class AssemblyNameReference : IMetadataScope {
string name;
string culture;
Version version;
uint attributes;
byte [] public_key;
byte [] public_key_token;
AssemblyHashAlgorithm hash_algorithm;
byte [] hash;
internal MetadataToken token;
string full_name;
public string Name {
get { return name; }
set {
name = value;
full_name = null;
}
}
public string Culture {
get { return culture; }
set {
culture = value;
full_name = null;
}
}
public Version Version {
get { return version; }
set {
version = Mixin.CheckVersion (value);
full_name = null;
}
}
public AssemblyAttributes Attributes {
get { return (AssemblyAttributes)attributes; }
set { attributes = (uint)value; }
}
public bool HasPublicKey {
get { return attributes.GetAttributes ((uint)AssemblyAttributes.PublicKey); }
set { attributes = attributes.SetAttributes ((uint)AssemblyAttributes.PublicKey, value); }
}
public bool IsSideBySideCompatible {
get { return attributes.GetAttributes ((uint)AssemblyAttributes.SideBySideCompatible); }
set { attributes = attributes.SetAttributes ((uint)AssemblyAttributes.SideBySideCompatible, value); }
}
public bool IsRetargetable {
get { return attributes.GetAttributes ((uint)AssemblyAttributes.Retargetable); }
set { attributes = attributes.SetAttributes ((uint)AssemblyAttributes.Retargetable, value); }
}
public bool IsWindowsRuntime {
get { return attributes.GetAttributes ((uint)AssemblyAttributes.WindowsRuntime); }
set { attributes = attributes.SetAttributes ((uint)AssemblyAttributes.WindowsRuntime, value); }
}
public byte [] PublicKey {
get { return public_key ?? Empty<byte>.Array; }
set {
public_key = value;
HasPublicKey = !public_key.IsNullOrEmpty ();
public_key_token = null;
full_name = null;
}
}
public byte [] PublicKeyToken {
get {
if (public_key_token == null && !public_key.IsNullOrEmpty ()) {
var hash = HashPublicKey ();
// we need the last 8 bytes in reverse order
var local_public_key_token = new byte [8];
Array.Copy (hash, (hash.Length - 8), local_public_key_token, 0, 8);
Array.Reverse (local_public_key_token, 0, 8);
Interlocked.CompareExchange (ref public_key_token, local_public_key_token, null); // publish only once finished (required for thread-safety)
}
return public_key_token ?? Empty<byte>.Array;
}
set {
public_key_token = value;
full_name = null;
}
}
byte [] HashPublicKey ()
{
HashAlgorithm algorithm;
switch (hash_algorithm) {
case AssemblyHashAlgorithm.Reserved:
algorithm = MD5.Create ();
break;
default:
// None default to SHA1
algorithm = SHA1.Create ();
break;
}
using (algorithm)
return algorithm.ComputeHash (public_key);
}
public virtual MetadataScopeType MetadataScopeType {
get { return MetadataScopeType.AssemblyNameReference; }
}
public string FullName {
get {
if (full_name != null)
return full_name;
const string sep = ", ";
var builder = new StringBuilder ();
builder.Append (name);
builder.Append (sep);
builder.Append ("Version=");
builder.Append (version.ToString (fieldCount: 4));
builder.Append (sep);
builder.Append ("Culture=");
builder.Append (string.IsNullOrEmpty (culture) ? "neutral" : culture);
builder.Append (sep);
builder.Append ("PublicKeyToken=");
var pk_token = PublicKeyToken;
if (!pk_token.IsNullOrEmpty () && pk_token.Length > 0) {
for (int i = 0; i < pk_token.Length; i++) {
builder.Append (pk_token [i].ToString ("x2"));
}
} else
builder.Append ("null");
if (IsRetargetable) {
builder.Append (sep);
builder.Append ("Retargetable=Yes");
}
Interlocked.CompareExchange (ref full_name, builder.ToString (), null);
return full_name;
}
}
public static AssemblyNameReference Parse (string fullName)
{
if (fullName == null)
throw new ArgumentNullException ("fullName");
if (fullName.Length == 0)
throw new ArgumentException ("Name can not be empty");
var name = new AssemblyNameReference ();
var tokens = fullName.Split (',');
for (int i = 0; i < tokens.Length; i++) {
var token = tokens [i].Trim ();
if (i == 0) {
name.Name = token;
continue;
}
var parts = token.Split ('=');
if (parts.Length != 2)
throw new ArgumentException ("Malformed name");
switch (parts [0].ToLowerInvariant ()) {
case "version":
name.Version = new Version (parts [1]);
break;
case "culture":
name.Culture = parts [1] == "neutral" ? "" : parts [1];
break;
case "publickeytoken":
var pk_token = parts [1];
if (pk_token == "null")
break;
name.PublicKeyToken = new byte [pk_token.Length / 2];
for (int j = 0; j < name.PublicKeyToken.Length; j++)
name.PublicKeyToken [j] = Byte.Parse (pk_token.Substring (j * 2, 2), NumberStyles.HexNumber);
break;
}
}
return name;
}
public AssemblyHashAlgorithm HashAlgorithm {
get { return hash_algorithm; }
set { hash_algorithm = value; }
}
public virtual byte [] Hash {
get { return hash; }
set { hash = value; }
}
public MetadataToken MetadataToken {
get { return token; }
set { token = value; }
}
internal AssemblyNameReference ()
{
this.version = Mixin.ZeroVersion;
this.token = new MetadataToken (TokenType.AssemblyRef);
}
public AssemblyNameReference (string name, Version version)
{
Mixin.CheckName (name);
this.name = name;
this.version = Mixin.CheckVersion (version);
this.hash_algorithm = AssemblyHashAlgorithm.None;
this.token = new MetadataToken (TokenType.AssemblyRef);
}
public override string ToString ()
{
return this.FullName;
}
}
partial class Mixin {
public static Version ZeroVersion = new Version (0, 0, 0, 0);
public static Version CheckVersion (Version version)
{
if (version == null)
return ZeroVersion;
if (version.Build == -1)
return new Version (version.Major, version.Minor, 0, 0);
if (version.Revision == -1)
return new Version (version.Major, version.Minor, version.Build, 0);
return version;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fdaf7563058f3f54ba3e6b32c888eb3c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d8fb74d16029713429e831cb3b5b0861
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a88ce645df13da4aa9eca43f013f6ae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,406 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace MonoFN.Cecil {
public delegate AssemblyDefinition AssemblyResolveEventHandler (object sender, AssemblyNameReference reference);
public sealed class AssemblyResolveEventArgs : EventArgs {
readonly AssemblyNameReference reference;
public AssemblyNameReference AssemblyReference {
get { return reference; }
}
public AssemblyResolveEventArgs (AssemblyNameReference reference)
{
this.reference = reference;
}
}
#if !NET_CORE
[Serializable]
#endif
public sealed class AssemblyResolutionException : FileNotFoundException {
readonly AssemblyNameReference reference;
public AssemblyNameReference AssemblyReference {
get { return reference; }
}
public AssemblyResolutionException (AssemblyNameReference reference)
: this (reference, null)
{
}
public AssemblyResolutionException (AssemblyNameReference reference, Exception innerException)
: base (string.Format ("Failed to resolve assembly: '{0}'", reference), innerException)
{
this.reference = reference;
}
#if !NET_CORE
AssemblyResolutionException (
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base (info, context)
{
}
#endif
}
public abstract class BaseAssemblyResolver : IAssemblyResolver {
static readonly bool on_mono = Type.GetType ("MonoFN.Runtime") != null;
readonly Collection<string> directories;
#if NET_CORE
// Maps file names of available trusted platform assemblies to their full paths.
// Internal for testing.
internal static readonly Lazy<Dictionary<string, string>> TrustedPlatformAssemblies = new Lazy<Dictionary<string, string>> (CreateTrustedPlatformAssemblyMap);
#else
Collection<string> gac_paths;
#endif
public void AddSearchDirectory (string directory)
{
directories.Add (directory);
}
public void RemoveSearchDirectory (string directory)
{
directories.Remove (directory);
}
public string [] GetSearchDirectories ()
{
var directories = new string [this.directories.size];
Array.Copy (this.directories.items, directories, directories.Length);
return directories;
}
public event AssemblyResolveEventHandler ResolveFailure;
protected BaseAssemblyResolver ()
{
directories = new Collection<string> (2) { ".", "bin" };
}
AssemblyDefinition GetAssembly (string file, ReaderParameters parameters)
{
if (parameters.AssemblyResolver == null)
parameters.AssemblyResolver = this;
return ModuleDefinition.ReadModule (file, parameters).Assembly;
}
public virtual AssemblyDefinition Resolve (AssemblyNameReference name)
{
return Resolve (name, new ReaderParameters ());
}
public virtual AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters)
{
Mixin.CheckName (name);
Mixin.CheckParameters (parameters);
var assembly = SearchDirectory (name, directories, parameters);
if (assembly != null)
return assembly;
if (name.IsRetargetable) {
// if the reference is retargetable, zero it
name = new AssemblyNameReference (name.Name, Mixin.ZeroVersion) {
PublicKeyToken = Empty<byte>.Array,
};
}
#if NET_CORE
assembly = SearchTrustedPlatformAssemblies (name, parameters);
if (assembly != null)
return assembly;
#else
var framework_dir = Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName);
var framework_dirs = on_mono
? new [] { framework_dir, Path.Combine (framework_dir, "Facades") }
: new [] { framework_dir };
if (IsZero (name.Version)) {
assembly = SearchDirectory (name, framework_dirs, parameters);
if (assembly != null)
return assembly;
}
if (name.Name == "mscorlib") {
assembly = GetCorlib (name, parameters);
if (assembly != null)
return assembly;
}
assembly = GetAssemblyInGac (name, parameters);
if (assembly != null)
return assembly;
assembly = SearchDirectory (name, framework_dirs, parameters);
if (assembly != null)
return assembly;
#endif
if (ResolveFailure != null) {
assembly = ResolveFailure (this, name);
if (assembly != null)
return assembly;
}
throw new AssemblyResolutionException (name);
}
#if NET_CORE
AssemblyDefinition SearchTrustedPlatformAssemblies (AssemblyNameReference name, ReaderParameters parameters)
{
if (name.IsWindowsRuntime)
return null;
if (TrustedPlatformAssemblies.Value.TryGetValue (name.Name, out string path))
return GetAssembly (path, parameters);
return null;
}
static Dictionary<string, string> CreateTrustedPlatformAssemblyMap ()
{
var result = new Dictionary<string, string> (StringComparer.OrdinalIgnoreCase);
string paths;
try {
paths = (string) AppDomain.CurrentDomain.GetData ("TRUSTED_PLATFORM_ASSEMBLIES");
} catch {
paths = null;
}
if (paths == null)
return result;
foreach (var path in paths.Split (Path.PathSeparator))
if (string.Equals (Path.GetExtension (path), ".dll", StringComparison.OrdinalIgnoreCase))
result [Path.GetFileNameWithoutExtension (path)] = path;
return result;
}
#endif
protected virtual AssemblyDefinition SearchDirectory (AssemblyNameReference name, IEnumerable<string> directories, ReaderParameters parameters)
{
var extensions = name.IsWindowsRuntime ? new [] { ".winmd", ".dll" } : new [] { ".exe", ".dll" };
foreach (var directory in directories) {
foreach (var extension in extensions) {
string file = Path.Combine (directory, name.Name + extension);
if (!File.Exists (file))
continue;
try {
return GetAssembly (file, parameters);
}
catch (System.BadImageFormatException) {
continue;
}
}
}
return null;
}
static bool IsZero (Version version)
{
return version.Major == 0 && version.Minor == 0 && version.Build == 0 && version.Revision == 0;
}
#if !NET_CORE
AssemblyDefinition GetCorlib (AssemblyNameReference reference, ReaderParameters parameters)
{
var version = reference.Version;
var corlib = typeof (object).Assembly.GetName ();
if (corlib.Version == version || IsZero (version))
return GetAssembly (typeof (object).Module.FullyQualifiedName, parameters);
var path = Directory.GetParent (
Directory.GetParent (
typeof (object).Module.FullyQualifiedName).FullName
).FullName;
if (on_mono) {
if (version.Major == 1)
path = Path.Combine (path, "1.0");
else if (version.Major == 2) {
if (version.MajorRevision == 5)
path = Path.Combine (path, "2.1");
else
path = Path.Combine (path, "2.0");
} else if (version.Major == 4)
path = Path.Combine (path, "4.0");
else
throw new NotSupportedException ("Version not supported: " + version);
} else {
switch (version.Major) {
case 1:
if (version.MajorRevision == 3300)
path = Path.Combine (path, "v1.0.3705");
else
path = Path.Combine (path, "v1.1.4322");
break;
case 2:
path = Path.Combine (path, "v2.0.50727");
break;
case 4:
path = Path.Combine (path, "v4.0.30319");
break;
default:
throw new NotSupportedException ("Version not supported: " + version);
}
}
var file = Path.Combine (path, "mscorlib.dll");
if (File.Exists (file))
return GetAssembly (file, parameters);
if (on_mono && Directory.Exists (path + "-api")) {
file = Path.Combine (path + "-api", "mscorlib.dll");
if (File.Exists (file))
return GetAssembly (file, parameters);
}
return null;
}
static Collection<string> GetGacPaths ()
{
if (on_mono)
return GetDefaultMonoGacPaths ();
var paths = new Collection<string> (2);
var windir = Environment.GetEnvironmentVariable ("WINDIR");
if (windir == null)
return paths;
paths.Add (Path.Combine (windir, "assembly"));
paths.Add (Path.Combine (windir, Path.Combine ("Microsoft.NET", "assembly")));
return paths;
}
static Collection<string> GetDefaultMonoGacPaths ()
{
var paths = new Collection<string> (1);
var gac = GetCurrentMonoGac ();
if (gac != null)
paths.Add (gac);
var gac_paths_env = Environment.GetEnvironmentVariable ("MONO_GAC_PREFIX");
if (string.IsNullOrEmpty (gac_paths_env))
return paths;
var prefixes = gac_paths_env.Split (Path.PathSeparator);
foreach (var prefix in prefixes) {
if (string.IsNullOrEmpty (prefix))
continue;
var gac_path = Path.Combine (Path.Combine (Path.Combine (prefix, "lib"), "mono"), "gac");
if (Directory.Exists (gac_path) && !paths.Contains (gac))
paths.Add (gac_path);
}
return paths;
}
static string GetCurrentMonoGac ()
{
return Path.Combine (
Directory.GetParent (
Path.GetDirectoryName (typeof (object).Module.FullyQualifiedName)).FullName,
"gac");
}
AssemblyDefinition GetAssemblyInGac (AssemblyNameReference reference, ReaderParameters parameters)
{
if (reference.PublicKeyToken == null || reference.PublicKeyToken.Length == 0)
return null;
if (gac_paths == null)
gac_paths = GetGacPaths ();
if (on_mono)
return GetAssemblyInMonoGac (reference, parameters);
return GetAssemblyInNetGac (reference, parameters);
}
AssemblyDefinition GetAssemblyInMonoGac (AssemblyNameReference reference, ReaderParameters parameters)
{
for (int i = 0; i < gac_paths.Count; i++) {
var gac_path = gac_paths [i];
var file = GetAssemblyFile (reference, string.Empty, gac_path);
if (File.Exists (file))
return GetAssembly (file, parameters);
}
return null;
}
AssemblyDefinition GetAssemblyInNetGac (AssemblyNameReference reference, ReaderParameters parameters)
{
var gacs = new [] { "GAC_MSIL", "GAC_32", "GAC_64", "GAC" };
var prefixes = new [] { string.Empty, "v4.0_" };
for (int i = 0; i < gac_paths.Count; i++) {
for (int j = 0; j < gacs.Length; j++) {
var gac = Path.Combine (gac_paths [i], gacs [j]);
var file = GetAssemblyFile (reference, prefixes [i], gac);
if (Directory.Exists (gac) && File.Exists (file))
return GetAssembly (file, parameters);
}
}
return null;
}
static string GetAssemblyFile (AssemblyNameReference reference, string prefix, string gac)
{
var gac_folder = new StringBuilder ()
.Append (prefix)
.Append (reference.Version)
.Append ("__");
for (int i = 0; i < reference.PublicKeyToken.Length; i++)
gac_folder.Append (reference.PublicKeyToken [i].ToString ("x2"));
return Path.Combine (
Path.Combine (
Path.Combine (gac, reference.Name), gac_folder.ToString ()),
reference.Name + ".dll");
}
#endif
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ab1d53794ef7444c81e276b5a3a5c2b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,105 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
using System.Text;
namespace MonoFN.Cecil {
public sealed class CallSite : IMethodSignature {
readonly MethodReference signature;
public bool HasThis {
get { return signature.HasThis; }
set { signature.HasThis = value; }
}
public bool ExplicitThis {
get { return signature.ExplicitThis; }
set { signature.ExplicitThis = value; }
}
public MethodCallingConvention CallingConvention {
get { return signature.CallingConvention; }
set { signature.CallingConvention = value; }
}
public bool HasParameters {
get { return signature.HasParameters; }
}
public Collection<ParameterDefinition> Parameters {
get { return signature.Parameters; }
}
public TypeReference ReturnType {
get { return signature.MethodReturnType.ReturnType; }
set { signature.MethodReturnType.ReturnType = value; }
}
public MethodReturnType MethodReturnType {
get { return signature.MethodReturnType; }
}
public string Name {
get { return string.Empty; }
set { throw new InvalidOperationException (); }
}
public string Namespace {
get { return string.Empty; }
set { throw new InvalidOperationException (); }
}
public ModuleDefinition Module {
get { return ReturnType.Module; }
}
public IMetadataScope Scope {
get { return signature.ReturnType.Scope; }
}
public MetadataToken MetadataToken {
get { return signature.token; }
set { signature.token = value; }
}
public string FullName {
get {
var signature = new StringBuilder ();
signature.Append (ReturnType.FullName);
this.MethodSignatureFullName (signature);
return signature.ToString ();
}
}
internal CallSite ()
{
this.signature = new MethodReference ();
this.signature.token = new MetadataToken (TokenType.Signature, 0);
}
public CallSite (TypeReference returnType)
: this ()
{
if (returnType == null)
throw new ArgumentNullException ("returnType");
this.signature.ReturnType = returnType;
}
public override string ToString ()
{
return FullName;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 087823dce9623d348927f193f95a1807
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
namespace MonoFN.Cecil
{
static class Consts
{
public const string AssemblyName = "MonoFN.Cecil";
public const string PublicKey = "00240000048000009400000006020000002400005253413100040000010001002b5c9f7f04346c324a3176f8d3ee823bbf2d60efdbc35f86fd9e65ea3e6cd11bcdcba3a353e55133c8ac5c4caaba581b2c6dfff2cc2d0edc43959ddb86b973300a479a82419ef489c3225f1fe429a708507bd515835160e10bc743d20ca33ab9570cfd68d479fcf0bc797a763bec5d1000f0159ef619e709d915975e87beebaf";
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da413e0e98056364a9512beb26e9aea5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,221 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
using System.Diagnostics;
using System.Threading;
namespace MonoFN.Cecil {
public struct CustomAttributeArgument {
readonly TypeReference type;
readonly object value;
public TypeReference Type {
get { return type; }
}
public object Value {
get { return value; }
}
public CustomAttributeArgument (TypeReference type, object value)
{
Mixin.CheckType (type);
this.type = type;
this.value = value;
}
}
public struct CustomAttributeNamedArgument {
readonly string name;
readonly CustomAttributeArgument argument;
public string Name {
get { return name; }
}
public CustomAttributeArgument Argument {
get { return argument; }
}
public CustomAttributeNamedArgument (string name, CustomAttributeArgument argument)
{
Mixin.CheckName (name);
this.name = name;
this.argument = argument;
}
}
public interface ICustomAttribute {
TypeReference AttributeType { get; }
bool HasFields { get; }
bool HasProperties { get; }
bool HasConstructorArguments { get; }
Collection<CustomAttributeNamedArgument> Fields { get; }
Collection<CustomAttributeNamedArgument> Properties { get; }
Collection<CustomAttributeArgument> ConstructorArguments { get; }
}
[DebuggerDisplay ("{AttributeType}")]
public sealed class CustomAttribute : ICustomAttribute {
internal CustomAttributeValueProjection projection;
readonly internal uint signature;
internal bool resolved;
MethodReference constructor;
byte [] blob;
internal Collection<CustomAttributeArgument> arguments;
internal Collection<CustomAttributeNamedArgument> fields;
internal Collection<CustomAttributeNamedArgument> properties;
public MethodReference Constructor {
get { return constructor; }
set { constructor = value; }
}
public TypeReference AttributeType {
get { return constructor.DeclaringType; }
}
public bool IsResolved {
get { return resolved; }
}
public bool HasConstructorArguments {
get {
Resolve ();
return !arguments.IsNullOrEmpty ();
}
}
public Collection<CustomAttributeArgument> ConstructorArguments {
get {
Resolve ();
if (arguments == null)
Interlocked.CompareExchange (ref arguments, new Collection<CustomAttributeArgument> (), null);
return arguments;
}
}
public bool HasFields {
get {
Resolve ();
return !fields.IsNullOrEmpty ();
}
}
public Collection<CustomAttributeNamedArgument> Fields {
get {
Resolve ();
if (fields == null)
Interlocked.CompareExchange (ref fields, new Collection<CustomAttributeNamedArgument> (), null);
return fields;
}
}
public bool HasProperties {
get {
Resolve ();
return !properties.IsNullOrEmpty ();
}
}
public Collection<CustomAttributeNamedArgument> Properties {
get {
Resolve ();
if (properties == null)
Interlocked.CompareExchange (ref properties, new Collection<CustomAttributeNamedArgument> (), null);
return properties;
}
}
internal bool HasImage {
get { return constructor != null && constructor.HasImage; }
}
internal ModuleDefinition Module {
get { return constructor.Module; }
}
internal CustomAttribute (uint signature, MethodReference constructor)
{
this.signature = signature;
this.constructor = constructor;
this.resolved = false;
}
public CustomAttribute (MethodReference constructor)
{
this.constructor = constructor;
this.resolved = true;
}
public CustomAttribute (MethodReference constructor, byte [] blob)
{
this.constructor = constructor;
this.resolved = false;
this.blob = blob;
}
public byte [] GetBlob ()
{
if (blob != null)
return blob;
if (!HasImage)
throw new NotSupportedException ();
return Module.Read (ref blob, this, (attribute, reader) => reader.ReadCustomAttributeBlob (attribute.signature));
}
void Resolve ()
{
if (resolved || !HasImage)
return;
lock (Module.SyncRoot) {
if (resolved)
return;
Module.Read (this, (attribute, reader) => {
try {
reader.ReadCustomAttributeSignature (attribute);
resolved = true;
}
catch (ResolutionException) {
if (arguments != null)
arguments.Clear ();
if (fields != null)
fields.Clear ();
if (properties != null)
properties.Clear ();
resolved = false;
}
});
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91db4bc8250b4b949bf262a196c9c0c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,61 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Collections.Generic;
namespace MonoFN.Cecil {
public class DefaultAssemblyResolver : BaseAssemblyResolver {
readonly IDictionary<string, AssemblyDefinition> cache;
public DefaultAssemblyResolver ()
{
cache = new Dictionary<string, AssemblyDefinition> (StringComparer.Ordinal);
}
public override AssemblyDefinition Resolve (AssemblyNameReference name)
{
Mixin.CheckName (name);
AssemblyDefinition assembly;
if (cache.TryGetValue (name.FullName, out assembly))
return assembly;
assembly = base.Resolve (name);
cache [name.FullName] = assembly;
return assembly;
}
protected void RegisterAssembly (AssemblyDefinition assembly)
{
if (assembly == null)
throw new ArgumentNullException ("assembly");
var name = assembly.Name.FullName;
if (cache.ContainsKey (name))
return;
cache [name] = assembly;
}
protected override void Dispose (bool disposing)
{
foreach (var assembly in cache.Values)
assembly.Dispose ();
cache.Clear ();
base.Dispose (disposing);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5390b4f18cb83c046baaaa937fec06a7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,98 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.IO;
namespace MonoFN.Cecil {
public sealed class EmbeddedResource : Resource {
readonly MetadataReader reader;
uint? offset;
byte [] data;
Stream stream;
public override ResourceType ResourceType {
get { return ResourceType.Embedded; }
}
public EmbeddedResource (string name, ManifestResourceAttributes attributes, byte [] data) :
base (name, attributes)
{
this.data = data;
}
public EmbeddedResource (string name, ManifestResourceAttributes attributes, Stream stream) :
base (name, attributes)
{
this.stream = stream;
}
internal EmbeddedResource (string name, ManifestResourceAttributes attributes, uint offset, MetadataReader reader)
: base (name, attributes)
{
this.offset = offset;
this.reader = reader;
}
public Stream GetResourceStream ()
{
if (stream != null)
return stream;
if (data != null)
return new MemoryStream (data);
if (offset.HasValue)
return new MemoryStream (reader.GetManagedResource (offset.Value));
throw new InvalidOperationException ();
}
public byte [] GetResourceData ()
{
if (stream != null)
return ReadStream (stream);
if (data != null)
return data;
if (offset.HasValue)
return reader.GetManagedResource (offset.Value);
throw new InvalidOperationException ();
}
static byte [] ReadStream (Stream stream)
{
int read;
if (stream.CanSeek) {
var length = (int)stream.Length;
var data = new byte [length];
int offset = 0;
while ((read = stream.Read (data, offset, length - offset)) > 0)
offset += read;
return data;
}
var buffer = new byte [1024 * 8];
var memory = new MemoryStream ();
while ((read = stream.Read (buffer, 0, buffer.Length)) > 0)
memory.Write (buffer, 0, read);
return memory.ToArray ();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b5874acd8fee1b4499a3249dd4648428
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
[Flags]
public enum EventAttributes : ushort {
None = 0x0000,
SpecialName = 0x0200, // Event is special
RTSpecialName = 0x0400 // CLI provides 'special' behavior, depending upon the name of the event
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20c18be3d45bbf84d82732fd16751df3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,156 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System.Threading;
namespace MonoFN.Cecil {
public sealed class EventDefinition : EventReference, IMemberDefinition {
ushort attributes;
Collection<CustomAttribute> custom_attributes;
internal MethodDefinition add_method;
internal MethodDefinition invoke_method;
internal MethodDefinition remove_method;
internal Collection<MethodDefinition> other_methods;
public EventAttributes Attributes {
get { return (EventAttributes)attributes; }
set { attributes = (ushort)value; }
}
public MethodDefinition AddMethod {
get {
if (add_method != null)
return add_method;
InitializeMethods ();
return add_method;
}
set { add_method = value; }
}
public MethodDefinition InvokeMethod {
get {
if (invoke_method != null)
return invoke_method;
InitializeMethods ();
return invoke_method;
}
set { invoke_method = value; }
}
public MethodDefinition RemoveMethod {
get {
if (remove_method != null)
return remove_method;
InitializeMethods ();
return remove_method;
}
set { remove_method = value; }
}
public bool HasOtherMethods {
get {
if (other_methods != null)
return other_methods.Count > 0;
InitializeMethods ();
return !other_methods.IsNullOrEmpty ();
}
}
public Collection<MethodDefinition> OtherMethods {
get {
if (other_methods != null)
return other_methods;
InitializeMethods ();
if (other_methods == null)
Interlocked.CompareExchange (ref other_methods, new Collection<MethodDefinition> (), null);
return other_methods;
}
}
public bool HasCustomAttributes {
get {
if (custom_attributes != null)
return custom_attributes.Count > 0;
return this.GetHasCustomAttributes (Module);
}
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
#region EventAttributes
public bool IsSpecialName {
get { return attributes.GetAttributes ((ushort)EventAttributes.SpecialName); }
set { attributes = attributes.SetAttributes ((ushort)EventAttributes.SpecialName, value); }
}
public bool IsRuntimeSpecialName {
get { return attributes.GetAttributes ((ushort)EventAttributes.RTSpecialName); }
set { attributes = attributes.SetAttributes ((ushort)EventAttributes.RTSpecialName, value); }
}
#endregion
public new TypeDefinition DeclaringType {
get { return (TypeDefinition)base.DeclaringType; }
set { base.DeclaringType = value; }
}
public override bool IsDefinition {
get { return true; }
}
public EventDefinition (string name, EventAttributes attributes, TypeReference eventType)
: base (name, eventType)
{
this.attributes = (ushort)attributes;
this.token = new MetadataToken (TokenType.Event);
}
void InitializeMethods ()
{
var module = this.Module;
if (module == null)
return;
lock (module.SyncRoot) {
if (add_method != null
|| invoke_method != null
|| remove_method != null)
return;
if (!module.HasImage ())
return;
module.Read (this, (@event, reader) => reader.ReadMethods (@event));
}
}
public override EventDefinition Resolve ()
{
return this;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4b201911ff1f925438edbe5b91275268
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public abstract class EventReference : MemberReference {
TypeReference event_type;
public TypeReference EventType {
get { return event_type; }
set { event_type = value; }
}
public override string FullName {
get { return event_type.FullName + " " + MemberFullName (); }
}
protected EventReference (string name, TypeReference eventType)
: base (name)
{
Mixin.CheckType (eventType, Mixin.Argument.eventType);
event_type = eventType;
}
protected override IMemberDefinition ResolveDefinition ()
{
return this.Resolve ();
}
public new abstract EventDefinition Resolve ();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94d9b58b6c4033343b975f6730127514
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,238 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public sealed class ExportedType : IMetadataTokenProvider {
string @namespace;
string name;
uint attributes;
IMetadataScope scope;
ModuleDefinition module;
int identifier;
ExportedType declaring_type;
internal MetadataToken token;
public string Namespace {
get { return @namespace; }
set { @namespace = value; }
}
public string Name {
get { return name; }
set { name = value; }
}
public TypeAttributes Attributes {
get { return (TypeAttributes)attributes; }
set { attributes = (uint)value; }
}
public IMetadataScope Scope {
get {
if (declaring_type != null)
return declaring_type.Scope;
return scope;
}
set {
if (declaring_type != null) {
declaring_type.Scope = value;
return;
}
scope = value;
}
}
public ExportedType DeclaringType {
get { return declaring_type; }
set { declaring_type = value; }
}
public MetadataToken MetadataToken {
get { return token; }
set { token = value; }
}
public int Identifier {
get { return identifier; }
set { identifier = value; }
}
#region TypeAttributes
public bool IsNotPublic {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NotPublic); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NotPublic, value); }
}
public bool IsPublic {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.Public); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.Public, value); }
}
public bool IsNestedPublic {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedPublic); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedPublic, value); }
}
public bool IsNestedPrivate {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedPrivate); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedPrivate, value); }
}
public bool IsNestedFamily {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedFamily); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedFamily, value); }
}
public bool IsNestedAssembly {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedAssembly); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedAssembly, value); }
}
public bool IsNestedFamilyAndAssembly {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedFamANDAssem); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedFamANDAssem, value); }
}
public bool IsNestedFamilyOrAssembly {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedFamORAssem); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.VisibilityMask, (uint)TypeAttributes.NestedFamORAssem, value); }
}
public bool IsAutoLayout {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.LayoutMask, (uint)TypeAttributes.AutoLayout); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.LayoutMask, (uint)TypeAttributes.AutoLayout, value); }
}
public bool IsSequentialLayout {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.LayoutMask, (uint)TypeAttributes.SequentialLayout); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.LayoutMask, (uint)TypeAttributes.SequentialLayout, value); }
}
public bool IsExplicitLayout {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.LayoutMask, (uint)TypeAttributes.ExplicitLayout); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.LayoutMask, (uint)TypeAttributes.ExplicitLayout, value); }
}
public bool IsClass {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.ClassSemanticMask, (uint)TypeAttributes.Class); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.ClassSemanticMask, (uint)TypeAttributes.Class, value); }
}
public bool IsInterface {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.ClassSemanticMask, (uint)TypeAttributes.Interface); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.ClassSemanticMask, (uint)TypeAttributes.Interface, value); }
}
public bool IsAbstract {
get { return attributes.GetAttributes ((uint)TypeAttributes.Abstract); }
set { attributes = attributes.SetAttributes ((uint)TypeAttributes.Abstract, value); }
}
public bool IsSealed {
get { return attributes.GetAttributes ((uint)TypeAttributes.Sealed); }
set { attributes = attributes.SetAttributes ((uint)TypeAttributes.Sealed, value); }
}
public bool IsSpecialName {
get { return attributes.GetAttributes ((uint)TypeAttributes.SpecialName); }
set { attributes = attributes.SetAttributes ((uint)TypeAttributes.SpecialName, value); }
}
public bool IsImport {
get { return attributes.GetAttributes ((uint)TypeAttributes.Import); }
set { attributes = attributes.SetAttributes ((uint)TypeAttributes.Import, value); }
}
public bool IsSerializable {
get { return attributes.GetAttributes ((uint)TypeAttributes.Serializable); }
set { attributes = attributes.SetAttributes ((uint)TypeAttributes.Serializable, value); }
}
public bool IsAnsiClass {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.StringFormatMask, (uint)TypeAttributes.AnsiClass); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.StringFormatMask, (uint)TypeAttributes.AnsiClass, value); }
}
public bool IsUnicodeClass {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.StringFormatMask, (uint)TypeAttributes.UnicodeClass); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.StringFormatMask, (uint)TypeAttributes.UnicodeClass, value); }
}
public bool IsAutoClass {
get { return attributes.GetMaskedAttributes ((uint)TypeAttributes.StringFormatMask, (uint)TypeAttributes.AutoClass); }
set { attributes = attributes.SetMaskedAttributes ((uint)TypeAttributes.StringFormatMask, (uint)TypeAttributes.AutoClass, value); }
}
public bool IsBeforeFieldInit {
get { return attributes.GetAttributes ((uint)TypeAttributes.BeforeFieldInit); }
set { attributes = attributes.SetAttributes ((uint)TypeAttributes.BeforeFieldInit, value); }
}
public bool IsRuntimeSpecialName {
get { return attributes.GetAttributes ((uint)TypeAttributes.RTSpecialName); }
set { attributes = attributes.SetAttributes ((uint)TypeAttributes.RTSpecialName, value); }
}
public bool HasSecurity {
get { return attributes.GetAttributes ((uint)TypeAttributes.HasSecurity); }
set { attributes = attributes.SetAttributes ((uint)TypeAttributes.HasSecurity, value); }
}
#endregion
public bool IsForwarder {
get { return attributes.GetAttributes ((uint)TypeAttributes.Forwarder); }
set { attributes = attributes.SetAttributes ((uint)TypeAttributes.Forwarder, value); }
}
public string FullName {
get {
var fullname = string.IsNullOrEmpty (@namespace)
? name
: @namespace + '.' + name;
if (declaring_type != null)
return declaring_type.FullName + "/" + fullname;
return fullname;
}
}
public ExportedType (string @namespace, string name, ModuleDefinition module, IMetadataScope scope)
{
this.@namespace = @namespace;
this.name = name;
this.scope = scope;
this.module = module;
}
public override string ToString ()
{
return FullName;
}
public TypeDefinition Resolve ()
{
return module.Resolve (CreateReference ());
}
internal TypeReference CreateReference ()
{
return new TypeReference (@namespace, name, module, scope) {
DeclaringType = declaring_type != null ? declaring_type.CreateReference () : null,
};
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b7fa6f0bdd43c0d44a63cd789a765eeb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
[Flags]
public enum FieldAttributes : ushort {
FieldAccessMask = 0x0007,
CompilerControlled = 0x0000, // Member not referenceable
Private = 0x0001, // Accessible only by the parent type
FamANDAssem = 0x0002, // Accessible by sub-types only in this assembly
Assembly = 0x0003, // Accessible by anyone in the Assembly
Family = 0x0004, // Accessible only by type and sub-types
FamORAssem = 0x0005, // Accessible by sub-types anywhere, plus anyone in the assembly
Public = 0x0006, // Accessible by anyone who has visibility to this scope field contract attributes
Static = 0x0010, // Defined on type, else per instance
InitOnly = 0x0020, // Field may only be initialized, not written after init
Literal = 0x0040, // Value is compile time constant
NotSerialized = 0x0080, // Field does not have to be serialized when type is remoted
SpecialName = 0x0200, // Field is special
// Interop Attributes
PInvokeImpl = 0x2000, // Implementation is forwarded through PInvoke
// Additional flags
RTSpecialName = 0x0400, // CLI provides 'special' behavior, depending upon the name of the field
HasFieldMarshal = 0x1000, // Field has marshalling information
HasDefault = 0x8000, // Field has default
HasFieldRVA = 0x0100 // Field has RVA
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8e9187082e8fc1446a8c2aa12d8f3fa4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,281 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
namespace MonoFN.Cecil {
public sealed class FieldDefinition : FieldReference, IMemberDefinition, IConstantProvider, IMarshalInfoProvider {
ushort attributes;
Collection<CustomAttribute> custom_attributes;
int offset = Mixin.NotResolvedMarker;
internal int rva = Mixin.NotResolvedMarker;
byte [] initial_value;
object constant = Mixin.NotResolved;
MarshalInfo marshal_info;
void ResolveLayout ()
{
if (offset != Mixin.NotResolvedMarker)
return;
if (!HasImage) {
offset = Mixin.NoDataMarker;
return;
}
lock (Module.SyncRoot) {
if (offset != Mixin.NotResolvedMarker)
return;
offset = Module.Read (this, (field, reader) => reader.ReadFieldLayout (field));
}
}
public bool HasLayoutInfo {
get {
if (offset >= 0)
return true;
ResolveLayout ();
return offset >= 0;
}
}
public int Offset {
get {
if (offset >= 0)
return offset;
ResolveLayout ();
return offset >= 0 ? offset : -1;
}
set { offset = value; }
}
internal FieldDefinitionProjection WindowsRuntimeProjection {
get { return (FieldDefinitionProjection)projection; }
set { projection = value; }
}
void ResolveRVA ()
{
if (rva != Mixin.NotResolvedMarker)
return;
if (!HasImage)
return;
lock (Module.SyncRoot) {
if (rva != Mixin.NotResolvedMarker)
return;
rva = Module.Read (this, (field, reader) => reader.ReadFieldRVA (field));
}
}
public int RVA {
get {
if (rva > 0)
return rva;
ResolveRVA ();
return rva > 0 ? rva : 0;
}
}
public byte [] InitialValue {
get {
if (initial_value != null)
return initial_value;
ResolveRVA ();
if (initial_value == null)
initial_value = Empty<byte>.Array;
return initial_value;
}
set {
initial_value = value;
HasFieldRVA = !initial_value.IsNullOrEmpty ();
rva = 0;
}
}
public FieldAttributes Attributes {
get { return (FieldAttributes)attributes; }
set {
if (IsWindowsRuntimeProjection && (ushort)value != attributes)
throw new InvalidOperationException ();
attributes = (ushort)value;
}
}
public bool HasConstant {
get {
this.ResolveConstant (ref constant, Module);
return constant != Mixin.NoValue;
}
set { if (!value) constant = Mixin.NoValue; }
}
public object Constant {
get { return HasConstant ? constant : null; }
set { constant = value; }
}
public bool HasCustomAttributes {
get {
if (custom_attributes != null)
return custom_attributes.Count > 0;
return this.GetHasCustomAttributes (Module);
}
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
public bool HasMarshalInfo {
get {
if (marshal_info != null)
return true;
return this.GetHasMarshalInfo (Module);
}
}
public MarshalInfo MarshalInfo {
get { return marshal_info ?? (this.GetMarshalInfo (ref marshal_info, Module)); }
set { marshal_info = value; }
}
#region FieldAttributes
public bool IsCompilerControlled {
get { return attributes.GetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.CompilerControlled); }
set { attributes = attributes.SetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.CompilerControlled, value); }
}
public bool IsPrivate {
get { return attributes.GetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.Private); }
set { attributes = attributes.SetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.Private, value); }
}
public bool IsFamilyAndAssembly {
get { return attributes.GetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.FamANDAssem); }
set { attributes = attributes.SetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.FamANDAssem, value); }
}
public bool IsAssembly {
get { return attributes.GetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.Assembly); }
set { attributes = attributes.SetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.Assembly, value); }
}
public bool IsFamily {
get { return attributes.GetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.Family); }
set { attributes = attributes.SetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.Family, value); }
}
public bool IsFamilyOrAssembly {
get { return attributes.GetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.FamORAssem); }
set { attributes = attributes.SetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.FamORAssem, value); }
}
public bool IsPublic {
get { return attributes.GetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.Public); }
set { attributes = attributes.SetMaskedAttributes ((ushort)FieldAttributes.FieldAccessMask, (ushort)FieldAttributes.Public, value); }
}
public bool IsStatic {
get { return attributes.GetAttributes ((ushort)FieldAttributes.Static); }
set { attributes = attributes.SetAttributes ((ushort)FieldAttributes.Static, value); }
}
public bool IsInitOnly {
get { return attributes.GetAttributes ((ushort)FieldAttributes.InitOnly); }
set { attributes = attributes.SetAttributes ((ushort)FieldAttributes.InitOnly, value); }
}
public bool IsLiteral {
get { return attributes.GetAttributes ((ushort)FieldAttributes.Literal); }
set { attributes = attributes.SetAttributes ((ushort)FieldAttributes.Literal, value); }
}
public bool IsNotSerialized {
get { return attributes.GetAttributes ((ushort)FieldAttributes.NotSerialized); }
set { attributes = attributes.SetAttributes ((ushort)FieldAttributes.NotSerialized, value); }
}
public bool IsSpecialName {
get { return attributes.GetAttributes ((ushort)FieldAttributes.SpecialName); }
set { attributes = attributes.SetAttributes ((ushort)FieldAttributes.SpecialName, value); }
}
public bool IsPInvokeImpl {
get { return attributes.GetAttributes ((ushort)FieldAttributes.PInvokeImpl); }
set { attributes = attributes.SetAttributes ((ushort)FieldAttributes.PInvokeImpl, value); }
}
public bool IsRuntimeSpecialName {
get { return attributes.GetAttributes ((ushort)FieldAttributes.RTSpecialName); }
set { attributes = attributes.SetAttributes ((ushort)FieldAttributes.RTSpecialName, value); }
}
public bool HasDefault {
get { return attributes.GetAttributes ((ushort)FieldAttributes.HasDefault); }
set { attributes = attributes.SetAttributes ((ushort)FieldAttributes.HasDefault, value); }
}
public bool HasFieldRVA {
get { return attributes.GetAttributes ((ushort)FieldAttributes.HasFieldRVA); }
set { attributes = attributes.SetAttributes ((ushort)FieldAttributes.HasFieldRVA, value); }
}
#endregion
public override bool IsDefinition {
get { return true; }
}
public new TypeDefinition DeclaringType {
get { return (TypeDefinition)base.DeclaringType; }
set { base.DeclaringType = value; }
}
public FieldDefinition (string name, FieldAttributes attributes, TypeReference fieldType)
: base (name, fieldType)
{
this.attributes = (ushort)attributes;
}
public override FieldDefinition Resolve ()
{
return this;
}
}
static partial class Mixin {
public const int NotResolvedMarker = -2;
public const int NoDataMarker = -1;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 00dcb95135f39ec4c923f7923bcc93ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
public class FieldReference : MemberReference {
TypeReference field_type;
public TypeReference FieldType {
get { return field_type; }
set { field_type = value; }
}
public override string FullName {
get { return field_type.FullName + " " + MemberFullName (); }
}
public override bool ContainsGenericParameter {
get { return field_type.ContainsGenericParameter || base.ContainsGenericParameter; }
}
internal FieldReference ()
{
this.token = new MetadataToken (TokenType.MemberRef);
}
public FieldReference (string name, TypeReference fieldType)
: base (name)
{
Mixin.CheckType (fieldType, Mixin.Argument.fieldType);
this.field_type = fieldType;
this.token = new MetadataToken (TokenType.MemberRef);
}
public FieldReference (string name, TypeReference fieldType, TypeReference declaringType)
: this (name, fieldType)
{
Mixin.CheckType (declaringType, Mixin.Argument.declaringType);
this.DeclaringType = declaringType;
}
protected override IMemberDefinition ResolveDefinition ()
{
return this.Resolve ();
}
public new virtual FieldDefinition Resolve ()
{
var module = this.Module;
if (module == null)
throw new NotSupportedException ();
return module.Resolve (this);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 990be2becde06b4468f79bd17646a47a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
enum FileAttributes : uint {
ContainsMetaData = 0x0000, // This is not a resource file
ContainsNoMetaData = 0x0001, // This is a resource file or other non-metadata-containing file
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 56e662d580c0894489669cc8058a2783
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,111 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
using System.Text;
using MD = MonoFN.Cecil.Metadata;
namespace MonoFN.Cecil {
public sealed class FunctionPointerType : TypeSpecification, IMethodSignature {
readonly MethodReference function;
public bool HasThis {
get { return function.HasThis; }
set { function.HasThis = value; }
}
public bool ExplicitThis {
get { return function.ExplicitThis; }
set { function.ExplicitThis = value; }
}
public MethodCallingConvention CallingConvention {
get { return function.CallingConvention; }
set { function.CallingConvention = value; }
}
public bool HasParameters {
get { return function.HasParameters; }
}
public Collection<ParameterDefinition> Parameters {
get { return function.Parameters; }
}
public TypeReference ReturnType {
get { return function.MethodReturnType.ReturnType; }
set { function.MethodReturnType.ReturnType = value; }
}
public MethodReturnType MethodReturnType {
get { return function.MethodReturnType; }
}
public override string Name {
get { return function.Name; }
set { throw new InvalidOperationException (); }
}
public override string Namespace {
get { return string.Empty; }
set { throw new InvalidOperationException (); }
}
public override ModuleDefinition Module {
get { return ReturnType.Module; }
}
public override IMetadataScope Scope {
get { return function.ReturnType.Scope; }
set { throw new InvalidOperationException (); }
}
public override bool IsFunctionPointer {
get { return true; }
}
public override bool ContainsGenericParameter {
get { return function.ContainsGenericParameter; }
}
public override string FullName {
get {
var signature = new StringBuilder ();
signature.Append (function.Name);
signature.Append (" ");
signature.Append (function.ReturnType.FullName);
signature.Append (" *");
this.MethodSignatureFullName (signature);
return signature.ToString ();
}
}
public FunctionPointerType ()
: base (null)
{
this.function = new MethodReference ();
this.function.Name = "method";
this.etype = MD.ElementType.FnPtr;
}
public override TypeDefinition Resolve ()
{
return null;
}
public override TypeReference GetElementType ()
{
return this;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91d84cd146416f945acbfce1b1dbcacb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System.Text;
using System.Threading;
namespace MonoFN.Cecil {
public sealed class GenericInstanceMethod : MethodSpecification, IGenericInstance, IGenericContext {
Collection<TypeReference> arguments;
public bool HasGenericArguments {
get { return !arguments.IsNullOrEmpty (); }
}
public Collection<TypeReference> GenericArguments {
get {
if (arguments == null)
Interlocked.CompareExchange (ref arguments, new Collection<TypeReference> (), null);
return arguments;
}
}
public override bool IsGenericInstance {
get { return true; }
}
IGenericParameterProvider IGenericContext.Method {
get { return ElementMethod; }
}
IGenericParameterProvider IGenericContext.Type {
get { return ElementMethod.DeclaringType; }
}
public override bool ContainsGenericParameter {
get { return this.ContainsGenericParameter () || base.ContainsGenericParameter; }
}
public override string FullName {
get {
var signature = new StringBuilder ();
var method = this.ElementMethod;
signature.Append (method.ReturnType.FullName)
.Append (" ")
.Append (method.DeclaringType.FullName)
.Append ("::")
.Append (method.Name);
this.GenericInstanceFullName (signature);
this.MethodSignatureFullName (signature);
return signature.ToString ();
}
}
public GenericInstanceMethod (MethodReference method)
: base (method)
{
}
internal GenericInstanceMethod (MethodReference method, int arity)
: this (method)
{
this.arguments = new Collection<TypeReference> (arity);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fd61b82dc3c653d42a1fc0f4e4c003f8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
using System.Text;
using System.Threading;
using MD = MonoFN.Cecil.Metadata;
namespace MonoFN.Cecil {
public sealed class GenericInstanceType : TypeSpecification, IGenericInstance, IGenericContext {
Collection<TypeReference> arguments;
public bool HasGenericArguments {
get { return !arguments.IsNullOrEmpty (); }
}
public Collection<TypeReference> GenericArguments {
get {
if (arguments == null)
Interlocked.CompareExchange (ref arguments, new Collection<TypeReference> (), null);
return arguments;
}
}
public override TypeReference DeclaringType {
get { return ElementType.DeclaringType; }
set { throw new NotSupportedException (); }
}
public override string FullName {
get {
var name = new StringBuilder ();
name.Append (base.FullName);
this.GenericInstanceFullName (name);
return name.ToString ();
}
}
public override bool IsGenericInstance {
get { return true; }
}
public override bool ContainsGenericParameter {
get { return this.ContainsGenericParameter () || base.ContainsGenericParameter; }
}
IGenericParameterProvider IGenericContext.Type {
get { return ElementType; }
}
public GenericInstanceType (TypeReference type)
: base (type)
{
base.IsValueType = type.IsValueType;
this.etype = MD.ElementType.GenericInst;
}
internal GenericInstanceType (TypeReference type, int arity)
: this (type)
{
this.arguments = new Collection<TypeReference> (arity);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 536e7e359f0fa6c449a352476e8af197
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,360 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Cecil.Metadata;
using MonoFN.Collections.Generic;
using System;
using System.Threading;
namespace MonoFN.Cecil {
public sealed class GenericParameter : TypeReference, ICustomAttributeProvider {
internal int position;
internal GenericParameterType type;
internal IGenericParameterProvider owner;
ushort attributes;
GenericParameterConstraintCollection constraints;
Collection<CustomAttribute> custom_attributes;
public GenericParameterAttributes Attributes {
get { return (GenericParameterAttributes)attributes; }
set { attributes = (ushort)value; }
}
public int Position {
get { return position; }
}
public GenericParameterType Type {
get { return type; }
}
public IGenericParameterProvider Owner {
get { return owner; }
}
public bool HasConstraints {
get {
if (constraints != null)
return constraints.Count > 0;
return HasImage && Module.Read (this, (generic_parameter, reader) => reader.HasGenericConstraints (generic_parameter));
}
}
public Collection<GenericParameterConstraint> Constraints {
get {
if (constraints != null)
return constraints;
if (HasImage)
return Module.Read (ref constraints, this, (generic_parameter, reader) => reader.ReadGenericConstraints (generic_parameter));
Interlocked.CompareExchange (ref constraints, new GenericParameterConstraintCollection (this), null);
return constraints;
}
}
public bool HasCustomAttributes {
get {
if (custom_attributes != null)
return custom_attributes.Count > 0;
return this.GetHasCustomAttributes (Module);
}
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
public override IMetadataScope Scope {
get {
if (owner == null)
return null;
return owner.GenericParameterType == GenericParameterType.Method
? ((MethodReference)owner).DeclaringType.Scope
: ((TypeReference)owner).Scope;
}
set { throw new InvalidOperationException (); }
}
public override TypeReference DeclaringType {
get { return owner as TypeReference; }
set { throw new InvalidOperationException (); }
}
public MethodReference DeclaringMethod {
get { return owner as MethodReference; }
}
public override ModuleDefinition Module {
get { return module ?? owner.Module; }
}
public override string Name {
get {
if (!string.IsNullOrEmpty (base.Name))
return base.Name;
return base.Name = (type == GenericParameterType.Method ? "!!" : "!") + position;
}
}
public override string Namespace {
get { return string.Empty; }
set { throw new InvalidOperationException (); }
}
public override string FullName {
get { return Name; }
}
public override bool IsGenericParameter {
get { return true; }
}
public override bool ContainsGenericParameter {
get { return true; }
}
public override MetadataType MetadataType {
get { return (MetadataType)etype; }
}
#region GenericParameterAttributes
public bool IsNonVariant {
get { return attributes.GetMaskedAttributes ((ushort)GenericParameterAttributes.VarianceMask, (ushort)GenericParameterAttributes.NonVariant); }
set { attributes = attributes.SetMaskedAttributes ((ushort)GenericParameterAttributes.VarianceMask, (ushort)GenericParameterAttributes.NonVariant, value); }
}
public bool IsCovariant {
get { return attributes.GetMaskedAttributes ((ushort)GenericParameterAttributes.VarianceMask, (ushort)GenericParameterAttributes.Covariant); }
set { attributes = attributes.SetMaskedAttributes ((ushort)GenericParameterAttributes.VarianceMask, (ushort)GenericParameterAttributes.Covariant, value); }
}
public bool IsContravariant {
get { return attributes.GetMaskedAttributes ((ushort)GenericParameterAttributes.VarianceMask, (ushort)GenericParameterAttributes.Contravariant); }
set { attributes = attributes.SetMaskedAttributes ((ushort)GenericParameterAttributes.VarianceMask, (ushort)GenericParameterAttributes.Contravariant, value); }
}
public bool HasReferenceTypeConstraint {
get { return attributes.GetAttributes ((ushort)GenericParameterAttributes.ReferenceTypeConstraint); }
set { attributes = attributes.SetAttributes ((ushort)GenericParameterAttributes.ReferenceTypeConstraint, value); }
}
public bool HasNotNullableValueTypeConstraint {
get { return attributes.GetAttributes ((ushort)GenericParameterAttributes.NotNullableValueTypeConstraint); }
set { attributes = attributes.SetAttributes ((ushort)GenericParameterAttributes.NotNullableValueTypeConstraint, value); }
}
public bool HasDefaultConstructorConstraint {
get { return attributes.GetAttributes ((ushort)GenericParameterAttributes.DefaultConstructorConstraint); }
set { attributes = attributes.SetAttributes ((ushort)GenericParameterAttributes.DefaultConstructorConstraint, value); }
}
#endregion
public GenericParameter (IGenericParameterProvider owner)
: this (string.Empty, owner)
{
}
public GenericParameter (string name, IGenericParameterProvider owner)
: base (string.Empty, name)
{
if (owner == null)
throw new ArgumentNullException ();
this.position = -1;
this.owner = owner;
this.type = owner.GenericParameterType;
this.etype = ConvertGenericParameterType (this.type);
this.token = new MetadataToken (TokenType.GenericParam);
}
internal GenericParameter (int position, GenericParameterType type, ModuleDefinition module)
: base (string.Empty, string.Empty)
{
Mixin.CheckModule (module);
this.position = position;
this.type = type;
this.etype = ConvertGenericParameterType (type);
this.module = module;
this.token = new MetadataToken (TokenType.GenericParam);
}
static ElementType ConvertGenericParameterType (GenericParameterType type)
{
switch (type) {
case GenericParameterType.Type:
return ElementType.Var;
case GenericParameterType.Method:
return ElementType.MVar;
}
throw new ArgumentOutOfRangeException ();
}
public override TypeDefinition Resolve ()
{
return null;
}
}
sealed class GenericParameterCollection : Collection<GenericParameter> {
readonly IGenericParameterProvider owner;
internal GenericParameterCollection (IGenericParameterProvider owner)
{
this.owner = owner;
}
internal GenericParameterCollection (IGenericParameterProvider owner, int capacity)
: base (capacity)
{
this.owner = owner;
}
protected override void OnAdd (GenericParameter item, int index)
{
UpdateGenericParameter (item, index);
}
protected override void OnInsert (GenericParameter item, int index)
{
UpdateGenericParameter (item, index);
for (int i = index; i < size; i++)
items [i].position = i + 1;
}
protected override void OnSet (GenericParameter item, int index)
{
UpdateGenericParameter (item, index);
}
void UpdateGenericParameter (GenericParameter item, int index)
{
item.owner = owner;
item.position = index;
item.type = owner.GenericParameterType;
}
protected override void OnRemove (GenericParameter item, int index)
{
item.owner = null;
item.position = -1;
item.type = GenericParameterType.Type;
for (int i = index + 1; i < size; i++)
items [i].position = i - 1;
}
}
public sealed class GenericParameterConstraint : ICustomAttributeProvider {
internal GenericParameter generic_parameter;
internal MetadataToken token;
TypeReference constraint_type;
Collection<CustomAttribute> custom_attributes;
public TypeReference ConstraintType {
get { return constraint_type; }
set { constraint_type = value; }
}
public bool HasCustomAttributes {
get {
if (custom_attributes != null)
return custom_attributes.Count > 0;
if (generic_parameter == null)
return false;
return this.GetHasCustomAttributes (generic_parameter.Module);
}
}
public Collection<CustomAttribute> CustomAttributes {
get {
if (generic_parameter == null) {
if (custom_attributes == null)
Interlocked.CompareExchange (ref custom_attributes, new Collection<CustomAttribute> (), null);
return custom_attributes;
}
return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, generic_parameter.Module));
}
}
public MetadataToken MetadataToken {
get { return token; }
set { token = value; }
}
internal GenericParameterConstraint (TypeReference constraintType, MetadataToken token)
{
this.constraint_type = constraintType;
this.token = token;
}
public GenericParameterConstraint (TypeReference constraintType)
{
Mixin.CheckType (constraintType, Mixin.Argument.constraintType);
this.constraint_type = constraintType;
this.token = new MetadataToken (TokenType.GenericParamConstraint);
}
}
class GenericParameterConstraintCollection : Collection<GenericParameterConstraint> {
readonly GenericParameter generic_parameter;
internal GenericParameterConstraintCollection (GenericParameter genericParameter)
{
this.generic_parameter = genericParameter;
}
internal GenericParameterConstraintCollection (GenericParameter genericParameter, int length)
: base (length)
{
this.generic_parameter = genericParameter;
}
protected override void OnAdd (GenericParameterConstraint item, int index)
{
item.generic_parameter = generic_parameter;
}
protected override void OnInsert (GenericParameterConstraint item, int index)
{
item.generic_parameter = generic_parameter;
}
protected override void OnSet (GenericParameterConstraint item, int index)
{
item.generic_parameter = generic_parameter;
}
protected override void OnRemove (GenericParameterConstraint item, int index)
{
item.generic_parameter = null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a20d39eab5fe7884c8cdf55fde143904
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
[Flags]
public enum GenericParameterAttributes : ushort {
VarianceMask = 0x0003,
NonVariant = 0x0000,
Covariant = 0x0001,
Contravariant = 0x0002,
SpecialConstraintMask = 0x001c,
ReferenceTypeConstraint = 0x0004,
NotNullableValueTypeConstraint = 0x0008,
DefaultConstructorConstraint = 0x0010
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 406369465fc07a643b3923d53fb1e941
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,175 @@
using MonoFN.Cecil.Cil;
using System;
namespace MonoFN.Cecil {
internal sealed class GenericParameterResolver {
internal static TypeReference ResolveReturnTypeIfNeeded (MethodReference methodReference)
{
if (methodReference.DeclaringType.IsArray && methodReference.Name == "Get")
return methodReference.ReturnType;
var genericInstanceMethod = methodReference as GenericInstanceMethod;
var declaringGenericInstanceType = methodReference.DeclaringType as GenericInstanceType;
if (genericInstanceMethod == null && declaringGenericInstanceType == null)
return methodReference.ReturnType;
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, methodReference.ReturnType);
}
internal static TypeReference ResolveFieldTypeIfNeeded (FieldReference fieldReference)
{
return ResolveIfNeeded (null, fieldReference.DeclaringType as GenericInstanceType, fieldReference.FieldType);
}
internal static TypeReference ResolveParameterTypeIfNeeded (MethodReference method, ParameterReference parameter)
{
var genericInstanceMethod = method as GenericInstanceMethod;
var declaringGenericInstanceType = method.DeclaringType as GenericInstanceType;
if (genericInstanceMethod == null && declaringGenericInstanceType == null)
return parameter.ParameterType;
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, parameter.ParameterType);
}
internal static TypeReference ResolveVariableTypeIfNeeded (MethodReference method, VariableReference variable)
{
var genericInstanceMethod = method as GenericInstanceMethod;
var declaringGenericInstanceType = method.DeclaringType as GenericInstanceType;
if (genericInstanceMethod == null && declaringGenericInstanceType == null)
return variable.VariableType;
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, variable.VariableType);
}
private static TypeReference ResolveIfNeeded (IGenericInstance genericInstanceMethod, IGenericInstance declaringGenericInstanceType, TypeReference parameterType)
{
var byRefType = parameterType as ByReferenceType;
if (byRefType != null)
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, byRefType);
var arrayType = parameterType as ArrayType;
if (arrayType != null)
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, arrayType);
var genericInstanceType = parameterType as GenericInstanceType;
if (genericInstanceType != null)
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, genericInstanceType);
var genericParameter = parameterType as GenericParameter;
if (genericParameter != null)
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, genericParameter);
var requiredModifierType = parameterType as RequiredModifierType;
if (requiredModifierType != null && ContainsGenericParameters (requiredModifierType))
return ResolveIfNeeded (genericInstanceMethod, declaringGenericInstanceType, requiredModifierType.ElementType);
if (ContainsGenericParameters (parameterType))
throw new Exception ("Unexpected generic parameter.");
return parameterType;
}
private static TypeReference ResolveIfNeeded (IGenericInstance genericInstanceMethod, IGenericInstance genericInstanceType, GenericParameter genericParameterElement)
{
return (genericParameterElement.MetadataType == MetadataType.MVar)
? (genericInstanceMethod != null ? genericInstanceMethod.GenericArguments [genericParameterElement.Position] : genericParameterElement)
: genericInstanceType.GenericArguments [genericParameterElement.Position];
}
private static ArrayType ResolveIfNeeded (IGenericInstance genericInstanceMethod, IGenericInstance genericInstanceType, ArrayType arrayType)
{
return new ArrayType (ResolveIfNeeded (genericInstanceMethod, genericInstanceType, arrayType.ElementType), arrayType.Rank);
}
private static ByReferenceType ResolveIfNeeded (IGenericInstance genericInstanceMethod, IGenericInstance genericInstanceType, ByReferenceType byReferenceType)
{
return new ByReferenceType (ResolveIfNeeded (genericInstanceMethod, genericInstanceType, byReferenceType.ElementType));
}
private static GenericInstanceType ResolveIfNeeded (IGenericInstance genericInstanceMethod, IGenericInstance genericInstanceType, GenericInstanceType genericInstanceType1)
{
if (!ContainsGenericParameters (genericInstanceType1))
return genericInstanceType1;
var newGenericInstance = new GenericInstanceType (genericInstanceType1.ElementType);
foreach (var genericArgument in genericInstanceType1.GenericArguments) {
if (!genericArgument.IsGenericParameter) {
newGenericInstance.GenericArguments.Add (ResolveIfNeeded (genericInstanceMethod, genericInstanceType, genericArgument));
continue;
}
var genParam = (GenericParameter)genericArgument;
switch (genParam.Type) {
case GenericParameterType.Type: {
if (genericInstanceType == null)
throw new NotSupportedException ();
newGenericInstance.GenericArguments.Add (genericInstanceType.GenericArguments [genParam.Position]);
}
break;
case GenericParameterType.Method: {
if (genericInstanceMethod == null)
newGenericInstance.GenericArguments.Add (genParam);
else
newGenericInstance.GenericArguments.Add (genericInstanceMethod.GenericArguments [genParam.Position]);
}
break;
}
}
return newGenericInstance;
}
private static bool ContainsGenericParameters (TypeReference typeReference)
{
var genericParameter = typeReference as GenericParameter;
if (genericParameter != null)
return true;
var arrayType = typeReference as ArrayType;
if (arrayType != null)
return ContainsGenericParameters (arrayType.ElementType);
var pointerType = typeReference as PointerType;
if (pointerType != null)
return ContainsGenericParameters (pointerType.ElementType);
var byRefType = typeReference as ByReferenceType;
if (byRefType != null)
return ContainsGenericParameters (byRefType.ElementType);
var sentinelType = typeReference as SentinelType;
if (sentinelType != null)
return ContainsGenericParameters (sentinelType.ElementType);
var pinnedType = typeReference as PinnedType;
if (pinnedType != null)
return ContainsGenericParameters (pinnedType.ElementType);
var requiredModifierType = typeReference as RequiredModifierType;
if (requiredModifierType != null)
return ContainsGenericParameters (requiredModifierType.ElementType);
var genericInstance = typeReference as GenericInstanceType;
if (genericInstance != null) {
foreach (var genericArgument in genericInstance.GenericArguments) {
if (ContainsGenericParameters (genericArgument))
return true;
}
return false;
}
if (typeReference is TypeSpecification)
throw new NotSupportedException ();
return false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4151464170fe40440a031e1f4f2ecf53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public interface IConstantProvider : IMetadataTokenProvider {
bool HasConstant { get; set; }
object Constant { get; set; }
}
static partial class Mixin {
internal static object NoValue = new object ();
internal static object NotResolved = new object ();
public static void ResolveConstant (
this IConstantProvider self,
ref object constant,
ModuleDefinition module)
{
if (module == null) {
constant = Mixin.NoValue;
return;
}
lock (module.SyncRoot) {
if (constant != Mixin.NotResolved)
return;
if (module.HasImage ())
constant = module.Read (self, (provider, reader) => reader.ReadConstant (provider));
else
constant = Mixin.NoValue;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 58315b928b9e49540b9d1591523c92c6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System.Threading;
namespace MonoFN.Cecil {
public interface ICustomAttributeProvider : IMetadataTokenProvider {
Collection<CustomAttribute> CustomAttributes { get; }
bool HasCustomAttributes { get; }
}
static partial class Mixin {
public static bool GetHasCustomAttributes (
this ICustomAttributeProvider self,
ModuleDefinition module)
{
return module.HasImage () && module.Read (self, (provider, reader) => reader.HasCustomAttributes (provider));
}
public static Collection<CustomAttribute> GetCustomAttributes (
this ICustomAttributeProvider self,
ref Collection<CustomAttribute> variable,
ModuleDefinition module)
{
if (module.HasImage ())
return module.Read (ref variable, self, (provider, reader) => reader.ReadCustomAttributes (provider));
Interlocked.CompareExchange (ref variable, new Collection<CustomAttribute> (), null);
return variable;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1585603aa3fe4f1409c42694378a557c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System.Text;
namespace MonoFN.Cecil {
public interface IGenericInstance : IMetadataTokenProvider {
bool HasGenericArguments { get; }
Collection<TypeReference> GenericArguments { get; }
}
static partial class Mixin {
public static bool ContainsGenericParameter (this IGenericInstance self)
{
var arguments = self.GenericArguments;
for (int i = 0; i < arguments.Count; i++)
if (arguments [i].ContainsGenericParameter)
return true;
return false;
}
public static void GenericInstanceFullName (this IGenericInstance self, StringBuilder builder)
{
builder.Append ("<");
var arguments = self.GenericArguments;
for (int i = 0; i < arguments.Count; i++) {
if (i > 0)
builder.Append (",");
builder.Append (arguments [i].FullName);
}
builder.Append (">");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 22b3a8ddd25a989449e5e9ffc632bc00
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,58 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System.Threading;
namespace MonoFN.Cecil {
public interface IGenericParameterProvider : IMetadataTokenProvider {
bool HasGenericParameters { get; }
bool IsDefinition { get; }
ModuleDefinition Module { get; }
Collection<GenericParameter> GenericParameters { get; }
GenericParameterType GenericParameterType { get; }
}
public enum GenericParameterType {
Type,
Method
}
interface IGenericContext {
bool IsDefinition { get; }
IGenericParameterProvider Type { get; }
IGenericParameterProvider Method { get; }
}
static partial class Mixin {
public static bool GetHasGenericParameters (
this IGenericParameterProvider self,
ModuleDefinition module)
{
return module.HasImage () && module.Read (self, (provider, reader) => reader.HasGenericParameters (provider));
}
public static Collection<GenericParameter> GetGenericParameters (
this IGenericParameterProvider self,
ref Collection<GenericParameter> collection,
ModuleDefinition module)
{
if (module.HasImage ())
return module.Read (ref collection, self, (provider, reader) => reader.ReadGenericParameters (provider));
Interlocked.CompareExchange (ref collection, new GenericParameterCollection (self), null);
return collection;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c81842a9d1ff34f4b94b047da954469f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public interface IMarshalInfoProvider : IMetadataTokenProvider {
bool HasMarshalInfo { get; }
MarshalInfo MarshalInfo { get; set; }
}
static partial class Mixin {
public static bool GetHasMarshalInfo (
this IMarshalInfoProvider self,
ModuleDefinition module)
{
return module.HasImage () && module.Read (self, (provider, reader) => reader.HasMarshalInfo (provider));
}
public static MarshalInfo GetMarshalInfo (
this IMarshalInfoProvider self,
ref MarshalInfo variable,
ModuleDefinition module)
{
return module.HasImage ()
? module.Read (ref variable, self, (provider, reader) => reader.ReadMarshalInfo (provider))
: null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a73829f4e35521e4892ef4e0cce2e4f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,82 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public interface IMemberDefinition : ICustomAttributeProvider {
string Name { get; set; }
string FullName { get; }
bool IsSpecialName { get; set; }
bool IsRuntimeSpecialName { get; set; }
TypeDefinition DeclaringType { get; set; }
}
static partial class Mixin {
public static bool GetAttributes (this uint self, uint attributes)
{
return (self & attributes) != 0;
}
public static uint SetAttributes (this uint self, uint attributes, bool value)
{
if (value)
return self | attributes;
return self & ~attributes;
}
public static bool GetMaskedAttributes (this uint self, uint mask, uint attributes)
{
return (self & mask) == attributes;
}
public static uint SetMaskedAttributes (this uint self, uint mask, uint attributes, bool value)
{
if (value) {
self &= ~mask;
return self | attributes;
}
return self & ~(mask & attributes);
}
public static bool GetAttributes (this ushort self, ushort attributes)
{
return (self & attributes) != 0;
}
public static ushort SetAttributes (this ushort self, ushort attributes, bool value)
{
if (value)
return (ushort)(self | attributes);
return (ushort)(self & ~attributes);
}
public static bool GetMaskedAttributes (this ushort self, ushort mask, uint attributes)
{
return (self & mask) == attributes;
}
public static ushort SetMaskedAttributes (this ushort self, ushort mask, uint attributes, bool value)
{
if (value) {
self = (ushort)(self & ~mask);
return (ushort)(self | attributes);
}
return (ushort)(self & ~(mask & attributes));
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 482577ba8693d3f438504e54d6edb971
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public enum MetadataScopeType {
AssemblyNameReference,
ModuleReference,
ModuleDefinition,
}
public interface IMetadataScope : IMetadataTokenProvider {
MetadataScopeType MetadataScopeType { get; }
string Name { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da1ce103d170a414c8c8c6849a8856a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public interface IMetadataTokenProvider {
MetadataToken MetadataToken { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c01133d3a99e95542b153987746696d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System.Text;
namespace MonoFN.Cecil {
public interface IMethodSignature : IMetadataTokenProvider {
bool HasThis { get; set; }
bool ExplicitThis { get; set; }
MethodCallingConvention CallingConvention { get; set; }
bool HasParameters { get; }
Collection<ParameterDefinition> Parameters { get; }
TypeReference ReturnType { get; set; }
MethodReturnType MethodReturnType { get; }
}
static partial class Mixin {
public static bool HasImplicitThis (this IMethodSignature self)
{
return self.HasThis && !self.ExplicitThis;
}
public static void MethodSignatureFullName (this IMethodSignature self, StringBuilder builder)
{
builder.Append ("(");
if (self.HasParameters) {
var parameters = self.Parameters;
for (int i = 0; i < parameters.Count; i++) {
var parameter = parameters [i];
if (i > 0)
builder.Append (",");
if (parameter.ParameterType.IsSentinel)
builder.Append ("...,");
builder.Append (parameter.ParameterType.FullName);
}
}
builder.Append (")");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8fdcc55987f0a4f4b93358d994704a98
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,858 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Cecil.Metadata;
using MonoFN.Collections.Generic;
using System;
using System.Collections.Generic;
using SR = System.Reflection;
namespace MonoFN.Cecil
{
public interface IMetadataImporterProvider
{
IMetadataImporter GetMetadataImporter(ModuleDefinition module);
}
public interface IMetadataImporter
{
AssemblyNameReference ImportReference(AssemblyNameReference reference);
TypeReference ImportReference(TypeReference type, IGenericParameterProvider context);
FieldReference ImportReference(FieldReference field, IGenericParameterProvider context);
MethodReference ImportReference(MethodReference method, IGenericParameterProvider context);
}
public interface IReflectionImporterProvider
{
IReflectionImporter GetReflectionImporter(ModuleDefinition module);
}
public interface IReflectionImporter
{
AssemblyNameReference ImportReference(SR.AssemblyName reference);
TypeReference ImportReference(Type type, IGenericParameterProvider context);
FieldReference ImportReference(SR.FieldInfo field, IGenericParameterProvider context);
MethodReference ImportReference(SR.MethodBase method, IGenericParameterProvider context);
}
struct ImportGenericContext
{
Collection<IGenericParameterProvider> stack;
public bool IsEmpty { get { return stack == null; } }
public ImportGenericContext(IGenericParameterProvider provider)
{
if (provider == null)
throw new ArgumentNullException("provider");
stack = null;
Push(provider);
}
public void Push(IGenericParameterProvider provider)
{
if (stack == null)
stack = new Collection<IGenericParameterProvider>(1) { provider };
else
stack.Add(provider);
}
public void Pop()
{
stack.RemoveAt(stack.Count - 1);
}
public TypeReference MethodParameter(string method, int position)
{
for (int i = stack.Count - 1; i >= 0; i--)
{
var candidate = stack[i] as MethodReference;
if (candidate == null)
continue;
if (method != NormalizeMethodName(candidate))
continue;
return candidate.GenericParameters[position];
}
throw new InvalidOperationException();
}
public string NormalizeMethodName(MethodReference method)
{
return method.DeclaringType.GetElementType().FullName + "." + method.Name;
}
public TypeReference TypeParameter(string type, int position)
{
for (int i = stack.Count - 1; i >= 0; i--)
{
var candidate = GenericTypeFor(stack[i]);
if (candidate.FullName != type)
continue;
return candidate.GenericParameters[position];
}
throw new InvalidOperationException();
}
static TypeReference GenericTypeFor(IGenericParameterProvider context)
{
var type = context as TypeReference;
if (type != null)
return type.GetElementType();
var method = context as MethodReference;
if (method != null)
return method.DeclaringType.GetElementType();
throw new InvalidOperationException();
}
public static ImportGenericContext For(IGenericParameterProvider context)
{
return context != null ? new ImportGenericContext(context) : default(ImportGenericContext);
}
}
public class DefaultReflectionImporter : IReflectionImporter
{
readonly protected ModuleDefinition module;
public DefaultReflectionImporter(ModuleDefinition module)
{
Mixin.CheckModule(module);
this.module = module;
}
enum ImportGenericKind
{
Definition,
Open,
}
static readonly Dictionary<Type, ElementType> type_etype_mapping = new Dictionary<Type, ElementType>(18) {
{ typeof (void), ElementType.Void },
{ typeof (bool), ElementType.Boolean },
{ typeof (char), ElementType.Char },
{ typeof (sbyte), ElementType.I1 },
{ typeof (byte), ElementType.U1 },
{ typeof (short), ElementType.I2 },
{ typeof (ushort), ElementType.U2 },
{ typeof (int), ElementType.I4 },
{ typeof (uint), ElementType.U4 },
{ typeof (long), ElementType.I8 },
{ typeof (ulong), ElementType.U8 },
{ typeof (float), ElementType.R4 },
{ typeof (double), ElementType.R8 },
{ typeof (string), ElementType.String },
{ typeof (TypedReference), ElementType.TypedByRef },
{ typeof (IntPtr), ElementType.I },
{ typeof (UIntPtr), ElementType.U },
{ typeof (object), ElementType.Object },
};
TypeReference ImportType(Type type, ImportGenericContext context)
{
return ImportType(type, context, ImportGenericKind.Open);
}
TypeReference ImportType(Type type, ImportGenericContext context, ImportGenericKind import_kind)
{
if (IsTypeSpecification(type) || ImportOpenGenericType(type, import_kind))
return ImportTypeSpecification(type, context);
var reference = new TypeReference(
string.Empty,
type.Name,
module,
ImportScope(type),
type.IsValueType);
reference.etype = ImportElementType(type);
if (IsNestedType(type))
reference.DeclaringType = ImportType(type.DeclaringType, context, import_kind);
else
reference.Namespace = type.Namespace ?? string.Empty;
if (type.IsGenericType)
ImportGenericParameters(reference, type.GetGenericArguments());
return reference;
}
protected virtual IMetadataScope ImportScope(Type type)
{
return ImportScope(type.Assembly);
}
static bool ImportOpenGenericType(Type type, ImportGenericKind import_kind)
{
return type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open;
}
static bool ImportOpenGenericMethod(SR.MethodBase method, ImportGenericKind import_kind)
{
return method.IsGenericMethod && method.IsGenericMethodDefinition && import_kind == ImportGenericKind.Open;
}
static bool IsNestedType(Type type)
{
return type.IsNested;
}
TypeReference ImportTypeSpecification(Type type, ImportGenericContext context)
{
if (type.IsByRef)
return new ByReferenceType(ImportType(type.GetElementType(), context));
if (type.IsPointer)
return new PointerType(ImportType(type.GetElementType(), context));
if (type.IsArray)
return new ArrayType(ImportType(type.GetElementType(), context), type.GetArrayRank());
if (type.IsGenericType)
return ImportGenericInstance(type, context);
if (type.IsGenericParameter)
return ImportGenericParameter(type, context);
throw new NotSupportedException(type.FullName);
}
static TypeReference ImportGenericParameter(Type type, ImportGenericContext context)
{
if (context.IsEmpty)
throw new InvalidOperationException();
if (type.DeclaringMethod != null)
return context.MethodParameter(NormalizeMethodName(type.DeclaringMethod), type.GenericParameterPosition);
if (type.DeclaringType != null)
return context.TypeParameter(NormalizeTypeFullName(type.DeclaringType), type.GenericParameterPosition);
throw new InvalidOperationException();
}
static string NormalizeMethodName(SR.MethodBase method)
{
return NormalizeTypeFullName(method.DeclaringType) + "." + method.Name;
}
static string NormalizeTypeFullName(Type type)
{
if (IsNestedType(type))
return NormalizeTypeFullName(type.DeclaringType) + "/" + type.Name;
return type.FullName;
}
TypeReference ImportGenericInstance(Type type, ImportGenericContext context)
{
var element_type = ImportType(type.GetGenericTypeDefinition(), context, ImportGenericKind.Definition);
var arguments = type.GetGenericArguments();
var instance = new GenericInstanceType(element_type, arguments.Length);
var instance_arguments = instance.GenericArguments;
context.Push(element_type);
try
{
for (int i = 0; i < arguments.Length; i++)
instance_arguments.Add(ImportType(arguments[i], context));
return instance;
}
finally
{
context.Pop();
}
}
static bool IsTypeSpecification(Type type)
{
return type.HasElementType
|| IsGenericInstance(type)
|| type.IsGenericParameter;
}
static bool IsGenericInstance(Type type)
{
return type.IsGenericType && !type.IsGenericTypeDefinition;
}
static ElementType ImportElementType(Type type)
{
ElementType etype;
if (!type_etype_mapping.TryGetValue(type, out etype))
return ElementType.None;
return etype;
}
protected AssemblyNameReference ImportScope(SR.Assembly assembly)
{
return ImportReference(assembly.GetName());
}
public virtual AssemblyNameReference ImportReference(SR.AssemblyName name)
{
Mixin.CheckName(name);
AssemblyNameReference reference;
if (TryGetAssemblyNameReference(name, out reference))
return reference;
reference = new AssemblyNameReference(name.Name, name.Version)
{
PublicKeyToken = name.GetPublicKeyToken(),
Culture = name.CultureInfo.Name,
HashAlgorithm = (AssemblyHashAlgorithm)name.HashAlgorithm,
};
module.AssemblyReferences.Add(reference);
return reference;
}
bool TryGetAssemblyNameReference(SR.AssemblyName name, out AssemblyNameReference assembly_reference)
{
var references = module.AssemblyReferences;
for (int i = 0; i < references.Count; i++)
{
var reference = references[i];
if (name.FullName != reference.FullName) // TODO compare field by field
continue;
assembly_reference = reference;
return true;
}
assembly_reference = null;
return false;
}
FieldReference ImportField(SR.FieldInfo field, ImportGenericContext context)
{
var declaring_type = ImportType(field.DeclaringType, context);
if (IsGenericInstance(field.DeclaringType))
field = ResolveFieldDefinition(field);
context.Push(declaring_type);
try
{
return new FieldReference
{
Name = field.Name,
DeclaringType = declaring_type,
FieldType = ImportType(field.FieldType, context),
};
}
finally
{
context.Pop();
}
}
static SR.FieldInfo ResolveFieldDefinition(SR.FieldInfo field)
{
return field.Module.ResolveField(field.MetadataToken);
}
static SR.MethodBase ResolveMethodDefinition(SR.MethodBase method)
{
return method.Module.ResolveMethod(method.MetadataToken);
}
MethodReference ImportMethod(SR.MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
{
if (IsMethodSpecification(method) || ImportOpenGenericMethod(method, import_kind))
return ImportMethodSpecification(method, context);
var declaring_type = ImportType(method.DeclaringType, context);
if (IsGenericInstance(method.DeclaringType))
method = ResolveMethodDefinition(method);
var reference = new MethodReference
{
Name = method.Name,
HasThis = HasCallingConvention(method, SR.CallingConventions.HasThis),
ExplicitThis = HasCallingConvention(method, SR.CallingConventions.ExplicitThis),
DeclaringType = ImportType(method.DeclaringType, context, ImportGenericKind.Definition),
};
if (HasCallingConvention(method, SR.CallingConventions.VarArgs))
reference.CallingConvention &= MethodCallingConvention.VarArg;
if (method.IsGenericMethod)
ImportGenericParameters(reference, method.GetGenericArguments());
context.Push(reference);
try
{
var method_info = method as SR.MethodInfo;
reference.ReturnType = method_info != null
? ImportType(method_info.ReturnType, context)
: ImportType(typeof(void), default(ImportGenericContext));
var parameters = method.GetParameters();
var reference_parameters = reference.Parameters;
for (int i = 0; i < parameters.Length; i++)
reference_parameters.Add(
new ParameterDefinition(ImportType(parameters[i].ParameterType, context)));
reference.DeclaringType = declaring_type;
return reference;
}
finally
{
context.Pop();
}
}
static void ImportGenericParameters(IGenericParameterProvider provider, Type[] arguments)
{
var provider_parameters = provider.GenericParameters;
for (int i = 0; i < arguments.Length; i++)
provider_parameters.Add(new GenericParameter(arguments[i].Name, provider));
}
static bool IsMethodSpecification(SR.MethodBase method)
{
return method.IsGenericMethod && !method.IsGenericMethodDefinition;
}
MethodReference ImportMethodSpecification(SR.MethodBase method, ImportGenericContext context)
{
var method_info = method as SR.MethodInfo;
if (method_info == null)
throw new InvalidOperationException();
var element_method = ImportMethod(method_info.GetGenericMethodDefinition(), context, ImportGenericKind.Definition);
var instance = new GenericInstanceMethod(element_method);
var arguments = method.GetGenericArguments();
var instance_arguments = instance.GenericArguments;
context.Push(element_method);
try
{
for (int i = 0; i < arguments.Length; i++)
instance_arguments.Add(ImportType(arguments[i], context));
return instance;
}
finally
{
context.Pop();
}
}
static bool HasCallingConvention(SR.MethodBase method, SR.CallingConventions conventions)
{
return (method.CallingConvention & conventions) != 0;
}
public virtual TypeReference ImportReference(Type type, IGenericParameterProvider context)
{
Mixin.CheckType(type);
return ImportType(
type,
ImportGenericContext.For(context),
context != null ? ImportGenericKind.Open : ImportGenericKind.Definition);
}
public virtual FieldReference ImportReference(SR.FieldInfo field, IGenericParameterProvider context)
{
Mixin.CheckField(field);
return ImportField(field, ImportGenericContext.For(context));
}
public virtual MethodReference ImportReference(SR.MethodBase method, IGenericParameterProvider context)
{
Mixin.CheckMethod(method);
return ImportMethod(method,
ImportGenericContext.For(context),
context != null ? ImportGenericKind.Open : ImportGenericKind.Definition);
}
}
public class DefaultMetadataImporter : IMetadataImporter
{
readonly protected ModuleDefinition module;
public DefaultMetadataImporter(ModuleDefinition module)
{
Mixin.CheckModule(module);
this.module = module;
}
TypeReference ImportType(TypeReference type, ImportGenericContext context)
{
if (type.IsTypeSpecification())
return ImportTypeSpecification(type, context);
var reference = new TypeReference(
type.Namespace,
type.Name,
module,
ImportScope(type),
type.IsValueType);
MetadataSystem.TryProcessPrimitiveTypeReference(reference);
if (type.IsNested)
reference.DeclaringType = ImportType(type.DeclaringType, context);
if (type.HasGenericParameters)
ImportGenericParameters(reference, type);
return reference;
}
protected virtual IMetadataScope ImportScope(TypeReference type)
{
return ImportScope(type.Scope);
}
protected IMetadataScope ImportScope(IMetadataScope scope)
{
switch (scope.MetadataScopeType)
{
case MetadataScopeType.AssemblyNameReference:
return ImportReference((AssemblyNameReference)scope);
case MetadataScopeType.ModuleDefinition:
if (scope == module) return scope;
return ImportReference(((ModuleDefinition)scope).Assembly.Name);
case MetadataScopeType.ModuleReference:
throw new NotImplementedException();
}
throw new NotSupportedException();
}
public virtual AssemblyNameReference ImportReference(AssemblyNameReference name)
{
Mixin.CheckName(name);
AssemblyNameReference reference;
if (module.TryGetAssemblyNameReference(name, out reference))
return reference;
reference = new AssemblyNameReference(name.Name, name.Version)
{
Culture = name.Culture,
HashAlgorithm = name.HashAlgorithm,
IsRetargetable = name.IsRetargetable,
IsWindowsRuntime = name.IsWindowsRuntime,
};
var pk_token = !name.PublicKeyToken.IsNullOrEmpty()
? new byte[name.PublicKeyToken.Length]
: Empty<byte>.Array;
if (pk_token.Length > 0)
Buffer.BlockCopy(name.PublicKeyToken, 0, pk_token, 0, pk_token.Length);
reference.PublicKeyToken = pk_token;
//Only add if not self.
if (CanAddAssemblyNameReference(module, reference))
module.AssemblyReferences.Add(reference);
return reference;
}
private bool CanAddAssemblyNameReference(ModuleDefinition module, AssemblyNameReference nameRef)
{
return true;
//return (module.assembly.FullName != nameRef.FullName);
}
static void ImportGenericParameters(IGenericParameterProvider imported, IGenericParameterProvider original)
{
var parameters = original.GenericParameters;
var imported_parameters = imported.GenericParameters;
for (int i = 0; i < parameters.Count; i++)
imported_parameters.Add(new GenericParameter(parameters[i].Name, imported));
}
TypeReference ImportTypeSpecification(TypeReference type, ImportGenericContext context)
{
switch (type.etype)
{
case ElementType.SzArray:
var vector = (ArrayType)type;
return new ArrayType(ImportType(vector.ElementType, context));
case ElementType.Ptr:
var pointer = (PointerType)type;
return new PointerType(ImportType(pointer.ElementType, context));
case ElementType.ByRef:
var byref = (ByReferenceType)type;
return new ByReferenceType(ImportType(byref.ElementType, context));
case ElementType.Pinned:
var pinned = (PinnedType)type;
return new PinnedType(ImportType(pinned.ElementType, context));
case ElementType.Sentinel:
var sentinel = (SentinelType)type;
return new SentinelType(ImportType(sentinel.ElementType, context));
case ElementType.FnPtr:
var fnptr = (FunctionPointerType)type;
var imported_fnptr = new FunctionPointerType()
{
HasThis = fnptr.HasThis,
ExplicitThis = fnptr.ExplicitThis,
CallingConvention = fnptr.CallingConvention,
ReturnType = ImportType(fnptr.ReturnType, context),
};
if (!fnptr.HasParameters)
return imported_fnptr;
for (int i = 0; i < fnptr.Parameters.Count; i++)
imported_fnptr.Parameters.Add(new ParameterDefinition(
ImportType(fnptr.Parameters[i].ParameterType, context)));
return imported_fnptr;
case ElementType.CModOpt:
var modopt = (OptionalModifierType)type;
return new OptionalModifierType(
ImportType(modopt.ModifierType, context),
ImportType(modopt.ElementType, context));
case ElementType.CModReqD:
var modreq = (RequiredModifierType)type;
return new RequiredModifierType(
ImportType(modreq.ModifierType, context),
ImportType(modreq.ElementType, context));
case ElementType.Array:
var array = (ArrayType)type;
var imported_array = new ArrayType(ImportType(array.ElementType, context));
if (array.IsVector)
return imported_array;
var dimensions = array.Dimensions;
var imported_dimensions = imported_array.Dimensions;
imported_dimensions.Clear();
for (int i = 0; i < dimensions.Count; i++)
{
var dimension = dimensions[i];
imported_dimensions.Add(new ArrayDimension(dimension.LowerBound, dimension.UpperBound));
}
return imported_array;
case ElementType.GenericInst:
var instance = (GenericInstanceType)type;
var element_type = ImportType(instance.ElementType, context);
var arguments = instance.GenericArguments;
var imported_instance = new GenericInstanceType(element_type, arguments.Count);
var imported_arguments = imported_instance.GenericArguments;
for (int i = 0; i < arguments.Count; i++)
imported_arguments.Add(ImportType(arguments[i], context));
return imported_instance;
case ElementType.Var:
var var_parameter = (GenericParameter)type;
if (var_parameter.DeclaringType == null)
throw new InvalidOperationException();
return context.TypeParameter(var_parameter.DeclaringType.FullName, var_parameter.Position);
case ElementType.MVar:
var mvar_parameter = (GenericParameter)type;
if (mvar_parameter.DeclaringMethod == null)
throw new InvalidOperationException();
return context.MethodParameter(context.NormalizeMethodName(mvar_parameter.DeclaringMethod), mvar_parameter.Position);
}
throw new NotSupportedException(type.etype.ToString());
}
FieldReference ImportField(FieldReference field, ImportGenericContext context)
{
var declaring_type = ImportType(field.DeclaringType, context);
context.Push(declaring_type);
try
{
return new FieldReference
{
Name = field.Name,
DeclaringType = declaring_type,
FieldType = ImportType(field.FieldType, context),
};
}
finally
{
context.Pop();
}
}
MethodReference ImportMethod(MethodReference method, ImportGenericContext context)
{
if (method.IsGenericInstance)
return ImportMethodSpecification(method, context);
var declaring_type = ImportType(method.DeclaringType, context);
var reference = new MethodReference
{
Name = method.Name,
HasThis = method.HasThis,
ExplicitThis = method.ExplicitThis,
DeclaringType = declaring_type,
CallingConvention = method.CallingConvention,
};
if (method.HasGenericParameters)
ImportGenericParameters(reference, method);
context.Push(reference);
try
{
reference.ReturnType = ImportType(method.ReturnType, context);
if (!method.HasParameters)
return reference;
var parameters = method.Parameters;
var reference_parameters = reference.parameters = new ParameterDefinitionCollection(reference, parameters.Count);
for (int i = 0; i < parameters.Count; i++)
reference_parameters.Add(
new ParameterDefinition(ImportType(parameters[i].ParameterType, context)));
return reference;
}
finally
{
context.Pop();
}
}
MethodSpecification ImportMethodSpecification(MethodReference method, ImportGenericContext context)
{
if (!method.IsGenericInstance)
throw new NotSupportedException();
var instance = (GenericInstanceMethod)method;
var element_method = ImportMethod(instance.ElementMethod, context);
var imported_instance = new GenericInstanceMethod(element_method);
var arguments = instance.GenericArguments;
var imported_arguments = imported_instance.GenericArguments;
for (int i = 0; i < arguments.Count; i++)
imported_arguments.Add(ImportType(arguments[i], context));
return imported_instance;
}
public virtual TypeReference ImportReference(TypeReference type, IGenericParameterProvider context)
{
Mixin.CheckType(type);
return ImportType(type, ImportGenericContext.For(context));
}
public virtual FieldReference ImportReference(FieldReference field, IGenericParameterProvider context)
{
Mixin.CheckField(field);
return ImportField(field, ImportGenericContext.For(context));
}
public virtual MethodReference ImportReference(MethodReference method, IGenericParameterProvider context)
{
Mixin.CheckMethod(method);
return ImportMethod(method, ImportGenericContext.For(context));
}
}
static partial class Mixin
{
public static void CheckModule(ModuleDefinition module)
{
if (module == null)
throw new ArgumentNullException(Argument.module.ToString());
}
public static bool TryGetAssemblyNameReference(this ModuleDefinition module, AssemblyNameReference name_reference, out AssemblyNameReference assembly_reference)
{
var references = module.AssemblyReferences;
for (int i = 0; i < references.Count; i++)
{
var reference = references[i];
if (!Equals(name_reference, reference))
continue;
assembly_reference = reference;
return true;
}
assembly_reference = null;
return false;
}
static bool Equals(byte[] a, byte[] b)
{
if (ReferenceEquals(a, b))
return true;
if (a == null)
return false;
if (a.Length != b.Length)
return false;
for (int i = 0; i < a.Length; i++)
if (a[i] != b[i])
return false;
return true;
}
static bool Equals<T>(T a, T b) where T : class, IEquatable<T>
{
if (ReferenceEquals(a, b))
return true;
if (a == null)
return false;
return a.Equals(b);
}
static bool Equals(AssemblyNameReference a, AssemblyNameReference b)
{
if (ReferenceEquals(a, b))
return true;
if (a.Name != b.Name)
return false;
if (!Equals(a.Version, b.Version))
return false;
if (a.Culture != b.Culture)
return false;
if (!Equals(a.PublicKeyToken, b.PublicKeyToken))
return false;
return true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fa57d261f1a90c746abaef3d59b4c655
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public sealed class LinkedResource : Resource {
internal byte [] hash;
string file;
public byte [] Hash {
get { return hash; }
}
public string File {
get { return file; }
set { file = value; }
}
public override ResourceType ResourceType {
get { return ResourceType.Linked; }
}
public LinkedResource (string name, ManifestResourceAttributes flags)
: base (name, flags)
{
}
public LinkedResource (string name, ManifestResourceAttributes flags, string file)
: base (name, flags)
{
this.file = file;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18c45c1a0891fdc40a07d309b564ec6d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
[Flags]
public enum ManifestResourceAttributes : uint {
VisibilityMask = 0x0007,
Public = 0x0001, // The resource is exported from the Assembly
Private = 0x0002 // The resource is private to the Assembly
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 136b98b695702f048857ea31d91193fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,153 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
public class MarshalInfo {
internal NativeType native;
public NativeType NativeType {
get { return native; }
set { native = value; }
}
public MarshalInfo (NativeType native)
{
this.native = native;
}
}
public sealed class ArrayMarshalInfo : MarshalInfo {
internal NativeType element_type;
internal int size_parameter_index;
internal int size;
internal int size_parameter_multiplier;
public NativeType ElementType {
get { return element_type; }
set { element_type = value; }
}
public int SizeParameterIndex {
get { return size_parameter_index; }
set { size_parameter_index = value; }
}
public int Size {
get { return size; }
set { size = value; }
}
public int SizeParameterMultiplier {
get { return size_parameter_multiplier; }
set { size_parameter_multiplier = value; }
}
public ArrayMarshalInfo ()
: base (NativeType.Array)
{
element_type = NativeType.None;
size_parameter_index = -1;
size = -1;
size_parameter_multiplier = -1;
}
}
public sealed class CustomMarshalInfo : MarshalInfo {
internal Guid guid;
internal string unmanaged_type;
internal TypeReference managed_type;
internal string cookie;
public Guid Guid {
get { return guid; }
set { guid = value; }
}
public string UnmanagedType {
get { return unmanaged_type; }
set { unmanaged_type = value; }
}
public TypeReference ManagedType {
get { return managed_type; }
set { managed_type = value; }
}
public string Cookie {
get { return cookie; }
set { cookie = value; }
}
public CustomMarshalInfo ()
: base (NativeType.CustomMarshaler)
{
}
}
public sealed class SafeArrayMarshalInfo : MarshalInfo {
internal VariantType element_type;
public VariantType ElementType {
get { return element_type; }
set { element_type = value; }
}
public SafeArrayMarshalInfo ()
: base (NativeType.SafeArray)
{
element_type = VariantType.None;
}
}
public sealed class FixedArrayMarshalInfo : MarshalInfo {
internal NativeType element_type;
internal int size;
public NativeType ElementType {
get { return element_type; }
set { element_type = value; }
}
public int Size {
get { return size; }
set { size = value; }
}
public FixedArrayMarshalInfo ()
: base (NativeType.FixedArray)
{
element_type = NativeType.None;
}
}
public sealed class FixedSysStringMarshalInfo : MarshalInfo {
internal int size;
public int Size {
get { return size; }
set { size = value; }
}
public FixedSysStringMarshalInfo ()
: base (NativeType.FixedSysString)
{
size = -1;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 081d03dc18ced1648ae4d9f2eefd3370
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
namespace MonoFN.Cecil {
sealed class MemberDefinitionCollection<T> : Collection<T> where T : IMemberDefinition {
TypeDefinition container;
internal MemberDefinitionCollection (TypeDefinition container)
{
this.container = container;
}
internal MemberDefinitionCollection (TypeDefinition container, int capacity)
: base (capacity)
{
this.container = container;
}
protected override void OnAdd (T item, int index)
{
Attach (item);
}
protected sealed override void OnSet (T item, int index)
{
Attach (item);
}
protected sealed override void OnInsert (T item, int index)
{
Attach (item);
}
protected sealed override void OnRemove (T item, int index)
{
Detach (item);
}
protected sealed override void OnClear ()
{
foreach (var definition in this)
Detach (definition);
}
void Attach (T element)
{
if (element.DeclaringType == container)
return;
if (element.DeclaringType != null)
throw new ArgumentException ("Member already attached");
element.DeclaringType = this.container;
}
static void Detach (T element)
{
element.DeclaringType = null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5caa999f42a585459c62b7b65eefdd8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
public abstract class MemberReference : IMetadataTokenProvider {
string name;
TypeReference declaring_type;
internal MetadataToken token;
internal object projection;
public virtual string Name {
get { return name; }
set {
if (IsWindowsRuntimeProjection && value != name)
throw new InvalidOperationException ();
name = value;
}
}
public abstract string FullName {
get;
}
public virtual TypeReference DeclaringType {
get { return declaring_type; }
set { declaring_type = value; }
}
public MetadataToken MetadataToken {
get { return token; }
set { token = value; }
}
public bool IsWindowsRuntimeProjection {
get { return projection != null; }
}
internal bool HasImage {
get {
var module = Module;
if (module == null)
return false;
return module.HasImage;
}
}
public virtual ModuleDefinition Module {
get { return declaring_type != null ? declaring_type.Module : null; }
}
public virtual bool IsDefinition {
get { return false; }
}
public virtual bool ContainsGenericParameter {
get { return declaring_type != null && declaring_type.ContainsGenericParameter; }
}
internal MemberReference ()
{
}
internal MemberReference (string name)
{
this.name = name ?? string.Empty;
}
internal string MemberFullName ()
{
if (declaring_type == null)
return name;
return declaring_type.FullName + "::" + name;
}
public IMemberDefinition Resolve ()
{
return ResolveDefinition ();
}
protected abstract IMemberDefinition ResolveDefinition ();
public override string ToString ()
{
return FullName;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2dcf551ad731c204fa148ec1ee0ce881
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,391 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Collections.Generic;
using System;
namespace MonoFN.Cecil {
public interface IAssemblyResolver : IDisposable {
AssemblyDefinition Resolve (AssemblyNameReference name);
AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters);
}
public interface IMetadataResolver {
TypeDefinition Resolve (TypeReference type);
FieldDefinition Resolve (FieldReference field);
MethodDefinition Resolve (MethodReference method);
}
#if !NET_CORE
[Serializable]
#endif
public sealed class ResolutionException : Exception {
readonly MemberReference member;
public MemberReference Member {
get { return member; }
}
public IMetadataScope Scope {
get {
var type = member as TypeReference;
if (type != null)
return type.Scope;
var declaring_type = member.DeclaringType;
if (declaring_type != null)
return declaring_type.Scope;
throw new NotSupportedException ();
}
}
public ResolutionException (MemberReference member)
: base ("Failed to resolve " + member.FullName)
{
if (member == null)
throw new ArgumentNullException ("member");
this.member = member;
}
public ResolutionException (MemberReference member, Exception innerException)
: base ("Failed to resolve " + member.FullName, innerException)
{
if (member == null)
throw new ArgumentNullException ("member");
this.member = member;
}
#if !NET_CORE
ResolutionException (
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base (info, context)
{
}
#endif
}
public class MetadataResolver : IMetadataResolver {
readonly IAssemblyResolver assembly_resolver;
public IAssemblyResolver AssemblyResolver {
get { return assembly_resolver; }
}
public MetadataResolver (IAssemblyResolver assemblyResolver)
{
if (assemblyResolver == null)
throw new ArgumentNullException ("assemblyResolver");
assembly_resolver = assemblyResolver;
}
public virtual TypeDefinition Resolve (TypeReference type)
{
Mixin.CheckType (type);
type = type.GetElementType ();
var scope = type.Scope;
if (scope == null)
return null;
switch (scope.MetadataScopeType) {
case MetadataScopeType.AssemblyNameReference:
var assembly = assembly_resolver.Resolve ((AssemblyNameReference)scope);
if (assembly == null)
return null;
return GetType (assembly.MainModule, type);
case MetadataScopeType.ModuleDefinition:
return GetType ((ModuleDefinition)scope, type);
case MetadataScopeType.ModuleReference:
if (type.Module.Assembly == null)
return null;
var modules = type.Module.Assembly.Modules;
var module_ref = (ModuleReference)scope;
for (int i = 0; i < modules.Count; i++) {
var netmodule = modules [i];
if (netmodule.Name == module_ref.Name)
return GetType (netmodule, type);
}
break;
}
throw new NotSupportedException ();
}
static TypeDefinition GetType (ModuleDefinition module, TypeReference reference)
{
var type = GetTypeDefinition (module, reference);
if (type != null)
return type;
if (!module.HasExportedTypes)
return null;
var exported_types = module.ExportedTypes;
for (int i = 0; i < exported_types.Count; i++) {
var exported_type = exported_types [i];
if (exported_type.Name != reference.Name)
continue;
if (exported_type.Namespace != reference.Namespace)
continue;
return exported_type.Resolve ();
}
return null;
}
static TypeDefinition GetTypeDefinition (ModuleDefinition module, TypeReference type)
{
if (!type.IsNested)
return module.GetType (type.Namespace, type.Name);
var declaring_type = type.DeclaringType.Resolve ();
if (declaring_type == null)
return null;
return declaring_type.GetNestedType (type.TypeFullName ());
}
public virtual FieldDefinition Resolve (FieldReference field)
{
Mixin.CheckField (field);
var type = Resolve (field.DeclaringType);
if (type == null)
return null;
if (!type.HasFields)
return null;
return GetField (type, field);
}
FieldDefinition GetField (TypeDefinition type, FieldReference reference)
{
while (type != null) {
var field = GetField (type.Fields, reference);
if (field != null)
return field;
if (type.BaseType == null)
return null;
type = Resolve (type.BaseType);
}
return null;
}
static FieldDefinition GetField (Collection<FieldDefinition> fields, FieldReference reference)
{
for (int i = 0; i < fields.Count; i++) {
var field = fields [i];
if (field.Name != reference.Name)
continue;
if (!AreSame (field.FieldType, reference.FieldType))
continue;
return field;
}
return null;
}
public virtual MethodDefinition Resolve (MethodReference method)
{
Mixin.CheckMethod (method);
var type = Resolve (method.DeclaringType);
if (type == null)
return null;
method = method.GetElementMethod ();
if (!type.HasMethods)
return null;
return GetMethod (type, method);
}
MethodDefinition GetMethod (TypeDefinition type, MethodReference reference)
{
while (type != null) {
var method = GetMethod (type.Methods, reference);
if (method != null)
return method;
if (type.BaseType == null)
return null;
type = Resolve (type.BaseType);
}
return null;
}
public static MethodDefinition GetMethod (Collection<MethodDefinition> methods, MethodReference reference)
{
for (int i = 0; i < methods.Count; i++) {
var method = methods [i];
if (method.Name != reference.Name)
continue;
if (method.HasGenericParameters != reference.HasGenericParameters)
continue;
if (method.HasGenericParameters && method.GenericParameters.Count != reference.GenericParameters.Count)
continue;
if (!AreSame (method.ReturnType, reference.ReturnType))
continue;
if (method.IsVarArg () != reference.IsVarArg ())
continue;
if (method.IsVarArg () && IsVarArgCallTo (method, reference))
return method;
if (method.HasParameters != reference.HasParameters)
continue;
if (!method.HasParameters && !reference.HasParameters)
return method;
if (!AreSame (method.Parameters, reference.Parameters))
continue;
return method;
}
return null;
}
static bool AreSame (Collection<ParameterDefinition> a, Collection<ParameterDefinition> b)
{
var count = a.Count;
if (count != b.Count)
return false;
if (count == 0)
return true;
for (int i = 0; i < count; i++)
if (!AreSame (a [i].ParameterType, b [i].ParameterType))
return false;
return true;
}
static bool IsVarArgCallTo (MethodDefinition method, MethodReference reference)
{
if (method.Parameters.Count >= reference.Parameters.Count)
return false;
if (reference.GetSentinelPosition () != method.Parameters.Count)
return false;
for (int i = 0; i < method.Parameters.Count; i++)
if (!AreSame (method.Parameters [i].ParameterType, reference.Parameters [i].ParameterType))
return false;
return true;
}
static bool AreSame (TypeSpecification a, TypeSpecification b)
{
if (!AreSame (a.ElementType, b.ElementType))
return false;
if (a.IsGenericInstance)
return AreSame ((GenericInstanceType)a, (GenericInstanceType)b);
if (a.IsRequiredModifier || a.IsOptionalModifier)
return AreSame ((IModifierType)a, (IModifierType)b);
if (a.IsArray)
return AreSame ((ArrayType)a, (ArrayType)b);
return true;
}
static bool AreSame (ArrayType a, ArrayType b)
{
if (a.Rank != b.Rank)
return false;
// TODO: dimensions
return true;
}
static bool AreSame (IModifierType a, IModifierType b)
{
return AreSame (a.ModifierType, b.ModifierType);
}
static bool AreSame (GenericInstanceType a, GenericInstanceType b)
{
if (a.GenericArguments.Count != b.GenericArguments.Count)
return false;
for (int i = 0; i < a.GenericArguments.Count; i++)
if (!AreSame (a.GenericArguments [i], b.GenericArguments [i]))
return false;
return true;
}
static bool AreSame (GenericParameter a, GenericParameter b)
{
return a.Position == b.Position;
}
static bool AreSame (TypeReference a, TypeReference b)
{
if (ReferenceEquals (a, b))
return true;
if (a == null || b == null)
return false;
if (a.etype != b.etype)
return false;
if (a.IsGenericParameter)
return AreSame ((GenericParameter)a, (GenericParameter)b);
if (a.IsTypeSpecification ())
return AreSame ((TypeSpecification)a, (TypeSpecification)b);
if (a.Name != b.Name || a.Namespace != b.Namespace)
return false;
return AreSame (a.DeclaringType, b.DeclaringType);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fdd2c926d773ffd4692e2d042135fd2b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,431 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Cecil.Cil;
using MonoFN.Cecil.Metadata;
using MonoFN.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading;
namespace MonoFN.Cecil {
struct Range {
public uint Start;
public uint Length;
public Range (uint index, uint length)
{
this.Start = index;
this.Length = length;
}
}
sealed class MetadataSystem {
internal AssemblyNameReference [] AssemblyReferences;
internal ModuleReference [] ModuleReferences;
internal TypeDefinition [] Types;
internal TypeReference [] TypeReferences;
internal FieldDefinition [] Fields;
internal MethodDefinition [] Methods;
internal MemberReference [] MemberReferences;
internal Dictionary<uint, Collection<uint>> NestedTypes;
internal Dictionary<uint, uint> ReverseNestedTypes;
internal Dictionary<uint, Collection<Row<uint, MetadataToken>>> Interfaces;
internal Dictionary<uint, Row<ushort, uint>> ClassLayouts;
internal Dictionary<uint, uint> FieldLayouts;
internal Dictionary<uint, uint> FieldRVAs;
internal Dictionary<MetadataToken, uint> FieldMarshals;
internal Dictionary<MetadataToken, Row<ElementType, uint>> Constants;
internal Dictionary<uint, Collection<MetadataToken>> Overrides;
internal Dictionary<MetadataToken, Range []> CustomAttributes;
internal Dictionary<MetadataToken, Range []> SecurityDeclarations;
internal Dictionary<uint, Range> Events;
internal Dictionary<uint, Range> Properties;
internal Dictionary<uint, Row<MethodSemanticsAttributes, MetadataToken>> Semantics;
internal Dictionary<uint, Row<PInvokeAttributes, uint, uint>> PInvokes;
internal Dictionary<MetadataToken, Range []> GenericParameters;
internal Dictionary<uint, Collection<Row<uint, MetadataToken>>> GenericConstraints;
internal Document [] Documents;
internal Dictionary<uint, Collection<Row<uint, Range, Range, uint, uint, uint>>> LocalScopes;
internal ImportDebugInformation [] ImportScopes;
internal Dictionary<uint, uint> StateMachineMethods;
internal Dictionary<MetadataToken, Row<Guid, uint, uint> []> CustomDebugInformations;
static Dictionary<string, Row<ElementType, bool>> primitive_value_types;
static void InitializePrimitives ()
{
var types = new Dictionary<string, Row<ElementType, bool>> (18, StringComparer.Ordinal) {
{ "Void", new Row<ElementType, bool> (ElementType.Void, false) },
{ "Boolean", new Row<ElementType, bool> (ElementType.Boolean, true) },
{ "Char", new Row<ElementType, bool> (ElementType.Char, true) },
{ "SByte", new Row<ElementType, bool> (ElementType.I1, true) },
{ "Byte", new Row<ElementType, bool> (ElementType.U1, true) },
{ "Int16", new Row<ElementType, bool> (ElementType.I2, true) },
{ "UInt16", new Row<ElementType, bool> (ElementType.U2, true) },
{ "Int32", new Row<ElementType, bool> (ElementType.I4, true) },
{ "UInt32", new Row<ElementType, bool> (ElementType.U4, true) },
{ "Int64", new Row<ElementType, bool> (ElementType.I8, true) },
{ "UInt64", new Row<ElementType, bool> (ElementType.U8, true) },
{ "Single", new Row<ElementType, bool> (ElementType.R4, true) },
{ "Double", new Row<ElementType, bool> (ElementType.R8, true) },
{ "String", new Row<ElementType, bool> (ElementType.String, false) },
{ "TypedReference", new Row<ElementType, bool> (ElementType.TypedByRef, false) },
{ "IntPtr", new Row<ElementType, bool> (ElementType.I, true) },
{ "UIntPtr", new Row<ElementType, bool> (ElementType.U, true) },
{ "Object", new Row<ElementType, bool> (ElementType.Object, false) },
};
Interlocked.CompareExchange (ref primitive_value_types, types, null);
}
public static void TryProcessPrimitiveTypeReference (TypeReference type)
{
if (type.Namespace != "System")
return;
var scope = type.scope;
if (scope == null || scope.MetadataScopeType != MetadataScopeType.AssemblyNameReference)
return;
Row<ElementType, bool> primitive_data;
if (!TryGetPrimitiveData (type, out primitive_data))
return;
type.etype = primitive_data.Col1;
type.IsValueType = primitive_data.Col2;
}
public static bool TryGetPrimitiveElementType (TypeDefinition type, out ElementType etype)
{
etype = ElementType.None;
if (type.Namespace != "System")
return false;
Row<ElementType, bool> primitive_data;
if (TryGetPrimitiveData (type, out primitive_data)) {
etype = primitive_data.Col1;
return true;
}
return false;
}
static bool TryGetPrimitiveData (TypeReference type, out Row<ElementType, bool> primitive_data)
{
if (primitive_value_types == null)
InitializePrimitives ();
return primitive_value_types.TryGetValue (type.Name, out primitive_data);
}
public void Clear ()
{
if (NestedTypes != null) NestedTypes = new Dictionary<uint, Collection<uint>> (capacity: 0);
if (ReverseNestedTypes != null) ReverseNestedTypes = new Dictionary<uint, uint> (capacity: 0);
if (Interfaces != null) Interfaces = new Dictionary<uint, Collection<Row<uint, MetadataToken>>> (capacity: 0);
if (ClassLayouts != null) ClassLayouts = new Dictionary<uint, Row<ushort, uint>> (capacity: 0);
if (FieldLayouts != null) FieldLayouts = new Dictionary<uint, uint> (capacity: 0);
if (FieldRVAs != null) FieldRVAs = new Dictionary<uint, uint> (capacity: 0);
if (FieldMarshals != null) FieldMarshals = new Dictionary<MetadataToken, uint> (capacity: 0);
if (Constants != null) Constants = new Dictionary<MetadataToken, Row<ElementType, uint>> (capacity: 0);
if (Overrides != null) Overrides = new Dictionary<uint, Collection<MetadataToken>> (capacity: 0);
if (CustomAttributes != null) CustomAttributes = new Dictionary<MetadataToken, Range []> (capacity: 0);
if (SecurityDeclarations != null) SecurityDeclarations = new Dictionary<MetadataToken, Range []> (capacity: 0);
if (Events != null) Events = new Dictionary<uint, Range> (capacity: 0);
if (Properties != null) Properties = new Dictionary<uint, Range> (capacity: 0);
if (Semantics != null) Semantics = new Dictionary<uint, Row<MethodSemanticsAttributes, MetadataToken>> (capacity: 0);
if (PInvokes != null) PInvokes = new Dictionary<uint, Row<PInvokeAttributes, uint, uint>> (capacity: 0);
if (GenericParameters != null) GenericParameters = new Dictionary<MetadataToken, Range []> (capacity: 0);
if (GenericConstraints != null) GenericConstraints = new Dictionary<uint, Collection<Row<uint, MetadataToken>>> (capacity: 0);
Documents = Empty<Document>.Array;
ImportScopes = Empty<ImportDebugInformation>.Array;
if (LocalScopes != null) LocalScopes = new Dictionary<uint, Collection<Row<uint, Range, Range, uint, uint, uint>>> (capacity: 0);
if (StateMachineMethods != null) StateMachineMethods = new Dictionary<uint, uint> (capacity: 0);
}
public AssemblyNameReference GetAssemblyNameReference (uint rid)
{
if (rid < 1 || rid > AssemblyReferences.Length)
return null;
return AssemblyReferences [rid - 1];
}
public TypeDefinition GetTypeDefinition (uint rid)
{
if (rid < 1 || rid > Types.Length)
return null;
return Types [rid - 1];
}
public void AddTypeDefinition (TypeDefinition type)
{
Types [type.token.RID - 1] = type;
}
public TypeReference GetTypeReference (uint rid)
{
if (rid < 1 || rid > TypeReferences.Length)
return null;
return TypeReferences [rid - 1];
}
public void AddTypeReference (TypeReference type)
{
TypeReferences [type.token.RID - 1] = type;
}
public FieldDefinition GetFieldDefinition (uint rid)
{
if (rid < 1 || rid > Fields.Length)
return null;
return Fields [rid - 1];
}
public void AddFieldDefinition (FieldDefinition field)
{
Fields [field.token.RID - 1] = field;
}
public MethodDefinition GetMethodDefinition (uint rid)
{
if (rid < 1 || rid > Methods.Length)
return null;
return Methods [rid - 1];
}
public void AddMethodDefinition (MethodDefinition method)
{
Methods [method.token.RID - 1] = method;
}
public MemberReference GetMemberReference (uint rid)
{
if (rid < 1 || rid > MemberReferences.Length)
return null;
return MemberReferences [rid - 1];
}
public void AddMemberReference (MemberReference member)
{
MemberReferences [member.token.RID - 1] = member;
}
public bool TryGetNestedTypeMapping (TypeDefinition type, out Collection<uint> mapping)
{
return NestedTypes.TryGetValue (type.token.RID, out mapping);
}
public void SetNestedTypeMapping (uint type_rid, Collection<uint> mapping)
{
NestedTypes [type_rid] = mapping;
}
public void RemoveNestedTypeMapping (TypeDefinition type)
{
NestedTypes.Remove (type.token.RID);
}
public bool TryGetReverseNestedTypeMapping (TypeDefinition type, out uint declaring)
{
return ReverseNestedTypes.TryGetValue (type.token.RID, out declaring);
}
public void SetReverseNestedTypeMapping (uint nested, uint declaring)
{
ReverseNestedTypes [nested] = declaring;
}
public void RemoveReverseNestedTypeMapping (TypeDefinition type)
{
ReverseNestedTypes.Remove (type.token.RID);
}
public bool TryGetInterfaceMapping (TypeDefinition type, out Collection<Row<uint, MetadataToken>> mapping)
{
return Interfaces.TryGetValue (type.token.RID, out mapping);
}
public void SetInterfaceMapping (uint type_rid, Collection<Row<uint, MetadataToken>> mapping)
{
Interfaces [type_rid] = mapping;
}
public void RemoveInterfaceMapping (TypeDefinition type)
{
Interfaces.Remove (type.token.RID);
}
public void AddPropertiesRange (uint type_rid, Range range)
{
Properties.Add (type_rid, range);
}
public bool TryGetPropertiesRange (TypeDefinition type, out Range range)
{
return Properties.TryGetValue (type.token.RID, out range);
}
public void RemovePropertiesRange (TypeDefinition type)
{
Properties.Remove (type.token.RID);
}
public void AddEventsRange (uint type_rid, Range range)
{
Events.Add (type_rid, range);
}
public bool TryGetEventsRange (TypeDefinition type, out Range range)
{
return Events.TryGetValue (type.token.RID, out range);
}
public void RemoveEventsRange (TypeDefinition type)
{
Events.Remove (type.token.RID);
}
public bool TryGetGenericParameterRanges (IGenericParameterProvider owner, out Range [] ranges)
{
return GenericParameters.TryGetValue (owner.MetadataToken, out ranges);
}
public void RemoveGenericParameterRange (IGenericParameterProvider owner)
{
GenericParameters.Remove (owner.MetadataToken);
}
public bool TryGetCustomAttributeRanges (ICustomAttributeProvider owner, out Range [] ranges)
{
return CustomAttributes.TryGetValue (owner.MetadataToken, out ranges);
}
public void RemoveCustomAttributeRange (ICustomAttributeProvider owner)
{
CustomAttributes.Remove (owner.MetadataToken);
}
public bool TryGetSecurityDeclarationRanges (ISecurityDeclarationProvider owner, out Range [] ranges)
{
return SecurityDeclarations.TryGetValue (owner.MetadataToken, out ranges);
}
public void RemoveSecurityDeclarationRange (ISecurityDeclarationProvider owner)
{
SecurityDeclarations.Remove (owner.MetadataToken);
}
public bool TryGetGenericConstraintMapping (GenericParameter generic_parameter, out Collection<Row<uint, MetadataToken>> mapping)
{
return GenericConstraints.TryGetValue (generic_parameter.token.RID, out mapping);
}
public void SetGenericConstraintMapping (uint gp_rid, Collection<Row<uint, MetadataToken>> mapping)
{
GenericConstraints [gp_rid] = mapping;
}
public void RemoveGenericConstraintMapping (GenericParameter generic_parameter)
{
GenericConstraints.Remove (generic_parameter.token.RID);
}
public bool TryGetOverrideMapping (MethodDefinition method, out Collection<MetadataToken> mapping)
{
return Overrides.TryGetValue (method.token.RID, out mapping);
}
public void SetOverrideMapping (uint rid, Collection<MetadataToken> mapping)
{
Overrides [rid] = mapping;
}
public void RemoveOverrideMapping (MethodDefinition method)
{
Overrides.Remove (method.token.RID);
}
public Document GetDocument (uint rid)
{
if (rid < 1 || rid > Documents.Length)
return null;
return Documents [rid - 1];
}
public bool TryGetLocalScopes (MethodDefinition method, out Collection<Row<uint, Range, Range, uint, uint, uint>> scopes)
{
return LocalScopes.TryGetValue (method.MetadataToken.RID, out scopes);
}
public void SetLocalScopes (uint method_rid, Collection<Row<uint, Range, Range, uint, uint, uint>> records)
{
LocalScopes [method_rid] = records;
}
public ImportDebugInformation GetImportScope (uint rid)
{
if (rid < 1 || rid > ImportScopes.Length)
return null;
return ImportScopes [rid - 1];
}
public bool TryGetStateMachineKickOffMethod (MethodDefinition method, out uint rid)
{
return StateMachineMethods.TryGetValue (method.MetadataToken.RID, out rid);
}
public TypeDefinition GetFieldDeclaringType (uint field_rid)
{
return BinaryRangeSearch (Types, field_rid, true);
}
public TypeDefinition GetMethodDeclaringType (uint method_rid)
{
return BinaryRangeSearch (Types, method_rid, false);
}
static TypeDefinition BinaryRangeSearch (TypeDefinition [] types, uint rid, bool field)
{
int min = 0;
int max = types.Length - 1;
while (min <= max) {
int mid = min + ((max - min) / 2);
var type = types [mid];
var range = field ? type.fields_range : type.methods_range;
if (rid < range.Start)
max = mid - 1;
else if (rid >= range.Start + range.Length)
min = mid + 1;
else
return type;
}
return null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6ea39c5122499d14fbca126d3ed39890
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil {
[Flags]
public enum MethodAttributes : ushort {
MemberAccessMask = 0x0007,
CompilerControlled = 0x0000, // Member not referenceable
Private = 0x0001, // Accessible only by the parent type
FamANDAssem = 0x0002, // Accessible by sub-types only in this Assembly
Assembly = 0x0003, // Accessibly by anyone in the Assembly
Family = 0x0004, // Accessible only by type and sub-types
FamORAssem = 0x0005, // Accessibly by sub-types anywhere, plus anyone in assembly
Public = 0x0006, // Accessibly by anyone who has visibility to this scope
Static = 0x0010, // Defined on type, else per instance
Final = 0x0020, // Method may not be overridden
Virtual = 0x0040, // Method is virtual
HideBySig = 0x0080, // Method hides by name+sig, else just by name
VtableLayoutMask = 0x0100, // Use this mask to retrieve vtable attributes
ReuseSlot = 0x0000, // Method reuses existing slot in vtable
NewSlot = 0x0100, // Method always gets a new slot in the vtable
CheckAccessOnOverride = 0x0200, // Method can only be overriden if also accessible
Abstract = 0x0400, // Method does not provide an implementation
SpecialName = 0x0800, // Method is special
// Interop Attributes
PInvokeImpl = 0x2000, // Implementation is forwarded through PInvoke
UnmanagedExport = 0x0008, // Reserved: shall be zero for conforming implementations
// Additional flags
RTSpecialName = 0x1000, // CLI provides 'special' behavior, depending upon the name of the method
HasSecurity = 0x4000, // Method has security associate with it
RequireSecObject = 0x8000 // Method calls another method containing security code
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 84996fdfc826be145836c454e3781c51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
namespace MonoFN.Cecil {
public enum MethodCallingConvention : byte {
Default = 0x0,
C = 0x1,
StdCall = 0x2,
ThisCall = 0x3,
FastCall = 0x4,
VarArg = 0x5,
Generic = 0x10,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d279830051a3cf4a9a8198756171875
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,558 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Cecil.Cil;
using MonoFN.Collections.Generic;
using System;
using System.Threading;
using RVA = System.UInt32;
namespace MonoFN.Cecil {
public sealed class MethodDefinition : MethodReference, IMemberDefinition, ISecurityDeclarationProvider, ICustomDebugInformationProvider {
ushort attributes;
ushort impl_attributes;
internal volatile bool sem_attrs_ready;
internal MethodSemanticsAttributes sem_attrs;
Collection<CustomAttribute> custom_attributes;
Collection<SecurityDeclaration> security_declarations;
internal RVA rva;
internal PInvokeInfo pinvoke;
Collection<MethodReference> overrides;
internal MethodBody body;
internal MethodDebugInformation debug_info;
internal Collection<CustomDebugInformation> custom_infos;
public override string Name {
get { return base.Name; }
set {
if (IsWindowsRuntimeProjection && value != base.Name)
throw new InvalidOperationException ();
base.Name = value;
}
}
public MethodAttributes Attributes {
get { return (MethodAttributes)attributes; }
set {
if (IsWindowsRuntimeProjection && (ushort)value != attributes)
throw new InvalidOperationException ();
attributes = (ushort)value;
}
}
public MethodImplAttributes ImplAttributes {
get { return (MethodImplAttributes)impl_attributes; }
set {
if (IsWindowsRuntimeProjection && (ushort)value != impl_attributes)
throw new InvalidOperationException ();
impl_attributes = (ushort)value;
}
}
public MethodSemanticsAttributes SemanticsAttributes {
get {
if (sem_attrs_ready)
return sem_attrs;
if (HasImage) {
ReadSemantics ();
return sem_attrs;
}
sem_attrs = MethodSemanticsAttributes.None;
sem_attrs_ready = true;
return sem_attrs;
}
set { sem_attrs = value; }
}
internal MethodDefinitionProjection WindowsRuntimeProjection {
get { return (MethodDefinitionProjection)projection; }
set { projection = value; }
}
internal void ReadSemantics ()
{
if (sem_attrs_ready)
return;
var module = this.Module;
if (module == null)
return;
if (!module.HasImage)
return;
lock (module.SyncRoot) {
if (sem_attrs_ready)
return;
module.Read (this, (method, reader) => reader.ReadAllSemantics (method));
}
}
public bool HasSecurityDeclarations {
get {
if (security_declarations != null)
return security_declarations.Count > 0;
return this.GetHasSecurityDeclarations (Module);
}
}
public Collection<SecurityDeclaration> SecurityDeclarations {
get { return security_declarations ?? (this.GetSecurityDeclarations (ref security_declarations, Module)); }
}
public bool HasCustomAttributes {
get {
if (custom_attributes != null)
return custom_attributes.Count > 0;
return this.GetHasCustomAttributes (Module);
}
}
public Collection<CustomAttribute> CustomAttributes {
get { return custom_attributes ?? (this.GetCustomAttributes (ref custom_attributes, Module)); }
}
public int RVA {
get { return (int)rva; }
}
public bool HasBody {
get {
return (attributes & (ushort)MethodAttributes.Abstract) == 0 &&
(attributes & (ushort)MethodAttributes.PInvokeImpl) == 0 &&
(impl_attributes & (ushort)MethodImplAttributes.InternalCall) == 0 &&
(impl_attributes & (ushort)MethodImplAttributes.Native) == 0 &&
(impl_attributes & (ushort)MethodImplAttributes.Unmanaged) == 0 &&
(impl_attributes & (ushort)MethodImplAttributes.Runtime) == 0;
}
}
public MethodBody Body {
get {
var local = this.body;
if (local != null)
return local;
if (!HasBody)
return null;
if (HasImage && rva != 0)
return Module.Read (ref body, this, (method, reader) => reader.ReadMethodBody (method));
Interlocked.CompareExchange (ref body, new MethodBody (this), null);
return body;
}
set {
var module = this.Module;
if (module == null) {
body = value;
return;
}
// we reset Body to null in ILSpy to save memory; so we need that operation to be thread-safe
lock (module.SyncRoot) {
body = value;
if (value == null)
this.debug_info = null;
}
}
}
public MethodDebugInformation DebugInformation {
get {
Mixin.Read (Body);
if (debug_info == null) {
Interlocked.CompareExchange (ref debug_info, new MethodDebugInformation (this), null);
}
return debug_info;
}
set {
debug_info = value;
}
}
public bool HasPInvokeInfo {
get {
if (pinvoke != null)
return true;
return IsPInvokeImpl;
}
}
public PInvokeInfo PInvokeInfo {
get {
if (pinvoke != null)
return pinvoke;
if (HasImage && IsPInvokeImpl)
return Module.Read (ref pinvoke, this, (method, reader) => reader.ReadPInvokeInfo (method));
return null;
}
set {
IsPInvokeImpl = true;
pinvoke = value;
}
}
public bool HasOverrides {
get {
if (overrides != null)
return overrides.Count > 0;
return HasImage && Module.Read (this, (method, reader) => reader.HasOverrides (method));
}
}
public Collection<MethodReference> Overrides {
get {
if (overrides != null)
return overrides;
if (HasImage)
return Module.Read (ref overrides, this, (method, reader) => reader.ReadOverrides (method));
Interlocked.CompareExchange (ref overrides, new Collection<MethodReference> (), null);
return overrides;
}
}
public override bool HasGenericParameters {
get {
if (generic_parameters != null)
return generic_parameters.Count > 0;
return this.GetHasGenericParameters (Module);
}
}
public override Collection<GenericParameter> GenericParameters {
get { return generic_parameters ?? (this.GetGenericParameters (ref generic_parameters, Module)); }
}
public bool HasCustomDebugInformations {
get {
Mixin.Read (Body);
return !custom_infos.IsNullOrEmpty ();
}
}
public Collection<CustomDebugInformation> CustomDebugInformations {
get {
Mixin.Read (Body);
if (custom_infos == null)
Interlocked.CompareExchange (ref custom_infos, new Collection<CustomDebugInformation> (), null);
return custom_infos;
}
}
#region MethodAttributes
public bool IsCompilerControlled {
get { return attributes.GetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.CompilerControlled); }
set { attributes = attributes.SetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.CompilerControlled, value); }
}
public bool IsPrivate {
get { return attributes.GetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.Private); }
set { attributes = attributes.SetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.Private, value); }
}
public bool IsFamilyAndAssembly {
get { return attributes.GetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.FamANDAssem); }
set { attributes = attributes.SetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.FamANDAssem, value); }
}
public bool IsAssembly {
get { return attributes.GetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.Assembly); }
set { attributes = attributes.SetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.Assembly, value); }
}
public bool IsFamily {
get { return attributes.GetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.Family); }
set { attributes = attributes.SetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.Family, value); }
}
public bool IsFamilyOrAssembly {
get { return attributes.GetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.FamORAssem); }
set { attributes = attributes.SetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.FamORAssem, value); }
}
public bool IsPublic {
get { return attributes.GetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.Public); }
set { attributes = attributes.SetMaskedAttributes ((ushort)MethodAttributes.MemberAccessMask, (ushort)MethodAttributes.Public, value); }
}
public bool IsStatic {
get { return attributes.GetAttributes ((ushort)MethodAttributes.Static); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.Static, value); }
}
public bool IsFinal {
get { return attributes.GetAttributes ((ushort)MethodAttributes.Final); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.Final, value); }
}
public bool IsVirtual {
get { return attributes.GetAttributes ((ushort)MethodAttributes.Virtual); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.Virtual, value); }
}
public bool IsHideBySig {
get { return attributes.GetAttributes ((ushort)MethodAttributes.HideBySig); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.HideBySig, value); }
}
public bool IsReuseSlot {
get { return attributes.GetMaskedAttributes ((ushort)MethodAttributes.VtableLayoutMask, (ushort)MethodAttributes.ReuseSlot); }
set { attributes = attributes.SetMaskedAttributes ((ushort)MethodAttributes.VtableLayoutMask, (ushort)MethodAttributes.ReuseSlot, value); }
}
public bool IsNewSlot {
get { return attributes.GetMaskedAttributes ((ushort)MethodAttributes.VtableLayoutMask, (ushort)MethodAttributes.NewSlot); }
set { attributes = attributes.SetMaskedAttributes ((ushort)MethodAttributes.VtableLayoutMask, (ushort)MethodAttributes.NewSlot, value); }
}
public bool IsCheckAccessOnOverride {
get { return attributes.GetAttributes ((ushort)MethodAttributes.CheckAccessOnOverride); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.CheckAccessOnOverride, value); }
}
public bool IsAbstract {
get { return attributes.GetAttributes ((ushort)MethodAttributes.Abstract); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.Abstract, value); }
}
public bool IsSpecialName {
get { return attributes.GetAttributes ((ushort)MethodAttributes.SpecialName); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.SpecialName, value); }
}
public bool IsPInvokeImpl {
get { return attributes.GetAttributes ((ushort)MethodAttributes.PInvokeImpl); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.PInvokeImpl, value); }
}
public bool IsUnmanagedExport {
get { return attributes.GetAttributes ((ushort)MethodAttributes.UnmanagedExport); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.UnmanagedExport, value); }
}
public bool IsRuntimeSpecialName {
get { return attributes.GetAttributes ((ushort)MethodAttributes.RTSpecialName); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.RTSpecialName, value); }
}
public bool HasSecurity {
get { return attributes.GetAttributes ((ushort)MethodAttributes.HasSecurity); }
set { attributes = attributes.SetAttributes ((ushort)MethodAttributes.HasSecurity, value); }
}
#endregion
#region MethodImplAttributes
public bool IsIL {
get { return impl_attributes.GetMaskedAttributes ((ushort)MethodImplAttributes.CodeTypeMask, (ushort)MethodImplAttributes.IL); }
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort)MethodImplAttributes.CodeTypeMask, (ushort)MethodImplAttributes.IL, value); }
}
public bool IsNative {
get { return impl_attributes.GetMaskedAttributes ((ushort)MethodImplAttributes.CodeTypeMask, (ushort)MethodImplAttributes.Native); }
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort)MethodImplAttributes.CodeTypeMask, (ushort)MethodImplAttributes.Native, value); }
}
public bool IsRuntime {
get { return impl_attributes.GetMaskedAttributes ((ushort)MethodImplAttributes.CodeTypeMask, (ushort)MethodImplAttributes.Runtime); }
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort)MethodImplAttributes.CodeTypeMask, (ushort)MethodImplAttributes.Runtime, value); }
}
public bool IsUnmanaged {
get { return impl_attributes.GetMaskedAttributes ((ushort)MethodImplAttributes.ManagedMask, (ushort)MethodImplAttributes.Unmanaged); }
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort)MethodImplAttributes.ManagedMask, (ushort)MethodImplAttributes.Unmanaged, value); }
}
public bool IsManaged {
get { return impl_attributes.GetMaskedAttributes ((ushort)MethodImplAttributes.ManagedMask, (ushort)MethodImplAttributes.Managed); }
set { impl_attributes = impl_attributes.SetMaskedAttributes ((ushort)MethodImplAttributes.ManagedMask, (ushort)MethodImplAttributes.Managed, value); }
}
public bool IsForwardRef {
get { return impl_attributes.GetAttributes ((ushort)MethodImplAttributes.ForwardRef); }
set { impl_attributes = impl_attributes.SetAttributes ((ushort)MethodImplAttributes.ForwardRef, value); }
}
public bool IsPreserveSig {
get { return impl_attributes.GetAttributes ((ushort)MethodImplAttributes.PreserveSig); }
set { impl_attributes = impl_attributes.SetAttributes ((ushort)MethodImplAttributes.PreserveSig, value); }
}
public bool IsInternalCall {
get { return impl_attributes.GetAttributes ((ushort)MethodImplAttributes.InternalCall); }
set { impl_attributes = impl_attributes.SetAttributes ((ushort)MethodImplAttributes.InternalCall, value); }
}
public bool IsSynchronized {
get { return impl_attributes.GetAttributes ((ushort)MethodImplAttributes.Synchronized); }
set { impl_attributes = impl_attributes.SetAttributes ((ushort)MethodImplAttributes.Synchronized, value); }
}
public bool NoInlining {
get { return impl_attributes.GetAttributes ((ushort)MethodImplAttributes.NoInlining); }
set { impl_attributes = impl_attributes.SetAttributes ((ushort)MethodImplAttributes.NoInlining, value); }
}
public bool NoOptimization {
get { return impl_attributes.GetAttributes ((ushort)MethodImplAttributes.NoOptimization); }
set { impl_attributes = impl_attributes.SetAttributes ((ushort)MethodImplAttributes.NoOptimization, value); }
}
public bool AggressiveInlining {
get { return impl_attributes.GetAttributes ((ushort)MethodImplAttributes.AggressiveInlining); }
set { impl_attributes = impl_attributes.SetAttributes ((ushort)MethodImplAttributes.AggressiveInlining, value); }
}
#endregion
#region MethodSemanticsAttributes
public bool IsSetter {
get { return this.GetSemantics (MethodSemanticsAttributes.Setter); }
set { this.SetSemantics (MethodSemanticsAttributes.Setter, value); }
}
public bool IsGetter {
get { return this.GetSemantics (MethodSemanticsAttributes.Getter); }
set { this.SetSemantics (MethodSemanticsAttributes.Getter, value); }
}
public bool IsOther {
get { return this.GetSemantics (MethodSemanticsAttributes.Other); }
set { this.SetSemantics (MethodSemanticsAttributes.Other, value); }
}
public bool IsAddOn {
get { return this.GetSemantics (MethodSemanticsAttributes.AddOn); }
set { this.SetSemantics (MethodSemanticsAttributes.AddOn, value); }
}
public bool IsRemoveOn {
get { return this.GetSemantics (MethodSemanticsAttributes.RemoveOn); }
set { this.SetSemantics (MethodSemanticsAttributes.RemoveOn, value); }
}
public bool IsFire {
get { return this.GetSemantics (MethodSemanticsAttributes.Fire); }
set { this.SetSemantics (MethodSemanticsAttributes.Fire, value); }
}
#endregion
public new TypeDefinition DeclaringType {
get { return (TypeDefinition)base.DeclaringType; }
set { base.DeclaringType = value; }
}
public bool IsConstructor {
get {
return this.IsRuntimeSpecialName
&& this.IsSpecialName
&& (this.Name == ".cctor" || this.Name == ".ctor");
}
}
public override bool IsDefinition {
get { return true; }
}
internal MethodDefinition ()
{
this.token = new MetadataToken (TokenType.Method);
}
public MethodDefinition (string name, MethodAttributes attributes, TypeReference returnType)
: base (name, returnType)
{
this.attributes = (ushort)attributes;
this.HasThis = !this.IsStatic;
this.token = new MetadataToken (TokenType.Method);
}
public override MethodDefinition Resolve ()
{
return this;
}
}
static partial class Mixin {
public static ParameterDefinition GetParameter (this MethodBody self, int index)
{
var method = self.method;
if (method.HasThis) {
if (index == 0)
return self.ThisParameter;
index--;
}
var parameters = method.Parameters;
if (index < 0 || index >= parameters.size)
return null;
return parameters [index];
}
public static VariableDefinition GetVariable (this MethodBody self, int index)
{
var variables = self.Variables;
if (index < 0 || index >= variables.size)
return null;
return variables [index];
}
public static bool GetSemantics (this MethodDefinition self, MethodSemanticsAttributes semantics)
{
return (self.SemanticsAttributes & semantics) != 0;
}
public static void SetSemantics (this MethodDefinition self, MethodSemanticsAttributes semantics, bool value)
{
if (value)
self.SemanticsAttributes |= semantics;
else
self.SemanticsAttributes &= ~semantics;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 51ade7e624f84ae4abb8dc28a51b3082
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More