[Add] FishNet
This commit is contained in:
@@ -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
|
||||
{
|
||||
private int? lower_bound;
|
||||
private 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)
|
||||
{
|
||||
lower_bound = lowerBound;
|
||||
upper_bound = upperBound;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return !IsSized ? string.Empty : lower_bound + "..." + upper_bound;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ArrayType : TypeSpecification
|
||||
{
|
||||
private Collection<ArrayDimension> dimensions;
|
||||
public Collection<ArrayDimension> Dimensions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dimensions != null)
|
||||
return dimensions;
|
||||
|
||||
Collection<ArrayDimension> empty_dimensions = new();
|
||||
empty_dimensions.Add(new());
|
||||
|
||||
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;
|
||||
|
||||
ArrayDimension 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; }
|
||||
}
|
||||
private string Suffix
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsVector)
|
||||
return "[]";
|
||||
|
||||
StringBuilder suffix = new();
|
||||
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);
|
||||
etype = MD.ElementType.Array;
|
||||
}
|
||||
|
||||
public ArrayType(TypeReference type, int rank) : this(type)
|
||||
{
|
||||
Mixin.CheckType(type);
|
||||
|
||||
if (rank == 1)
|
||||
return;
|
||||
|
||||
dimensions = new(rank);
|
||||
for (int i = 0; i < rank; i++)
|
||||
dimensions.Add(new());
|
||||
etype = MD.ElementType.Array;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7add098db82a032428c139b59f0878be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/ArrayType.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,185 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
internal ModuleDefinition main_module;
|
||||
private Collection<ModuleDefinition> modules;
|
||||
private Collection<CustomAttribute> custom_attributes;
|
||||
private Collection<SecurityDeclaration> security_declarations;
|
||||
public AssemblyNameDefinition Name { get; set; }
|
||||
public string FullName
|
||||
{
|
||||
get { return Name != null ? Name.FullName : string.Empty; }
|
||||
}
|
||||
public MetadataToken MetadataToken
|
||||
{
|
||||
get { return new(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(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;
|
||||
}
|
||||
|
||||
Collection<ModuleDefinition> modules = 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");
|
||||
|
||||
AssemblyDefinition 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));
|
||||
}
|
||||
|
||||
private static AssemblyDefinition ReadAssembly(ModuleDefinition module)
|
||||
{
|
||||
AssemblyDefinition assembly = module.Assembly;
|
||||
if (assembly == null)
|
||||
throw new ArgumentException();
|
||||
|
||||
return assembly;
|
||||
}
|
||||
|
||||
public void Write(string fileName)
|
||||
{
|
||||
Write(fileName, new());
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
public void Write(Stream stream, WriterParameters parameters)
|
||||
{
|
||||
main_module.Write(stream, parameters);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return FullName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c1ac0fc48f2d424f9c0d9fa74b16b07
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/AssemblyDefinition.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 257c8151138cda34dafbe0ca56ebedf4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/AssemblyFlags.cs
|
||||
uploadId: 866910
|
||||
@@ -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 AssemblyHashAlgorithm : uint
|
||||
{
|
||||
None = 0x0000,
|
||||
MD5 = 0x8003,
|
||||
SHA1 = 0x8004,
|
||||
SHA256 = 0x800C,
|
||||
SHA384 = 0x800D,
|
||||
SHA512 = 0x800E,
|
||||
Reserved = 0x8003 // MD5
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b200bdec09584af41bd3f656e091cccf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/AssemblyHashAlgorithm.cs
|
||||
uploadId: 866910
|
||||
@@ -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 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)]
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff23d7231ddfa574b816532360874834
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/AssemblyInfo.cs
|
||||
uploadId: 866910
|
||||
@@ -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.
|
||||
//
|
||||
|
||||
namespace MonoFN.Cecil
|
||||
{
|
||||
public sealed class AssemblyLinkedResource : Resource
|
||||
{
|
||||
public AssemblyNameReference Assembly { get; set; }
|
||||
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.Assembly = reference;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3d5a207fc55ac5419e42c86cef15db0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/AssemblyLinkedResource.cs
|
||||
uploadId: 866910
|
||||
@@ -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()
|
||||
{
|
||||
token = new(TokenType.Assembly, 1);
|
||||
}
|
||||
|
||||
public AssemblyNameDefinition(string name, Version version) : base(name, version)
|
||||
{
|
||||
token = new(TokenType.Assembly, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68b90f4f023a67e4db7ddb52802ca21e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/AssemblyNameDefinition.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,279 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
private string name;
|
||||
private string culture;
|
||||
private Version version;
|
||||
private uint attributes;
|
||||
private byte[] public_key;
|
||||
private byte[] public_key_token;
|
||||
internal MetadataToken token;
|
||||
private 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())
|
||||
{
|
||||
byte[] hash = HashPublicKey();
|
||||
// we need the last 8 bytes in reverse order
|
||||
byte[] 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;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] HashPublicKey()
|
||||
{
|
||||
HashAlgorithm algorithm;
|
||||
|
||||
switch (HashAlgorithm)
|
||||
{
|
||||
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 = ", ";
|
||||
|
||||
StringBuilder builder = new();
|
||||
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=");
|
||||
|
||||
byte[] 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");
|
||||
|
||||
AssemblyNameReference name = new();
|
||||
string[] tokens = fullName.Split(',');
|
||||
for (int i = 0; i < tokens.Length; i++)
|
||||
{
|
||||
string token = tokens[i].Trim();
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
name.Name = token;
|
||||
continue;
|
||||
}
|
||||
|
||||
string[] parts = token.Split('=');
|
||||
if (parts.Length != 2)
|
||||
throw new ArgumentException("Malformed name");
|
||||
|
||||
switch (parts[0].ToLowerInvariant())
|
||||
{
|
||||
case "version":
|
||||
name.Version = new(parts[1]);
|
||||
break;
|
||||
case "culture":
|
||||
name.Culture = parts[1] == "neutral" ? "" : parts[1];
|
||||
break;
|
||||
case "publickeytoken":
|
||||
string 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; set; }
|
||||
public virtual byte[] Hash { get; set; }
|
||||
public MetadataToken MetadataToken
|
||||
{
|
||||
get { return token; }
|
||||
set { token = value; }
|
||||
}
|
||||
|
||||
internal AssemblyNameReference()
|
||||
{
|
||||
version = Mixin.ZeroVersion;
|
||||
token = new(TokenType.AssemblyRef);
|
||||
}
|
||||
|
||||
public AssemblyNameReference(string name, Version version)
|
||||
{
|
||||
Mixin.CheckName(name);
|
||||
|
||||
this.name = name;
|
||||
this.version = Mixin.CheckVersion(version);
|
||||
HashAlgorithm = AssemblyHashAlgorithm.None;
|
||||
token = new(TokenType.AssemblyRef);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return FullName;
|
||||
}
|
||||
}
|
||||
|
||||
internal partial class Mixin
|
||||
{
|
||||
public static Version ZeroVersion = new(0, 0, 0, 0);
|
||||
|
||||
public static Version CheckVersion(Version version)
|
||||
{
|
||||
if (version == null)
|
||||
return ZeroVersion;
|
||||
|
||||
if (version.Build == -1)
|
||||
return new(version.Major, version.Minor, 0, 0);
|
||||
|
||||
if (version.Revision == -1)
|
||||
return new(version.Major, version.Minor, version.Build, 0);
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdaf7563058f3f54ba3e6b32c888eb3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/AssemblyNameReference.cs
|
||||
uploadId: 866910
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8fb74d16029713429e831cb3b5b0861
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/AssemblyReader.cs
|
||||
uploadId: 866910
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a88ce645df13da4aa9eca43f013f6ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/AssemblyWriter.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,400 @@
|
||||
//
|
||||
// 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.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace MonoFN.Cecil
|
||||
{
|
||||
public delegate AssemblyDefinition AssemblyResolveEventHandler(object sender, AssemblyNameReference reference);
|
||||
|
||||
public sealed class AssemblyResolveEventArgs : EventArgs
|
||||
{
|
||||
public AssemblyNameReference AssemblyReference { get; }
|
||||
|
||||
public AssemblyResolveEventArgs(AssemblyNameReference reference)
|
||||
{
|
||||
this.AssemblyReference = reference;
|
||||
}
|
||||
}
|
||||
|
||||
#if !NET_CORE
|
||||
[Serializable]
|
||||
#endif
|
||||
public sealed class AssemblyResolutionException : FileNotFoundException
|
||||
{
|
||||
public AssemblyNameReference AssemblyReference { get; }
|
||||
public AssemblyResolutionException(AssemblyNameReference reference) : this(reference, null) { }
|
||||
|
||||
public AssemblyResolutionException(AssemblyNameReference reference, Exception innerException) : base(string.Format("Failed to resolve assembly: '{0}'", reference), innerException)
|
||||
{
|
||||
this.AssemblyReference = reference;
|
||||
}
|
||||
|
||||
#if !NET_CORE
|
||||
private AssemblyResolutionException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
|
||||
#endif
|
||||
}
|
||||
|
||||
public abstract class BaseAssemblyResolver : IAssemblyResolver
|
||||
{
|
||||
private static readonly bool on_mono = Type.GetType("MonoFN.Runtime") != null;
|
||||
private 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
|
||||
private Collection<string> gac_paths;
|
||||
#endif
|
||||
|
||||
public void AddSearchDirectory(string directory)
|
||||
{
|
||||
directories.Add(directory);
|
||||
}
|
||||
|
||||
public void RemoveSearchDirectory(string directory)
|
||||
{
|
||||
directories.Remove(directory);
|
||||
}
|
||||
|
||||
public string[] GetSearchDirectories()
|
||||
{
|
||||
string[] directories = new string [this.directories.size];
|
||||
Array.Copy(this.directories.items, directories, directories.Length);
|
||||
return directories;
|
||||
}
|
||||
|
||||
public event AssemblyResolveEventHandler ResolveFailure;
|
||||
|
||||
protected BaseAssemblyResolver()
|
||||
{
|
||||
directories = new(2) { ".", "bin" };
|
||||
}
|
||||
|
||||
private 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());
|
||||
}
|
||||
|
||||
public virtual AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
|
||||
{
|
||||
Mixin.CheckName(name);
|
||||
Mixin.CheckParameters(parameters);
|
||||
|
||||
AssemblyDefinition assembly = SearchDirectory(name, directories, parameters);
|
||||
if (assembly != null)
|
||||
return assembly;
|
||||
|
||||
if (name.IsRetargetable)
|
||||
{
|
||||
// if the reference is retargetable, zero it
|
||||
name = new(name.Name, Mixin.ZeroVersion)
|
||||
{
|
||||
PublicKeyToken = Empty<byte>.Array
|
||||
};
|
||||
}
|
||||
|
||||
#if NET_CORE
|
||||
assembly = SearchTrustedPlatformAssemblies(name, parameters);
|
||||
if (assembly != null)
|
||||
return assembly;
|
||||
#else
|
||||
string framework_dir = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName);
|
||||
string[] 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)
|
||||
{
|
||||
string[] extensions = name.IsWindowsRuntime ? new[] { ".winmd", ".dll" } : new[] { ".exe", ".dll" };
|
||||
foreach (string directory in directories)
|
||||
{
|
||||
foreach (string extension in extensions)
|
||||
{
|
||||
string file = Path.Combine(directory, name.Name + extension);
|
||||
if (!File.Exists(file))
|
||||
continue;
|
||||
try
|
||||
{
|
||||
return GetAssembly(file, parameters);
|
||||
}
|
||||
catch (BadImageFormatException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool IsZero(Version version)
|
||||
{
|
||||
return version.Major == 0 && version.Minor == 0 && version.Build == 0 && version.Revision == 0;
|
||||
}
|
||||
|
||||
#if !NET_CORE
|
||||
private AssemblyDefinition GetCorlib(AssemblyNameReference reference, ReaderParameters parameters)
|
||||
{
|
||||
Version version = reference.Version;
|
||||
AssemblyName corlib = typeof(object).Assembly.GetName();
|
||||
if (corlib.Version == version || IsZero(version))
|
||||
return GetAssembly(typeof(object).Module.FullyQualifiedName, parameters);
|
||||
|
||||
string 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);
|
||||
}
|
||||
}
|
||||
|
||||
string 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;
|
||||
}
|
||||
|
||||
private static Collection<string> GetGacPaths()
|
||||
{
|
||||
if (on_mono)
|
||||
return GetDefaultMonoGacPaths();
|
||||
|
||||
Collection<string> paths = new(2);
|
||||
string 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;
|
||||
}
|
||||
|
||||
private static Collection<string> GetDefaultMonoGacPaths()
|
||||
{
|
||||
Collection<string> paths = new(1);
|
||||
string gac = GetCurrentMonoGac();
|
||||
if (gac != null)
|
||||
paths.Add(gac);
|
||||
|
||||
string gac_paths_env = Environment.GetEnvironmentVariable("MONO_GAC_PREFIX");
|
||||
if (string.IsNullOrEmpty(gac_paths_env))
|
||||
return paths;
|
||||
|
||||
string[] prefixes = gac_paths_env.Split(Path.PathSeparator);
|
||||
foreach (string prefix in prefixes)
|
||||
{
|
||||
if (string.IsNullOrEmpty(prefix))
|
||||
continue;
|
||||
|
||||
string 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;
|
||||
}
|
||||
|
||||
private static string GetCurrentMonoGac()
|
||||
{
|
||||
return Path.Combine(Directory.GetParent(Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName)).FullName, "gac");
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
|
||||
private AssemblyDefinition GetAssemblyInMonoGac(AssemblyNameReference reference, ReaderParameters parameters)
|
||||
{
|
||||
for (int i = 0; i < gac_paths.Count; i++)
|
||||
{
|
||||
string gac_path = gac_paths[i];
|
||||
string file = GetAssemblyFile(reference, string.Empty, gac_path);
|
||||
if (File.Exists(file))
|
||||
return GetAssembly(file, parameters);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private AssemblyDefinition GetAssemblyInNetGac(AssemblyNameReference reference, ReaderParameters parameters)
|
||||
{
|
||||
string[] gacs = new[] { "GAC_MSIL", "GAC_32", "GAC_64", "GAC" };
|
||||
string[] prefixes = new[] { string.Empty, "v4.0_" };
|
||||
|
||||
for (int i = 0; i < gac_paths.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < gacs.Length; j++)
|
||||
{
|
||||
string gac = Path.Combine(gac_paths[i], gacs[j]);
|
||||
string file = GetAssemblyFile(reference, prefixes[i], gac);
|
||||
if (Directory.Exists(gac) && File.Exists(file))
|
||||
return GetAssembly(file, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string GetAssemblyFile(AssemblyNameReference reference, string prefix, string gac)
|
||||
{
|
||||
StringBuilder 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) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ab1d53794ef7444c81e276b5a3a5c2b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/BaseAssemblyResolver.cs
|
||||
uploadId: 866910
|
||||
@@ -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
|
||||
{
|
||||
private 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
|
||||
{
|
||||
StringBuilder signature = new();
|
||||
signature.Append(ReturnType.FullName);
|
||||
this.MethodSignatureFullName(signature);
|
||||
return signature.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
internal CallSite()
|
||||
{
|
||||
signature = new();
|
||||
signature.token = new(TokenType.Signature, 0);
|
||||
}
|
||||
|
||||
public CallSite(TypeReference returnType) : this()
|
||||
{
|
||||
if (returnType == null)
|
||||
throw new ArgumentNullException("returnType");
|
||||
|
||||
signature.ReturnType = returnType;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return FullName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 087823dce9623d348927f193f95a1807
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/CallSite.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MonoFN.Cecil
|
||||
{
|
||||
internal static class Consts
|
||||
{
|
||||
public const string AssemblyName = "MonoFN.Cecil";
|
||||
public const string PublicKey = "00240000048000009400000006020000002400005253413100040000010001002b5c9f7f04346c324a3176f8d3ee823bbf2d60efdbc35f86fd9e65ea3e6cd11bcdcba3a353e55133c8ac5c4caaba581b2c6dfff2cc2d0edc43959ddb86b973300a479a82419ef489c3225f1fe429a708507bd515835160e10bc743d20ca33ab9570cfd68d479fcf0bc797a763bec5d1000f0159ef619e709d915975e87beebaf";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da413e0e98056364a9512beb26e9aea5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/Consts.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,209 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
public TypeReference Type { get; }
|
||||
public object Value { get; }
|
||||
|
||||
public CustomAttributeArgument(TypeReference type, object value)
|
||||
{
|
||||
Mixin.CheckType(type);
|
||||
this.Type = type;
|
||||
this.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public struct CustomAttributeNamedArgument
|
||||
{
|
||||
public string Name { get; }
|
||||
public CustomAttributeArgument Argument { get; }
|
||||
|
||||
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;
|
||||
internal readonly uint signature;
|
||||
internal bool resolved;
|
||||
private byte[] blob;
|
||||
internal Collection<CustomAttributeArgument> arguments;
|
||||
internal Collection<CustomAttributeNamedArgument> fields;
|
||||
internal Collection<CustomAttributeNamedArgument> properties;
|
||||
public MethodReference Constructor { get; set; }
|
||||
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(), 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(), 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(), 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;
|
||||
resolved = false;
|
||||
}
|
||||
|
||||
public CustomAttribute(MethodReference constructor)
|
||||
{
|
||||
this.Constructor = constructor;
|
||||
resolved = true;
|
||||
}
|
||||
|
||||
public CustomAttribute(MethodReference constructor, byte[] blob)
|
||||
{
|
||||
this.Constructor = constructor;
|
||||
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));
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91db4bc8250b4b949bf262a196c9c0c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/CustomAttribute.cs
|
||||
uploadId: 866910
|
||||
@@ -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
|
||||
{
|
||||
private 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");
|
||||
|
||||
string name = assembly.Name.FullName;
|
||||
if (cache.ContainsKey(name))
|
||||
return;
|
||||
|
||||
cache[name] = assembly;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
foreach (AssemblyDefinition assembly in cache.Values)
|
||||
assembly.Dispose();
|
||||
|
||||
cache.Clear();
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5390b4f18cb83c046baaaa937fec06a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/DefaultAssemblyResolver.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
private readonly MetadataReader reader;
|
||||
private uint? offset;
|
||||
private byte[] data;
|
||||
private 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();
|
||||
}
|
||||
|
||||
private static byte[] ReadStream(Stream stream)
|
||||
{
|
||||
int read;
|
||||
|
||||
if (stream.CanSeek)
|
||||
{
|
||||
int length = (int)stream.Length;
|
||||
byte[] data = new byte [length];
|
||||
int offset = 0;
|
||||
|
||||
while ((read = stream.Read(data, offset, length - offset)) > 0)
|
||||
offset += read;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
byte[] buffer = new byte [1024 * 8];
|
||||
MemoryStream memory = new();
|
||||
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
memory.Write(buffer, 0, read);
|
||||
|
||||
return memory.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5874acd8fee1b4499a3249dd4648428
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/EmbeddedResource.cs
|
||||
uploadId: 866910
|
||||
@@ -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.
|
||||
//
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20c18be3d45bbf84d82732fd16751df3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/EventAttributes.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,158 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
private ushort attributes;
|
||||
private 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(), 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;
|
||||
token = new(TokenType.Event);
|
||||
}
|
||||
|
||||
private void InitializeMethods()
|
||||
{
|
||||
ModuleDefinition module = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b201911ff1f925438edbe5b91275268
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/EventDefinition.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
public TypeReference EventType { get; set; }
|
||||
public override string FullName
|
||||
{
|
||||
get { return EventType.FullName + " " + MemberFullName(); }
|
||||
}
|
||||
|
||||
protected EventReference(string name, TypeReference eventType) : base(name)
|
||||
{
|
||||
Mixin.CheckType(eventType, Mixin.Argument.eventType);
|
||||
EventType = eventType;
|
||||
}
|
||||
|
||||
protected override IMemberDefinition ResolveDefinition()
|
||||
{
|
||||
return Resolve();
|
||||
}
|
||||
|
||||
public new abstract EventDefinition Resolve();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94d9b58b6c4033343b975f6730127514
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/EventReference.cs
|
||||
uploadId: 866910
|
||||
@@ -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.
|
||||
//
|
||||
|
||||
namespace MonoFN.Cecil
|
||||
{
|
||||
public sealed class ExportedType : IMetadataTokenProvider
|
||||
{
|
||||
private uint attributes;
|
||||
private IMetadataScope scope;
|
||||
private ModuleDefinition module;
|
||||
internal MetadataToken token;
|
||||
public string Namespace { get; set; }
|
||||
public string Name { get; set; }
|
||||
public TypeAttributes Attributes
|
||||
{
|
||||
get { return (TypeAttributes)attributes; }
|
||||
set { attributes = (uint)value; }
|
||||
}
|
||||
public IMetadataScope Scope
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DeclaringType != null)
|
||||
return DeclaringType.Scope;
|
||||
|
||||
return scope;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (DeclaringType != null)
|
||||
{
|
||||
DeclaringType.Scope = value;
|
||||
return;
|
||||
}
|
||||
|
||||
scope = value;
|
||||
}
|
||||
}
|
||||
public ExportedType DeclaringType { get; set; }
|
||||
public MetadataToken MetadataToken
|
||||
{
|
||||
get { return token; }
|
||||
set { token = value; }
|
||||
}
|
||||
public int Identifier { get; set; }
|
||||
|
||||
#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
|
||||
{
|
||||
string fullname = string.IsNullOrEmpty(Namespace) ? Name : Namespace + '.' + Name;
|
||||
|
||||
if (DeclaringType != null)
|
||||
return DeclaringType.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(Namespace, Name, module, scope)
|
||||
{
|
||||
DeclaringType = DeclaringType != null ? DeclaringType.CreateReference() : null
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7fa6f0bdd43c0d44a63cd789a765eeb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/ExportedType.cs
|
||||
uploadId: 866910
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e9187082e8fc1446a8c2aa12d8f3fa4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/FieldAttributes.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,294 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
private ushort attributes;
|
||||
private Collection<CustomAttribute> custom_attributes;
|
||||
private int offset = Mixin.NotResolvedMarker;
|
||||
internal int rva = Mixin.NotResolvedMarker;
|
||||
private byte[] initial_value;
|
||||
private object constant = Mixin.NotResolved;
|
||||
private MarshalInfo marshal_info;
|
||||
|
||||
private 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; }
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
|
||||
internal static partial class Mixin
|
||||
{
|
||||
public const int NotResolvedMarker = -2;
|
||||
public const int NoDataMarker = -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00dcb95135f39ec4c923f7923bcc93ed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/FieldDefinition.cs
|
||||
uploadId: 866910
|
||||
@@ -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;
|
||||
|
||||
namespace MonoFN.Cecil
|
||||
{
|
||||
public class FieldReference : MemberReference
|
||||
{
|
||||
public TypeReference FieldType { get; set; }
|
||||
public override string FullName
|
||||
{
|
||||
get { return FieldType.FullName + " " + MemberFullName(); }
|
||||
}
|
||||
public override bool ContainsGenericParameter
|
||||
{
|
||||
get { return FieldType.ContainsGenericParameter || base.ContainsGenericParameter; }
|
||||
}
|
||||
|
||||
internal FieldReference()
|
||||
{
|
||||
token = new(TokenType.MemberRef);
|
||||
}
|
||||
|
||||
public FieldReference(string name, TypeReference fieldType) : base(name)
|
||||
{
|
||||
Mixin.CheckType(fieldType, Mixin.Argument.fieldType);
|
||||
|
||||
FieldType = fieldType;
|
||||
token = new(TokenType.MemberRef);
|
||||
}
|
||||
|
||||
public FieldReference(string name, TypeReference fieldType, TypeReference declaringType) : this(name, fieldType)
|
||||
{
|
||||
Mixin.CheckType(declaringType, Mixin.Argument.declaringType);
|
||||
|
||||
DeclaringType = declaringType;
|
||||
}
|
||||
|
||||
protected override IMemberDefinition ResolveDefinition()
|
||||
{
|
||||
return Resolve();
|
||||
}
|
||||
|
||||
public new virtual FieldDefinition Resolve()
|
||||
{
|
||||
ModuleDefinition module = Module;
|
||||
if (module == null)
|
||||
throw new NotSupportedException();
|
||||
|
||||
return module.Resolve(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 990be2becde06b4468f79bd17646a47a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/FieldReference.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
internal enum FileAttributes : uint
|
||||
{
|
||||
ContainsMetaData = 0x0000, // This is not a resource file
|
||||
ContainsNoMetaData = 0x0001 // This is a resource file or other non-metadata-containing file
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56e662d580c0894489669cc8058a2783
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/FileAttributes.cs
|
||||
uploadId: 866910
|
||||
@@ -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
|
||||
{
|
||||
private 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
|
||||
{
|
||||
StringBuilder signature = new();
|
||||
signature.Append(function.Name);
|
||||
signature.Append(" ");
|
||||
signature.Append(function.ReturnType.FullName);
|
||||
signature.Append(" *");
|
||||
this.MethodSignatureFullName(signature);
|
||||
return signature.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public FunctionPointerType() : base(null)
|
||||
{
|
||||
function = new();
|
||||
function.Name = "method";
|
||||
etype = MD.ElementType.FnPtr;
|
||||
}
|
||||
|
||||
public override TypeDefinition Resolve()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override TypeReference GetElementType()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91d84cd146416f945acbfce1b1dbcacb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/FunctionPointerType.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
private Collection<TypeReference> arguments;
|
||||
public bool HasGenericArguments
|
||||
{
|
||||
get { return !arguments.IsNullOrEmpty(); }
|
||||
}
|
||||
public Collection<TypeReference> GenericArguments
|
||||
{
|
||||
get
|
||||
{
|
||||
if (arguments == null)
|
||||
Interlocked.CompareExchange(ref arguments, new(), 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
|
||||
{
|
||||
StringBuilder signature = new();
|
||||
MethodReference method = 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)
|
||||
{
|
||||
arguments = new(arity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd61b82dc3c653d42a1fc0f4e4c003f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/GenericInstanceMethod.cs
|
||||
uploadId: 866910
|
||||
@@ -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
|
||||
{
|
||||
private Collection<TypeReference> arguments;
|
||||
public bool HasGenericArguments
|
||||
{
|
||||
get { return !arguments.IsNullOrEmpty(); }
|
||||
}
|
||||
public Collection<TypeReference> GenericArguments
|
||||
{
|
||||
get
|
||||
{
|
||||
if (arguments == null)
|
||||
Interlocked.CompareExchange(ref arguments, new(), null);
|
||||
|
||||
return arguments;
|
||||
}
|
||||
}
|
||||
public override TypeReference DeclaringType
|
||||
{
|
||||
get { return ElementType.DeclaringType; }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
public override string FullName
|
||||
{
|
||||
get
|
||||
{
|
||||
StringBuilder name = new();
|
||||
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)
|
||||
{
|
||||
IsValueType = type.IsValueType;
|
||||
etype = MD.ElementType.GenericInst;
|
||||
}
|
||||
|
||||
internal GenericInstanceType(TypeReference type, int arity) : this(type)
|
||||
{
|
||||
arguments = new(arity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 536e7e359f0fa6c449a352476e8af197
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/GenericInstanceType.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,352 @@
|
||||
//
|
||||
// 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;
|
||||
private ushort attributes;
|
||||
private GenericParameterConstraintCollection constraints;
|
||||
private 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(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();
|
||||
|
||||
position = -1;
|
||||
this.owner = owner;
|
||||
type = owner.GenericParameterType;
|
||||
etype = ConvertGenericParameterType(type);
|
||||
token = new(TokenType.GenericParam);
|
||||
}
|
||||
|
||||
internal GenericParameter(int position, GenericParameterType type, ModuleDefinition module) : base(string.Empty, string.Empty)
|
||||
{
|
||||
Mixin.CheckModule(module);
|
||||
|
||||
this.position = position;
|
||||
this.type = type;
|
||||
etype = ConvertGenericParameterType(type);
|
||||
this.module = module;
|
||||
token = new(TokenType.GenericParam);
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class GenericParameterCollection : Collection<GenericParameter>
|
||||
{
|
||||
private 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);
|
||||
}
|
||||
|
||||
private 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;
|
||||
private Collection<CustomAttribute> custom_attributes;
|
||||
public TypeReference ConstraintType { get; set; }
|
||||
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(), 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)
|
||||
{
|
||||
ConstraintType = constraintType;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public GenericParameterConstraint(TypeReference constraintType)
|
||||
{
|
||||
Mixin.CheckType(constraintType, Mixin.Argument.constraintType);
|
||||
|
||||
ConstraintType = constraintType;
|
||||
token = new(TokenType.GenericParamConstraint);
|
||||
}
|
||||
}
|
||||
|
||||
internal class GenericParameterConstraintCollection : Collection<GenericParameterConstraint>
|
||||
{
|
||||
private readonly GenericParameter generic_parameter;
|
||||
|
||||
internal GenericParameterConstraintCollection(GenericParameter genericParameter)
|
||||
{
|
||||
generic_parameter = genericParameter;
|
||||
}
|
||||
|
||||
internal GenericParameterConstraintCollection(GenericParameter genericParameter, int length) : base(length)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a20d39eab5fe7884c8cdf55fde143904
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/GenericParameter.cs
|
||||
uploadId: 866910
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 406369465fc07a643b3923d53fb1e941
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/GenericParameterAttributes.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,182 @@
|
||||
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;
|
||||
|
||||
GenericInstanceMethod genericInstanceMethod = methodReference as GenericInstanceMethod;
|
||||
GenericInstanceType 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)
|
||||
{
|
||||
GenericInstanceMethod genericInstanceMethod = method as GenericInstanceMethod;
|
||||
GenericInstanceType 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)
|
||||
{
|
||||
GenericInstanceMethod genericInstanceMethod = method as GenericInstanceMethod;
|
||||
GenericInstanceType 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)
|
||||
{
|
||||
ByReferenceType byRefType = parameterType as ByReferenceType;
|
||||
if (byRefType != null)
|
||||
return ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, byRefType);
|
||||
|
||||
ArrayType arrayType = parameterType as ArrayType;
|
||||
if (arrayType != null)
|
||||
return ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, arrayType);
|
||||
|
||||
GenericInstanceType genericInstanceType = parameterType as GenericInstanceType;
|
||||
if (genericInstanceType != null)
|
||||
return ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, genericInstanceType);
|
||||
|
||||
GenericParameter genericParameter = parameterType as GenericParameter;
|
||||
if (genericParameter != null)
|
||||
return ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, genericParameter);
|
||||
|
||||
RequiredModifierType requiredModifierType = parameterType as RequiredModifierType;
|
||||
if (requiredModifierType != null && ContainsGenericParameters(requiredModifierType))
|
||||
return ResolveIfNeeded(genericInstanceMethod, declaringGenericInstanceType, requiredModifierType.ElementType);
|
||||
|
||||
if (ContainsGenericParameters(parameterType))
|
||||
throw new("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(ResolveIfNeeded(genericInstanceMethod, genericInstanceType, arrayType.ElementType), arrayType.Rank);
|
||||
}
|
||||
|
||||
private static ByReferenceType ResolveIfNeeded(IGenericInstance genericInstanceMethod, IGenericInstance genericInstanceType, ByReferenceType byReferenceType)
|
||||
{
|
||||
return new(ResolveIfNeeded(genericInstanceMethod, genericInstanceType, byReferenceType.ElementType));
|
||||
}
|
||||
|
||||
private static GenericInstanceType ResolveIfNeeded(IGenericInstance genericInstanceMethod, IGenericInstance genericInstanceType, GenericInstanceType genericInstanceType1)
|
||||
{
|
||||
if (!ContainsGenericParameters(genericInstanceType1))
|
||||
return genericInstanceType1;
|
||||
|
||||
GenericInstanceType newGenericInstance = new(genericInstanceType1.ElementType);
|
||||
|
||||
foreach (TypeReference genericArgument in genericInstanceType1.GenericArguments)
|
||||
{
|
||||
if (!genericArgument.IsGenericParameter)
|
||||
{
|
||||
newGenericInstance.GenericArguments.Add(ResolveIfNeeded(genericInstanceMethod, genericInstanceType, genericArgument));
|
||||
continue;
|
||||
}
|
||||
|
||||
GenericParameter 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)
|
||||
{
|
||||
GenericParameter genericParameter = typeReference as GenericParameter;
|
||||
if (genericParameter != null)
|
||||
return true;
|
||||
|
||||
ArrayType arrayType = typeReference as ArrayType;
|
||||
if (arrayType != null)
|
||||
return ContainsGenericParameters(arrayType.ElementType);
|
||||
|
||||
PointerType pointerType = typeReference as PointerType;
|
||||
if (pointerType != null)
|
||||
return ContainsGenericParameters(pointerType.ElementType);
|
||||
|
||||
ByReferenceType byRefType = typeReference as ByReferenceType;
|
||||
if (byRefType != null)
|
||||
return ContainsGenericParameters(byRefType.ElementType);
|
||||
|
||||
SentinelType sentinelType = typeReference as SentinelType;
|
||||
if (sentinelType != null)
|
||||
return ContainsGenericParameters(sentinelType.ElementType);
|
||||
|
||||
PinnedType pinnedType = typeReference as PinnedType;
|
||||
if (pinnedType != null)
|
||||
return ContainsGenericParameters(pinnedType.ElementType);
|
||||
|
||||
RequiredModifierType requiredModifierType = typeReference as RequiredModifierType;
|
||||
if (requiredModifierType != null)
|
||||
return ContainsGenericParameters(requiredModifierType.ElementType);
|
||||
|
||||
GenericInstanceType genericInstance = typeReference as GenericInstanceType;
|
||||
if (genericInstance != null)
|
||||
{
|
||||
foreach (TypeReference genericArgument in genericInstance.GenericArguments)
|
||||
{
|
||||
if (ContainsGenericParameters(genericArgument))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeReference is TypeSpecification)
|
||||
throw new NotSupportedException();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4151464170fe40440a031e1f4f2ecf53
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/GenericParameterResolver.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// 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; }
|
||||
}
|
||||
|
||||
internal static partial class Mixin
|
||||
{
|
||||
internal static object NoValue = new();
|
||||
internal static object NotResolved = new();
|
||||
|
||||
public static void ResolveConstant(this IConstantProvider self, ref object constant, ModuleDefinition module)
|
||||
{
|
||||
if (module == null)
|
||||
{
|
||||
constant = NoValue;
|
||||
return;
|
||||
}
|
||||
|
||||
lock (module.SyncRoot)
|
||||
{
|
||||
if (constant != NotResolved)
|
||||
return;
|
||||
if (module.HasImage())
|
||||
constant = module.Read(self, (provider, reader) => reader.ReadConstant(provider));
|
||||
else
|
||||
constant = NoValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58315b928b9e49540b9d1591523c92c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/IConstantProvider.cs
|
||||
uploadId: 866910
|
||||
@@ -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.
|
||||
//
|
||||
|
||||
using MonoFN.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace MonoFN.Cecil
|
||||
{
|
||||
public interface ICustomAttributeProvider : IMetadataTokenProvider
|
||||
{
|
||||
Collection<CustomAttribute> CustomAttributes { get; }
|
||||
bool HasCustomAttributes { get; }
|
||||
}
|
||||
|
||||
internal 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(), null);
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1585603aa3fe4f1409c42694378a557c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/ICustomAttributeProvider.cs
|
||||
uploadId: 866910
|
||||
@@ -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 MonoFN.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace MonoFN.Cecil
|
||||
{
|
||||
public interface IGenericInstance : IMetadataTokenProvider
|
||||
{
|
||||
bool HasGenericArguments { get; }
|
||||
Collection<TypeReference> GenericArguments { get; }
|
||||
}
|
||||
|
||||
internal static partial class Mixin
|
||||
{
|
||||
public static bool ContainsGenericParameter(this IGenericInstance self)
|
||||
{
|
||||
Collection<TypeReference> 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("<");
|
||||
Collection<TypeReference> arguments = self.GenericArguments;
|
||||
for (int i = 0; i < arguments.Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
builder.Append(",");
|
||||
builder.Append(arguments[i].FullName);
|
||||
}
|
||||
builder.Append(">");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 22b3a8ddd25a989449e5e9ffc632bc00
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/IGenericInstance.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
||||
internal interface IGenericContext
|
||||
{
|
||||
bool IsDefinition { get; }
|
||||
IGenericParameterProvider Type { get; }
|
||||
IGenericParameterProvider Method { get; }
|
||||
}
|
||||
|
||||
internal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c81842a9d1ff34f4b94b047da954469f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/IGenericParameterProvider.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// 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; }
|
||||
}
|
||||
|
||||
internal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a73829f4e35521e4892ef4e0cce2e4f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/IMarshalInfoProvider.cs
|
||||
uploadId: 866910
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
internal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 482577ba8693d3f438504e54d6edb971
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/IMemberDefinition.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// 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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da1ce103d170a414c8c8c6849a8856a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/IMetadataScope.cs
|
||||
uploadId: 866910
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c01133d3a99e95542b153987746696d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/IMetadataTokenProvider.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// 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; }
|
||||
}
|
||||
|
||||
internal 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)
|
||||
{
|
||||
Collection<ParameterDefinition> parameters = self.Parameters;
|
||||
for (int i = 0; i < parameters.Count; i++)
|
||||
{
|
||||
ParameterDefinition parameter = parameters[i];
|
||||
if (i > 0)
|
||||
builder.Append(",");
|
||||
|
||||
if (parameter.ParameterType.IsSentinel)
|
||||
builder.Append("...,");
|
||||
|
||||
builder.Append(parameter.ParameterType.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
builder.Append(")");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fdcc55987f0a4f4b93358d994704a98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/IMethodSignature.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,829 @@
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
internal struct ImportGenericContext
|
||||
{
|
||||
private 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(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--)
|
||||
{
|
||||
MethodReference 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--)
|
||||
{
|
||||
TypeReference candidate = GenericTypeFor(stack[i]);
|
||||
|
||||
if (candidate.FullName != type)
|
||||
continue;
|
||||
|
||||
return candidate.GenericParameters[position];
|
||||
}
|
||||
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
private static TypeReference GenericTypeFor(IGenericParameterProvider context)
|
||||
{
|
||||
TypeReference type = context as TypeReference;
|
||||
if (type != null)
|
||||
return type.GetElementType();
|
||||
|
||||
MethodReference method = context as MethodReference;
|
||||
if (method != null)
|
||||
return method.DeclaringType.GetElementType();
|
||||
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public static ImportGenericContext For(IGenericParameterProvider context)
|
||||
{
|
||||
return context != null ? new(context) : default(ImportGenericContext);
|
||||
}
|
||||
}
|
||||
|
||||
public class DefaultReflectionImporter : IReflectionImporter
|
||||
{
|
||||
protected readonly ModuleDefinition module;
|
||||
|
||||
public DefaultReflectionImporter(ModuleDefinition module)
|
||||
{
|
||||
Mixin.CheckModule(module);
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
private enum ImportGenericKind
|
||||
{
|
||||
Definition,
|
||||
Open
|
||||
}
|
||||
|
||||
private static readonly Dictionary<Type, ElementType> type_etype_mapping = new(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 }
|
||||
};
|
||||
|
||||
private TypeReference ImportType(Type type, ImportGenericContext context)
|
||||
{
|
||||
return ImportType(type, context, ImportGenericKind.Open);
|
||||
}
|
||||
|
||||
private TypeReference ImportType(Type type, ImportGenericContext context, ImportGenericKind import_kind)
|
||||
{
|
||||
if (IsTypeSpecification(type) || ImportOpenGenericType(type, import_kind))
|
||||
return ImportTypeSpecification(type, context);
|
||||
|
||||
TypeReference reference = new(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);
|
||||
}
|
||||
|
||||
private static bool ImportOpenGenericType(Type type, ImportGenericKind import_kind)
|
||||
{
|
||||
return type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open;
|
||||
}
|
||||
|
||||
private static bool ImportOpenGenericMethod(SR.MethodBase method, ImportGenericKind import_kind)
|
||||
{
|
||||
return method.IsGenericMethod && method.IsGenericMethodDefinition && import_kind == ImportGenericKind.Open;
|
||||
}
|
||||
|
||||
private static bool IsNestedType(Type type)
|
||||
{
|
||||
return type.IsNested;
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
|
||||
private 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();
|
||||
}
|
||||
|
||||
private static string NormalizeMethodName(SR.MethodBase method)
|
||||
{
|
||||
return NormalizeTypeFullName(method.DeclaringType) + "." + method.Name;
|
||||
}
|
||||
|
||||
private static string NormalizeTypeFullName(Type type)
|
||||
{
|
||||
if (IsNestedType(type))
|
||||
return NormalizeTypeFullName(type.DeclaringType) + "/" + type.Name;
|
||||
|
||||
return type.FullName;
|
||||
}
|
||||
|
||||
private TypeReference ImportGenericInstance(Type type, ImportGenericContext context)
|
||||
{
|
||||
TypeReference element_type = ImportType(type.GetGenericTypeDefinition(), context, ImportGenericKind.Definition);
|
||||
Type[] arguments = type.GetGenericArguments();
|
||||
GenericInstanceType instance = new(element_type, arguments.Length);
|
||||
Collection<TypeReference> 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();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsTypeSpecification(Type type)
|
||||
{
|
||||
return type.HasElementType || IsGenericInstance(type) || type.IsGenericParameter;
|
||||
}
|
||||
|
||||
private static bool IsGenericInstance(Type type)
|
||||
{
|
||||
return type.IsGenericType && !type.IsGenericTypeDefinition;
|
||||
}
|
||||
|
||||
private 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(name.Name, name.Version)
|
||||
{
|
||||
PublicKeyToken = name.GetPublicKeyToken(),
|
||||
Culture = name.CultureInfo.Name,
|
||||
HashAlgorithm = (AssemblyHashAlgorithm)name.HashAlgorithm
|
||||
};
|
||||
|
||||
module.AssemblyReferences.Add(reference);
|
||||
return reference;
|
||||
}
|
||||
|
||||
private bool TryGetAssemblyNameReference(SR.AssemblyName name, out AssemblyNameReference assembly_reference)
|
||||
{
|
||||
Collection<AssemblyNameReference> references = module.AssemblyReferences;
|
||||
|
||||
for (int i = 0; i < references.Count; i++)
|
||||
{
|
||||
AssemblyNameReference reference = references[i];
|
||||
if (name.FullName != reference.FullName) // TODO compare field by field
|
||||
continue;
|
||||
|
||||
assembly_reference = reference;
|
||||
return true;
|
||||
}
|
||||
|
||||
assembly_reference = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private FieldReference ImportField(SR.FieldInfo field, ImportGenericContext context)
|
||||
{
|
||||
TypeReference declaring_type = ImportType(field.DeclaringType, context);
|
||||
|
||||
if (IsGenericInstance(field.DeclaringType))
|
||||
field = ResolveFieldDefinition(field);
|
||||
|
||||
context.Push(declaring_type);
|
||||
try
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = field.Name,
|
||||
DeclaringType = declaring_type,
|
||||
FieldType = ImportType(field.FieldType, context)
|
||||
};
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.Pop();
|
||||
}
|
||||
}
|
||||
|
||||
private static SR.FieldInfo ResolveFieldDefinition(SR.FieldInfo field)
|
||||
{
|
||||
return field.Module.ResolveField(field.MetadataToken);
|
||||
}
|
||||
|
||||
private static SR.MethodBase ResolveMethodDefinition(SR.MethodBase method)
|
||||
{
|
||||
return method.Module.ResolveMethod(method.MetadataToken);
|
||||
}
|
||||
|
||||
private MethodReference ImportMethod(SR.MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
|
||||
{
|
||||
if (IsMethodSpecification(method) || ImportOpenGenericMethod(method, import_kind))
|
||||
return ImportMethodSpecification(method, context);
|
||||
|
||||
TypeReference declaring_type = ImportType(method.DeclaringType, context);
|
||||
|
||||
if (IsGenericInstance(method.DeclaringType))
|
||||
method = ResolveMethodDefinition(method);
|
||||
|
||||
MethodReference reference = new()
|
||||
{
|
||||
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
|
||||
{
|
||||
SR.MethodInfo method_info = method as SR.MethodInfo;
|
||||
reference.ReturnType = method_info != null ? ImportType(method_info.ReturnType, context) : ImportType(typeof(void), default);
|
||||
|
||||
SR.ParameterInfo[] parameters = method.GetParameters();
|
||||
Collection<ParameterDefinition> reference_parameters = reference.Parameters;
|
||||
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
reference_parameters.Add(new(ImportType(parameters[i].ParameterType, context)));
|
||||
|
||||
reference.DeclaringType = declaring_type;
|
||||
|
||||
return reference;
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.Pop();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ImportGenericParameters(IGenericParameterProvider provider, Type[] arguments)
|
||||
{
|
||||
Collection<GenericParameter> provider_parameters = provider.GenericParameters;
|
||||
|
||||
for (int i = 0; i < arguments.Length; i++)
|
||||
provider_parameters.Add(new(arguments[i].Name, provider));
|
||||
}
|
||||
|
||||
private static bool IsMethodSpecification(SR.MethodBase method)
|
||||
{
|
||||
return method.IsGenericMethod && !method.IsGenericMethodDefinition;
|
||||
}
|
||||
|
||||
private MethodReference ImportMethodSpecification(SR.MethodBase method, ImportGenericContext context)
|
||||
{
|
||||
SR.MethodInfo method_info = method as SR.MethodInfo;
|
||||
if (method_info == null)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
MethodReference element_method = ImportMethod(method_info.GetGenericMethodDefinition(), context, ImportGenericKind.Definition);
|
||||
GenericInstanceMethod instance = new(element_method);
|
||||
Type[] arguments = method.GetGenericArguments();
|
||||
Collection<TypeReference> 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();
|
||||
}
|
||||
}
|
||||
|
||||
private 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
|
||||
{
|
||||
protected readonly ModuleDefinition module;
|
||||
|
||||
public DefaultMetadataImporter(ModuleDefinition module)
|
||||
{
|
||||
Mixin.CheckModule(module);
|
||||
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
private TypeReference ImportType(TypeReference type, ImportGenericContext context)
|
||||
{
|
||||
if (type.IsTypeSpecification())
|
||||
return ImportTypeSpecification(type, context);
|
||||
|
||||
TypeReference reference = new(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(name.Name, name.Version)
|
||||
{
|
||||
Culture = name.Culture,
|
||||
HashAlgorithm = name.HashAlgorithm,
|
||||
IsRetargetable = name.IsRetargetable,
|
||||
IsWindowsRuntime = name.IsWindowsRuntime
|
||||
};
|
||||
|
||||
byte[] 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);
|
||||
}
|
||||
|
||||
private static void ImportGenericParameters(IGenericParameterProvider imported, IGenericParameterProvider original)
|
||||
{
|
||||
Collection<GenericParameter> parameters = original.GenericParameters;
|
||||
Collection<GenericParameter> imported_parameters = imported.GenericParameters;
|
||||
|
||||
for (int i = 0; i < parameters.Count; i++)
|
||||
imported_parameters.Add(new(parameters[i].Name, imported));
|
||||
}
|
||||
|
||||
private TypeReference ImportTypeSpecification(TypeReference type, ImportGenericContext context)
|
||||
{
|
||||
switch (type.etype)
|
||||
{
|
||||
case ElementType.SzArray:
|
||||
ArrayType vector = (ArrayType)type;
|
||||
return new ArrayType(ImportType(vector.ElementType, context));
|
||||
case ElementType.Ptr:
|
||||
PointerType pointer = (PointerType)type;
|
||||
return new PointerType(ImportType(pointer.ElementType, context));
|
||||
case ElementType.ByRef:
|
||||
ByReferenceType byref = (ByReferenceType)type;
|
||||
return new ByReferenceType(ImportType(byref.ElementType, context));
|
||||
case ElementType.Pinned:
|
||||
PinnedType pinned = (PinnedType)type;
|
||||
return new PinnedType(ImportType(pinned.ElementType, context));
|
||||
case ElementType.Sentinel:
|
||||
SentinelType sentinel = (SentinelType)type;
|
||||
return new SentinelType(ImportType(sentinel.ElementType, context));
|
||||
case ElementType.FnPtr:
|
||||
FunctionPointerType fnptr = (FunctionPointerType)type;
|
||||
FunctionPointerType imported_fnptr = new()
|
||||
{
|
||||
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(ImportType(fnptr.Parameters[i].ParameterType, context)));
|
||||
|
||||
return imported_fnptr;
|
||||
case ElementType.CModOpt:
|
||||
OptionalModifierType modopt = (OptionalModifierType)type;
|
||||
return new OptionalModifierType(ImportType(modopt.ModifierType, context), ImportType(modopt.ElementType, context));
|
||||
case ElementType.CModReqD:
|
||||
RequiredModifierType modreq = (RequiredModifierType)type;
|
||||
return new RequiredModifierType(ImportType(modreq.ModifierType, context), ImportType(modreq.ElementType, context));
|
||||
case ElementType.Array:
|
||||
ArrayType array = (ArrayType)type;
|
||||
ArrayType imported_array = new(ImportType(array.ElementType, context));
|
||||
if (array.IsVector)
|
||||
return imported_array;
|
||||
|
||||
Collection<ArrayDimension> dimensions = array.Dimensions;
|
||||
Collection<ArrayDimension> imported_dimensions = imported_array.Dimensions;
|
||||
|
||||
imported_dimensions.Clear();
|
||||
|
||||
for (int i = 0; i < dimensions.Count; i++)
|
||||
{
|
||||
ArrayDimension dimension = dimensions[i];
|
||||
|
||||
imported_dimensions.Add(new(dimension.LowerBound, dimension.UpperBound));
|
||||
}
|
||||
|
||||
return imported_array;
|
||||
case ElementType.GenericInst:
|
||||
GenericInstanceType instance = (GenericInstanceType)type;
|
||||
TypeReference element_type = ImportType(instance.ElementType, context);
|
||||
Collection<TypeReference> arguments = instance.GenericArguments;
|
||||
GenericInstanceType imported_instance = new(element_type, arguments.Count);
|
||||
Collection<TypeReference> 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:
|
||||
GenericParameter 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:
|
||||
GenericParameter 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());
|
||||
}
|
||||
|
||||
private FieldReference ImportField(FieldReference field, ImportGenericContext context)
|
||||
{
|
||||
TypeReference declaring_type = ImportType(field.DeclaringType, context);
|
||||
|
||||
context.Push(declaring_type);
|
||||
try
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = field.Name,
|
||||
DeclaringType = declaring_type,
|
||||
FieldType = ImportType(field.FieldType, context)
|
||||
};
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.Pop();
|
||||
}
|
||||
}
|
||||
|
||||
private MethodReference ImportMethod(MethodReference method, ImportGenericContext context)
|
||||
{
|
||||
if (method.IsGenericInstance)
|
||||
return ImportMethodSpecification(method, context);
|
||||
|
||||
TypeReference declaring_type = ImportType(method.DeclaringType, context);
|
||||
|
||||
MethodReference reference = new()
|
||||
{
|
||||
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;
|
||||
|
||||
Collection<ParameterDefinition> parameters = method.Parameters;
|
||||
ParameterDefinitionCollection reference_parameters = reference.parameters = new(reference, parameters.Count);
|
||||
for (int i = 0; i < parameters.Count; i++)
|
||||
reference_parameters.Add(new(ImportType(parameters[i].ParameterType, context)));
|
||||
|
||||
return reference;
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.Pop();
|
||||
}
|
||||
}
|
||||
|
||||
private MethodSpecification ImportMethodSpecification(MethodReference method, ImportGenericContext context)
|
||||
{
|
||||
if (!method.IsGenericInstance)
|
||||
throw new NotSupportedException();
|
||||
|
||||
GenericInstanceMethod instance = (GenericInstanceMethod)method;
|
||||
MethodReference element_method = ImportMethod(instance.ElementMethod, context);
|
||||
GenericInstanceMethod imported_instance = new(element_method);
|
||||
|
||||
Collection<TypeReference> arguments = instance.GenericArguments;
|
||||
Collection<TypeReference> 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));
|
||||
}
|
||||
}
|
||||
|
||||
internal 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)
|
||||
{
|
||||
Collection<AssemblyNameReference> references = module.AssemblyReferences;
|
||||
|
||||
for (int i = 0; i < references.Count; i++)
|
||||
{
|
||||
AssemblyNameReference reference = references[i];
|
||||
if (!Equals(name_reference, reference))
|
||||
continue;
|
||||
|
||||
assembly_reference = reference;
|
||||
return true;
|
||||
}
|
||||
|
||||
assembly_reference = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa57d261f1a90c746abaef3d59b4c655
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/Import.cs
|
||||
uploadId: 866910
|
||||
@@ -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.
|
||||
//
|
||||
|
||||
namespace MonoFN.Cecil
|
||||
{
|
||||
public sealed class LinkedResource : Resource
|
||||
{
|
||||
internal byte[] hash;
|
||||
public byte[] Hash
|
||||
{
|
||||
get { return hash; }
|
||||
}
|
||||
public string File { get; set; }
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18c45c1a0891fdc40a07d309b564ec6d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/LinkedResource.cs
|
||||
uploadId: 866910
|
||||
@@ -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.
|
||||
//
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 136b98b695702f048857ea31d91193fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/ManifestResourceAttributes.cs
|
||||
uploadId: 866910
|
||||
@@ -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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 081d03dc18ced1648ae4d9f2eefd3370
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/MarshalInfo.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
internal sealed class MemberDefinitionCollection<T> : Collection<T> where T : IMemberDefinition
|
||||
{
|
||||
private 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 (T definition in this)
|
||||
Detach(definition);
|
||||
}
|
||||
|
||||
private void Attach(T element)
|
||||
{
|
||||
if (element.DeclaringType == container)
|
||||
return;
|
||||
|
||||
if (element.DeclaringType != null)
|
||||
throw new ArgumentException("Member already attached");
|
||||
|
||||
element.DeclaringType = container;
|
||||
}
|
||||
|
||||
private static void Detach(T element)
|
||||
{
|
||||
element.DeclaringType = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5caa999f42a585459c62b7b65eefdd8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/MemberDefinitionCollection.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
private string name;
|
||||
private 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
|
||||
{
|
||||
ModuleDefinition 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dcf551ad731c204fa148ec1ee0ce881
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/MemberReference.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,386 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
public MemberReference Member { get; }
|
||||
public IMetadataScope Scope
|
||||
{
|
||||
get
|
||||
{
|
||||
TypeReference type = Member as TypeReference;
|
||||
if (type != null)
|
||||
return type.Scope;
|
||||
|
||||
TypeReference 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
|
||||
private ResolutionException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
|
||||
#endif
|
||||
}
|
||||
|
||||
public class MetadataResolver : IMetadataResolver
|
||||
{
|
||||
public IAssemblyResolver AssemblyResolver { get; }
|
||||
|
||||
public MetadataResolver(IAssemblyResolver assemblyResolver)
|
||||
{
|
||||
if (assemblyResolver == null)
|
||||
throw new ArgumentNullException("assemblyResolver");
|
||||
|
||||
AssemblyResolver = assemblyResolver;
|
||||
}
|
||||
|
||||
public virtual TypeDefinition Resolve(TypeReference type)
|
||||
{
|
||||
Mixin.CheckType(type);
|
||||
|
||||
type = type.GetElementType();
|
||||
|
||||
IMetadataScope scope = type.Scope;
|
||||
|
||||
if (scope == null)
|
||||
return null;
|
||||
|
||||
switch (scope.MetadataScopeType)
|
||||
{
|
||||
case MetadataScopeType.AssemblyNameReference:
|
||||
AssemblyDefinition assembly = AssemblyResolver.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;
|
||||
|
||||
Collection<ModuleDefinition> modules = type.Module.Assembly.Modules;
|
||||
ModuleReference module_ref = (ModuleReference)scope;
|
||||
for (int i = 0; i < modules.Count; i++)
|
||||
{
|
||||
ModuleDefinition netmodule = modules[i];
|
||||
if (netmodule.Name == module_ref.Name)
|
||||
return GetType(netmodule, type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
private static TypeDefinition GetType(ModuleDefinition module, TypeReference reference)
|
||||
{
|
||||
TypeDefinition type = GetTypeDefinition(module, reference);
|
||||
if (type != null)
|
||||
return type;
|
||||
|
||||
if (!module.HasExportedTypes)
|
||||
return null;
|
||||
|
||||
Collection<ExportedType> exported_types = module.ExportedTypes;
|
||||
|
||||
for (int i = 0; i < exported_types.Count; i++)
|
||||
{
|
||||
ExportedType 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;
|
||||
}
|
||||
|
||||
private static TypeDefinition GetTypeDefinition(ModuleDefinition module, TypeReference type)
|
||||
{
|
||||
if (!type.IsNested)
|
||||
return module.GetType(type.Namespace, type.Name);
|
||||
|
||||
TypeDefinition 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);
|
||||
|
||||
TypeDefinition type = Resolve(field.DeclaringType);
|
||||
if (type == null)
|
||||
return null;
|
||||
|
||||
if (!type.HasFields)
|
||||
return null;
|
||||
|
||||
return GetField(type, field);
|
||||
}
|
||||
|
||||
private FieldDefinition GetField(TypeDefinition type, FieldReference reference)
|
||||
{
|
||||
while (type != null)
|
||||
{
|
||||
FieldDefinition field = GetField(type.Fields, reference);
|
||||
if (field != null)
|
||||
return field;
|
||||
|
||||
if (type.BaseType == null)
|
||||
return null;
|
||||
|
||||
type = Resolve(type.BaseType);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static FieldDefinition GetField(Collection<FieldDefinition> fields, FieldReference reference)
|
||||
{
|
||||
for (int i = 0; i < fields.Count; i++)
|
||||
{
|
||||
FieldDefinition 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);
|
||||
|
||||
TypeDefinition type = Resolve(method.DeclaringType);
|
||||
if (type == null)
|
||||
return null;
|
||||
|
||||
method = method.GetElementMethod();
|
||||
|
||||
if (!type.HasMethods)
|
||||
return null;
|
||||
|
||||
return GetMethod(type, method);
|
||||
}
|
||||
|
||||
private MethodDefinition GetMethod(TypeDefinition type, MethodReference reference)
|
||||
{
|
||||
while (type != null)
|
||||
{
|
||||
MethodDefinition 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++)
|
||||
{
|
||||
MethodDefinition 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;
|
||||
}
|
||||
|
||||
private static bool AreSame(Collection<ParameterDefinition> a, Collection<ParameterDefinition> b)
|
||||
{
|
||||
int 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;
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
private static bool AreSame(ArrayType a, ArrayType b)
|
||||
{
|
||||
if (a.Rank != b.Rank)
|
||||
return false;
|
||||
|
||||
// TODO: dimensions
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool AreSame(IModifierType a, IModifierType b)
|
||||
{
|
||||
return AreSame(a.ModifierType, b.ModifierType);
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
private static bool AreSame(GenericParameter a, GenericParameter b)
|
||||
{
|
||||
return a.Position == b.Position;
|
||||
}
|
||||
|
||||
private 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdd2c926d773ffd4692e2d042135fd2b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/MetadataResolver.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,449 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
internal struct Range
|
||||
{
|
||||
public uint Start;
|
||||
public uint Length;
|
||||
|
||||
public Range(uint index, uint length)
|
||||
{
|
||||
Start = index;
|
||||
Length = length;
|
||||
}
|
||||
}
|
||||
|
||||
internal 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;
|
||||
private static Dictionary<string, Row<ElementType, bool>> primitive_value_types;
|
||||
|
||||
private static void InitializePrimitives()
|
||||
{
|
||||
Dictionary<string, Row<ElementType, bool>> types = new(18, StringComparer.Ordinal)
|
||||
{
|
||||
{ "Void", new(ElementType.Void, false) },
|
||||
{ "Boolean", new(ElementType.Boolean, true) },
|
||||
{ "Char", new(ElementType.Char, true) },
|
||||
{ "SByte", new(ElementType.I1, true) },
|
||||
{ "Byte", new(ElementType.U1, true) },
|
||||
{ "Int16", new(ElementType.I2, true) },
|
||||
{ "UInt16", new(ElementType.U2, true) },
|
||||
{ "Int32", new(ElementType.I4, true) },
|
||||
{ "UInt32", new(ElementType.U4, true) },
|
||||
{ "Int64", new(ElementType.I8, true) },
|
||||
{ "UInt64", new(ElementType.U8, true) },
|
||||
{ "Single", new(ElementType.R4, true) },
|
||||
{ "Double", new(ElementType.R8, true) },
|
||||
{ "String", new(ElementType.String, false) },
|
||||
{ "TypedReference", new(ElementType.TypedByRef, false) },
|
||||
{ "IntPtr", new(ElementType.I, true) },
|
||||
{ "UIntPtr", new(ElementType.U, true) },
|
||||
{ "Object", new(ElementType.Object, false) }
|
||||
};
|
||||
|
||||
Interlocked.CompareExchange(ref primitive_value_types, types, null);
|
||||
}
|
||||
|
||||
public static void TryProcessPrimitiveTypeReference(TypeReference type)
|
||||
{
|
||||
if (type.Namespace != "System")
|
||||
return;
|
||||
|
||||
IMetadataScope 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;
|
||||
}
|
||||
|
||||
private 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(capacity: 0);
|
||||
if (ReverseNestedTypes != null)
|
||||
ReverseNestedTypes = new(capacity: 0);
|
||||
if (Interfaces != null)
|
||||
Interfaces = new(capacity: 0);
|
||||
if (ClassLayouts != null)
|
||||
ClassLayouts = new(capacity: 0);
|
||||
if (FieldLayouts != null)
|
||||
FieldLayouts = new(capacity: 0);
|
||||
if (FieldRVAs != null)
|
||||
FieldRVAs = new(capacity: 0);
|
||||
if (FieldMarshals != null)
|
||||
FieldMarshals = new(capacity: 0);
|
||||
if (Constants != null)
|
||||
Constants = new(capacity: 0);
|
||||
if (Overrides != null)
|
||||
Overrides = new(capacity: 0);
|
||||
if (CustomAttributes != null)
|
||||
CustomAttributes = new(capacity: 0);
|
||||
if (SecurityDeclarations != null)
|
||||
SecurityDeclarations = new(capacity: 0);
|
||||
if (Events != null)
|
||||
Events = new(capacity: 0);
|
||||
if (Properties != null)
|
||||
Properties = new(capacity: 0);
|
||||
if (Semantics != null)
|
||||
Semantics = new(capacity: 0);
|
||||
if (PInvokes != null)
|
||||
PInvokes = new(capacity: 0);
|
||||
if (GenericParameters != null)
|
||||
GenericParameters = new(capacity: 0);
|
||||
if (GenericConstraints != null)
|
||||
GenericConstraints = new(capacity: 0);
|
||||
|
||||
Documents = Empty<Document>.Array;
|
||||
ImportScopes = Empty<ImportDebugInformation>.Array;
|
||||
if (LocalScopes != null)
|
||||
LocalScopes = new(capacity: 0);
|
||||
if (StateMachineMethods != null)
|
||||
StateMachineMethods = new(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);
|
||||
}
|
||||
|
||||
private 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;
|
||||
TypeDefinition type = types[mid];
|
||||
Range 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ea39c5122499d14fbca126d3ed39890
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/MetadataSystem.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84996fdfc826be145836c454e3781c51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/MethodAttributes.cs
|
||||
uploadId: 866910
|
||||
@@ -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 MethodCallingConvention : byte
|
||||
{
|
||||
Default = 0x0,
|
||||
C = 0x1,
|
||||
StdCall = 0x2,
|
||||
ThisCall = 0x3,
|
||||
FastCall = 0x4,
|
||||
VarArg = 0x5,
|
||||
Generic = 0x10
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d279830051a3cf4a9a8198756171875
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/MethodCallingConvention.cs
|
||||
uploadId: 866910
|
||||
@@ -0,0 +1,564 @@
|
||||
//
|
||||
// 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
|
||||
{
|
||||
private ushort attributes;
|
||||
private ushort impl_attributes;
|
||||
internal volatile bool sem_attrs_ready;
|
||||
internal MethodSemanticsAttributes sem_attrs;
|
||||
private Collection<CustomAttribute> custom_attributes;
|
||||
private Collection<SecurityDeclaration> security_declarations;
|
||||
internal RVA rva;
|
||||
internal PInvokeInfo pinvoke;
|
||||
private 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;
|
||||
|
||||
ModuleDefinition module = 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
|
||||
{
|
||||
MethodBody local = 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(this), null);
|
||||
|
||||
return body;
|
||||
}
|
||||
set
|
||||
{
|
||||
ModuleDefinition module = 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)
|
||||
debug_info = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
public MethodDebugInformation DebugInformation
|
||||
{
|
||||
get
|
||||
{
|
||||
Mixin.Read(Body);
|
||||
|
||||
if (debug_info == null)
|
||||
{
|
||||
Interlocked.CompareExchange(ref debug_info, new(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(), 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(), 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 IsRuntimeSpecialName && IsSpecialName && (Name == ".cctor" || Name == ".ctor"); }
|
||||
}
|
||||
public override bool IsDefinition
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
internal MethodDefinition()
|
||||
{
|
||||
token = new(TokenType.Method);
|
||||
}
|
||||
|
||||
public MethodDefinition(string name, MethodAttributes attributes, TypeReference returnType) : base(name, returnType)
|
||||
{
|
||||
this.attributes = (ushort)attributes;
|
||||
HasThis = !IsStatic;
|
||||
token = new(TokenType.Method);
|
||||
}
|
||||
|
||||
public override MethodDefinition Resolve()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
internal static partial class Mixin
|
||||
{
|
||||
public static ParameterDefinition GetParameter(this MethodBody self, int index)
|
||||
{
|
||||
MethodDefinition method = self.method;
|
||||
|
||||
if (method.HasThis)
|
||||
{
|
||||
if (index == 0)
|
||||
return self.ThisParameter;
|
||||
|
||||
index--;
|
||||
}
|
||||
|
||||
Collection<ParameterDefinition> parameters = method.Parameters;
|
||||
|
||||
if (index < 0 || index >= parameters.size)
|
||||
return null;
|
||||
|
||||
return parameters[index];
|
||||
}
|
||||
|
||||
public static VariableDefinition GetVariable(this MethodBody self, int index)
|
||||
{
|
||||
Collection<VariableDefinition> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51ade7e624f84ae4abb8dc28a51b3082
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 207815
|
||||
packageName: 'FishNet: Networking Evolved'
|
||||
packageVersion: 4.6.22R
|
||||
assetPath: Assets/FishNet/CodeGenerating/cecil-0.11.4/Mono.Cecil/MethodDefinition.cs
|
||||
uploadId: 866910
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user