<Compile Include="$(BclSourcesRoot)\Internal\Console.cs" />
</ItemGroup>
<ItemGroup>
- <Compile Include="$(BclSourcesRoot)\System\Reflection\__Filters.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\AmbiguousMatchException.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Reflection\Assembly.cs" />
+ <Compile Include="$(BclSourcesRoot)\System\Reflection\Assembly.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\AssemblyAttributes.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\AssemblyName.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\AssemblyNameFlags.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodImplAttributes.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Missing.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Module.cs" />
+ <Compile Include="$(BclSourcesRoot)\System\Reflection\Module.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ModuleResolveEventHandler.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodBody.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ParameterAttributes.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Reflection\ParameterInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ParameterModifier.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Pointer.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\PortableExecutableKinds.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ParamArrayAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\PlatformNotSupportedException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\RankException.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Assembly.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ConstructorInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\FieldInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscateAssemblyAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscationAttribute.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ParameterInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\PropertyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeDelegator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeInfo.cs" />
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.IO;
+using System.Globalization;
+using System.Collections.Generic;
+using System.Configuration.Assemblies;
+using System.Runtime.Serialization;
+using System.Security;
+
+namespace System.Reflection
+{
+ public abstract partial class Assembly : ICustomAttributeProvider, ISerializable
+ {
+ protected Assembly() { }
+
+ public virtual IEnumerable<TypeInfo> DefinedTypes
+ {
+ get
+ {
+ Type[] types = GetTypes();
+ TypeInfo[] typeinfos = new TypeInfo[types.Length];
+ for (int i = 0; i < types.Length; i++)
+ {
+ TypeInfo typeinfo = types[i].GetTypeInfo();
+ if (typeinfo == null)
+ throw new NotSupportedException(SR.Format(SR.NotSupported_NoTypeInfo, types[i].FullName));
+
+ typeinfos[i] = typeinfo;
+ }
+ return typeinfos;
+ }
+ }
+
+ public virtual Type[] GetTypes()
+ {
+ Module[] m = GetModules(false);
+
+ int finalLength = 0;
+ Type[][] moduleTypes = new Type[m.Length][];
+
+ for (int i = 0; i < moduleTypes.Length; i++)
+ {
+ moduleTypes[i] = m[i].GetTypes();
+ finalLength += moduleTypes[i].Length;
+ }
+
+ int current = 0;
+ Type[] ret = new Type[finalLength];
+ for (int i = 0; i < moduleTypes.Length; i++)
+ {
+ int length = moduleTypes[i].Length;
+ Array.Copy(moduleTypes[i], 0, ret, current, length);
+ current += length;
+ }
+
+ return ret;
+ }
+
+ public virtual IEnumerable<Type> ExportedTypes => GetExportedTypes();
+ public virtual Type[] GetExportedTypes() { throw NotImplemented.ByDesign; }
+
+ public virtual string CodeBase { get { throw NotImplemented.ByDesign; } }
+ public virtual MethodInfo EntryPoint { get { throw NotImplemented.ByDesign; } }
+ public virtual string FullName { get { throw NotImplemented.ByDesign; } }
+ public virtual string ImageRuntimeVersion { get { throw NotImplemented.ByDesign; } }
+ public virtual bool IsDynamic => false;
+ public virtual string Location { get { throw NotImplemented.ByDesign; } }
+ public virtual bool ReflectionOnly { get { throw NotImplemented.ByDesign; } }
+
+ public virtual ManifestResourceInfo GetManifestResourceInfo(string resourceName) { throw NotImplemented.ByDesign; }
+ public virtual string[] GetManifestResourceNames() { throw NotImplemented.ByDesign; }
+ public virtual Stream GetManifestResourceStream(string name) { throw NotImplemented.ByDesign; }
+ public virtual Stream GetManifestResourceStream(Type type, string name) { throw NotImplemented.ByDesign; }
+
+ public bool IsFullyTrusted => true;
+
+ public virtual AssemblyName GetName() => GetName(copiedName: false);
+ public virtual AssemblyName GetName(bool copiedName) { throw NotImplemented.ByDesign; }
+
+ public virtual Type GetType(string name) => GetType(name, throwOnError: false, ignoreCase: false);
+ public virtual Type GetType(string name, bool throwOnError) => GetType(name, throwOnError: throwOnError, ignoreCase: false);
+ public virtual Type GetType(string name, bool throwOnError, bool ignoreCase) { throw NotImplemented.ByDesign; }
+
+ public virtual bool IsDefined(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; }
+
+ public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
+ public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
+
+ public virtual object[] GetCustomAttributes(bool inherit) { throw NotImplemented.ByDesign; }
+ public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; }
+
+ public virtual string EscapedCodeBase => AssemblyName.EscapeCodeBase(CodeBase);
+
+ public object CreateInstance(string typeName) => CreateInstance(typeName, false, BindingFlags.Public | BindingFlags.Instance, binder: null, args: null, culture: null, activationAttributes: null);
+ public object CreateInstance(string typeName, bool ignoreCase) => CreateInstance(typeName, ignoreCase, BindingFlags.Public | BindingFlags.Instance, binder: null, args: null, culture: null, activationAttributes: null);
+ public virtual object CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
+ {
+ Type t = GetType(typeName, throwOnError: false, ignoreCase: ignoreCase);
+ if (t == null)
+ return null;
+
+ return Activator.CreateInstance(t, bindingAttr, binder, args, culture, activationAttributes);
+ }
+
+ public virtual event ModuleResolveEventHandler ModuleResolve { add { throw NotImplemented.ByDesign; } remove { throw NotImplemented.ByDesign; } }
+
+ public virtual Module ManifestModule { get { throw NotImplemented.ByDesign; } }
+ public virtual Module GetModule(string name) { throw NotImplemented.ByDesign; }
+
+ public Module[] GetModules() => GetModules(getResourceModules: false);
+ public virtual Module[] GetModules(bool getResourceModules) { throw NotImplemented.ByDesign; }
+
+ public virtual IEnumerable<Module> Modules => GetLoadedModules(getResourceModules: true);
+ public Module[] GetLoadedModules() => GetLoadedModules(getResourceModules: false);
+ public virtual Module[] GetLoadedModules(bool getResourceModules) { throw NotImplemented.ByDesign; }
+
+ public virtual AssemblyName[] GetReferencedAssemblies() { throw NotImplemented.ByDesign; }
+
+ public virtual Assembly GetSatelliteAssembly(CultureInfo culture) { throw NotImplemented.ByDesign; }
+ public virtual Assembly GetSatelliteAssembly(CultureInfo culture, Version version) { throw NotImplemented.ByDesign; }
+
+ public virtual FileStream GetFile(string name) { throw NotImplemented.ByDesign; }
+ public virtual FileStream[] GetFiles() => GetFiles(getResourceModules: false);
+ public virtual FileStream[] GetFiles(bool getResourceModules) { throw NotImplemented.ByDesign; }
+
+ public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { throw NotImplemented.ByDesign; }
+
+ public override string ToString()
+ {
+ string displayName = FullName;
+ if (displayName == null)
+ return base.ToString();
+ else
+ return displayName;
+ }
+
+ /*
+ Returns true if the assembly was loaded from the global assembly cache.
+ */
+ public virtual bool GlobalAssemblyCache { get { throw NotImplemented.ByDesign; } }
+ public virtual Int64 HostContext { get { throw NotImplemented.ByDesign; } }
+
+ public override bool Equals(object o) => base.Equals(o);
+ public override int GetHashCode() => base.GetHashCode();
+
+ public static bool operator ==(Assembly left, Assembly right)
+ {
+ if (object.ReferenceEquals(left, right))
+ return true;
+
+ if ((object)left == null || (object)right == null)
+ return false;
+
+ return left.Equals(right);
+ }
+
+ public static bool operator !=(Assembly left, Assembly right)
+ {
+ return !(left == right);
+ }
+
+ public static string CreateQualifiedName(string assemblyName, string typeName) => typeName + ", " + assemblyName;
+
+ public static Assembly GetAssembly(Type type)
+ {
+ if (type == null)
+ throw new ArgumentNullException(nameof(type));
+
+ Module m = type.Module;
+ if (m == null)
+ return null;
+ else
+ return m.Assembly;
+ }
+
+ public static Assembly Load(byte[] rawAssembly) => Load(rawAssembly, rawSymbolStore: null);
+
+ [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")]
+ public static Assembly LoadWithPartialName(string partialName)
+ {
+ if (partialName == null)
+ throw new ArgumentNullException(nameof(partialName));
+
+ return Load(partialName);
+ }
+
+ public static Assembly UnsafeLoadFrom(string assemblyFile) => LoadFrom(assemblyFile);
+
+ public Module LoadModule(string moduleName, byte[] rawModule) => LoadModule(moduleName, rawModule, null);
+ public virtual Module LoadModule(string moduleName, byte[] rawModule, byte[] rawSymbolStore) { throw NotImplemented.ByDesign; }
+
+ public static Assembly ReflectionOnlyLoad(byte[] rawAssembly) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }
+ public static Assembly ReflectionOnlyLoad(string assemblyString) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }
+ public static Assembly ReflectionOnlyLoadFrom(string assemblyFile) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }
+
+ public virtual SecurityRuleSet SecurityRuleSet => SecurityRuleSet.None;
+ }
+}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Generic;
+using System.Runtime.Serialization;
+
+namespace System.Reflection
+{
+ public class ParameterInfo : ICustomAttributeProvider, IObjectReference
+ {
+ protected ParameterInfo() { }
+
+ public virtual ParameterAttributes Attributes => AttrsImpl;
+ public virtual MemberInfo Member => MemberImpl;
+ public virtual string Name => NameImpl;
+ public virtual Type ParameterType => ClassImpl;
+ public virtual int Position => PositionImpl;
+
+ public bool IsIn => (Attributes & ParameterAttributes.In) != 0;
+ public bool IsLcid => (Attributes & ParameterAttributes.Lcid) != 0;
+ public bool IsOptional => (Attributes & ParameterAttributes.Optional) != 0;
+ public bool IsOut => (Attributes & ParameterAttributes.Out) != 0;
+ public bool IsRetval => (Attributes & ParameterAttributes.Retval) != 0;
+
+ public virtual object DefaultValue { get { throw NotImplemented.ByDesign; } }
+ public virtual object RawDefaultValue { get { throw NotImplemented.ByDesign; } }
+ public virtual bool HasDefaultValue { get { throw NotImplemented.ByDesign; } }
+
+ public virtual bool IsDefined(Type attributeType, bool inherit)
+ {
+ if (attributeType == null)
+ throw new ArgumentNullException(nameof(attributeType));
+
+ return false;
+ }
+
+ public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
+ public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
+
+ public virtual object[] GetCustomAttributes(bool inherit) => Array.Empty<object>();
+ public virtual object[] GetCustomAttributes(Type attributeType, bool inherit)
+ {
+ if (attributeType == null)
+ throw new ArgumentNullException(nameof(attributeType));
+
+ return Array.Empty<object>();
+ }
+
+ public virtual Type[] GetOptionalCustomModifiers() => Array.Empty<Type>();
+ public virtual Type[] GetRequiredCustomModifiers() => Array.Empty<Type>();
+
+ public virtual int MetadataToken => MetadataToken_ParamDef;
+
+ public object GetRealObject(StreamingContext context)
+ {
+ // Once all the serializable fields have come in we can set up the real
+ // instance based on just two of them (MemberImpl and PositionImpl).
+
+ if (MemberImpl == null)
+ throw new SerializationException(SR.Serialization_InsufficientState);
+
+ ParameterInfo[] args = null;
+
+ switch (MemberImpl.MemberType)
+ {
+ case MemberTypes.Constructor:
+ case MemberTypes.Method:
+ if (PositionImpl == -1)
+ {
+ if (MemberImpl.MemberType == MemberTypes.Method)
+ return ((MethodInfo)MemberImpl).ReturnParameter;
+ else
+ throw new SerializationException(SR.Serialization_BadParameterInfo);
+ }
+ else
+ {
+ args = ((MethodBase)MemberImpl).GetParametersNoCopy();
+
+ if (args != null && PositionImpl < args.Length)
+ return args[PositionImpl];
+ else
+ throw new SerializationException(SR.Serialization_BadParameterInfo);
+ }
+
+ case MemberTypes.Property:
+ args = ((PropertyInfo)MemberImpl).GetIndexParameters();
+
+ if (args != null && PositionImpl > -1 && PositionImpl < args.Length)
+ return args[PositionImpl];
+ else
+ throw new SerializationException(SR.Serialization_BadParameterInfo);
+
+ default:
+ throw new SerializationException(SR.Serialization_NoParameterInfo);
+ }
+ }
+
+ public override string ToString() => ParameterType.FormatTypeName() + " " + Name;
+
+ protected ParameterAttributes AttrsImpl;
+ protected Type ClassImpl;
+ protected object DefaultValueImpl;
+ protected MemberInfo MemberImpl;
+ protected string NameImpl;
+ protected int PositionImpl;
+
+ private const int MetadataToken_ParamDef = 0x08000000;
+ }
+}
internal static string NotSupported_AbstractNonCLS =>
Environment.GetResourceString("NotSupported_AbstractNonCLS");
+
+ internal static string Serialization_InsufficientState =>
+ Environment.GetResourceString("Serialization_InsufficientState");
+
+ internal static string Serialization_BadParameterInfo =>
+ Environment.GetResourceString("Serialization_BadParameterInfo");
+
+ internal static string Serialization_NoParameterInfo =>
+ Environment.GetResourceString("Serialization_NoParameterInfo");
+
+ internal static string InvalidFilterCriteriaException_CritString =>
+ Environment.GetResourceString("InvalidFilterCriteriaException_CritString");
+
+ internal static string NotSupported_NoTypeInfo =>
+ Environment.GetResourceString("NotSupported_NoTypeInfo");
+
+ internal static string PlatformNotSupported_ReflectionOnly =>
+ Environment.GetResourceString("PlatformNotSupported_ReflectionOnly");
}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Generic;
+using System.Security.Policy;
+using System.IO;
+using System.Configuration.Assemblies;
+using StackCrawlMark = System.Threading.StackCrawlMark;
+using System.Runtime.Serialization;
+using System.Diagnostics.Contracts;
+using System.Runtime.Loader;
+
+namespace System.Reflection
+{
+ public abstract partial class Assembly : ICustomAttributeProvider, ISerializable
+ {
+ public static Assembly LoadFrom(String assemblyFile)
+ {
+ if (assemblyFile == null)
+ throw new ArgumentNullException(nameof(assemblyFile));
+ string fullPath = Path.GetFullPath(assemblyFile);
+ return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath);
+ }
+
+ // Evidence is protected in Assembly.Load()
+ [Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of LoadFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+ internal static Assembly LoadFrom(String assemblyFile,
+ Evidence securityEvidence)
+ {
+ Contract.Ensures(Contract.Result<Assembly>() != null);
+
+ StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+
+ return RuntimeAssembly.InternalLoadFrom(
+ assemblyFile,
+ securityEvidence,
+ null, // hashValue
+ AssemblyHashAlgorithm.None,
+ false,// forIntrospection);
+ ref stackMark);
+ }
+
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+ public static Assembly LoadFrom(String assemblyFile,
+ byte[] hashValue,
+ AssemblyHashAlgorithm hashAlgorithm)
+ {
+ throw new NotSupportedException(Environment.GetResourceString("NotSupported_AssemblyLoadFromHash"));
+ }
+
+ // Locate an assembly by the long form of the assembly name.
+ // eg. "Toolbox.dll, version=1.1.10.1220, locale=en, publickey=1234567890123456789012345678901234567890"
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+ public static Assembly Load(String assemblyString)
+ {
+ Contract.Ensures(Contract.Result<Assembly>() != null);
+ Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
+
+ StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+ return RuntimeAssembly.InternalLoad(assemblyString, null, ref stackMark, false /*forIntrospection*/);
+ }
+
+ // Returns type from the assembly while keeping compatibility with Assembly.Load(assemblyString).GetType(typeName) for managed types.
+ // Calls Type.GetType for WinRT types.
+ // Note: Type.GetType fails for assembly names that start with weird characters like '['. By calling it for managed types we would
+ // break AppCompat.
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+ internal static Type GetType_Compat(String assemblyString, String typeName)
+ {
+ // Normally we would get the stackMark only in public APIs. This is internal API, but it is AppCompat replacement of public API
+ // call Assembly.Load(assemblyString).GetType(typeName), therefore we take the stackMark here as well, to be fully compatible with
+ // the call sequence.
+ StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+
+ RuntimeAssembly assembly;
+ AssemblyName assemblyName = RuntimeAssembly.CreateAssemblyName(
+ assemblyString,
+ false /*forIntrospection*/,
+ out assembly);
+
+ if (assembly == null)
+ {
+ if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
+ {
+ return Type.GetType(typeName + ", " + assemblyString, true /*throwOnError*/, false /*ignoreCase*/);
+ }
+
+ assembly = RuntimeAssembly.InternalLoadAssemblyName(
+ assemblyName, null, null, ref stackMark,
+ true /*thrownOnFileNotFound*/, false /*forIntrospection*/);
+ }
+ return assembly.GetType(typeName, true /*throwOnError*/, false /*ignoreCase*/);
+ }
+
+ // Locate an assembly by its name. The name can be strong or
+ // weak. The assembly is loaded into the domain of the caller.
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+ public static Assembly Load(AssemblyName assemblyRef)
+ {
+ Contract.Ensures(Contract.Result<Assembly>() != null);
+ Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
+
+ if (assemblyRef != null && assemblyRef.CodeBase != null)
+ {
+ throw new NotSupportedException(Environment.GetResourceString("NotSupported_AssemblyLoadCodeBase"));
+ }
+
+ StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+ return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/);
+ }
+
+ // Locate an assembly by its name. The name can be strong or
+ // weak. The assembly is loaded into the domain of the caller.
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+ internal static Assembly Load(AssemblyName assemblyRef, IntPtr ptrLoadContextBinder)
+ {
+ Contract.Ensures(Contract.Result<Assembly>() != null);
+ Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
+
+ if (assemblyRef != null && assemblyRef.CodeBase != null)
+ {
+ throw new NotSupportedException(Environment.GetResourceString("NotSupported_AssemblyLoadCodeBase"));
+ }
+
+ StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+ return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/, ptrLoadContextBinder);
+ }
+
+ // Loads the assembly with a COFF based IMAGE containing
+ // an emitted assembly. The assembly is loaded into the domain
+ // of the caller. The second parameter is the raw bytes
+ // representing the symbol store that matches the assembly.
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+ public static Assembly Load(byte[] rawAssembly,
+ byte[] rawSymbolStore)
+ {
+ Contract.Ensures(Contract.Result<Assembly>() != null);
+ Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
+
+ AppDomain.CheckLoadByteArraySupported();
+
+ if (rawAssembly == null)
+ throw new ArgumentNullException(nameof(rawAssembly));
+ AssemblyLoadContext alc = new IndividualAssemblyLoadContext();
+ MemoryStream assemblyStream = new MemoryStream(rawAssembly);
+ MemoryStream symbolStream = (rawSymbolStore != null) ? new MemoryStream(rawSymbolStore) : null;
+ return alc.LoadFromStream(assemblyStream, symbolStream);
+ }
+
+ private static Dictionary<string, Assembly> s_loadfile = new Dictionary<string, Assembly>();
+
+ public static Assembly LoadFile(String path)
+ {
+ Contract.Ensures(Contract.Result<Assembly>() != null);
+ Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
+
+ AppDomain.CheckLoadFileSupported();
+
+ Assembly result = null;
+ if (path == null)
+ throw new ArgumentNullException(nameof(path));
+
+ if (PathInternal.IsPartiallyQualified(path))
+ {
+ throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), nameof(path));
+ }
+
+ string normalizedPath = Path.GetFullPath(path);
+
+ lock (s_loadfile)
+ {
+ if (s_loadfile.TryGetValue(normalizedPath, out result))
+ return result;
+ AssemblyLoadContext alc = new IndividualAssemblyLoadContext();
+ result = alc.LoadFromAssemblyPath(normalizedPath);
+ s_loadfile.Add(normalizedPath, result);
+ }
+ return result;
+ }
+
+ /*
+ * Get the assembly that the current code is running from.
+ */
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+ public static Assembly GetExecutingAssembly()
+ {
+ StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
+ return RuntimeAssembly.GetExecutingAssembly(ref stackMark);
+ }
+
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
+ public static Assembly GetCallingAssembly()
+ {
+ // LookForMyCallersCaller is not guarantee to return the correct stack frame
+ // because of inlining, tail calls, etc. As a result GetCallingAssembly is not
+ // ganranteed to return the correct result. We should document it as such.
+ StackCrawlMark stackMark = StackCrawlMark.LookForMyCallersCaller;
+ return RuntimeAssembly.GetExecutingAssembly(ref stackMark);
+ }
+
+ public static Assembly GetEntryAssembly()
+ {
+ AppDomainManager domainManager = AppDomain.CurrentDomain.DomainManager;
+ if (domainManager == null)
+ domainManager = new AppDomainManager();
+ return domainManager.EntryAssembly;
+ }
+ }
+}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using CultureInfo = System.Globalization.CultureInfo;
-using System.Security;
-using System.Security.Policy;
-using System.IO;
-using System.Configuration.Assemblies;
-using StackCrawlMark = System.Threading.StackCrawlMark;
-using System.Runtime.Serialization;
-using System.Diagnostics.Contracts;
-using System.Runtime.Loader;
-
-namespace System.Reflection
-{
- [Serializable]
- public abstract class Assembly : ICustomAttributeProvider, ISerializable
- {
- protected Assembly() { }
-
- #region public static methods
-
- public static String CreateQualifiedName(String assemblyName, String typeName)
- {
- return typeName + ", " + assemblyName;
- }
-
- public static Assembly GetAssembly(Type type)
- {
- if (type == null)
- throw new ArgumentNullException(nameof(type));
- Contract.EndContractBlock();
-
- Module m = type.Module;
- if (m == null)
- return null;
- else
- return m.Assembly;
- }
-
- public static bool operator ==(Assembly left, Assembly right)
- {
- if (ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null ||
- left is RuntimeAssembly || right is RuntimeAssembly)
- {
- return false;
- }
- return left.Equals(right);
- }
-
- public static bool operator !=(Assembly left, Assembly right)
- {
- return !(left == right);
- }
-
- public override bool Equals(object o)
- {
- return base.Equals(o);
- }
-
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
-
- public static Assembly LoadFrom(String assemblyFile)
- {
- if (assemblyFile == null)
- throw new ArgumentNullException(nameof(assemblyFile));
- string fullPath = Path.GetFullPath(assemblyFile);
- return AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath);
- }
-
- // Locate an assembly for reflection by the name of the file containing the manifest.
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly ReflectionOnlyLoadFrom(String assemblyFile)
- {
- if (assemblyFile == null)
- throw new ArgumentNullException(nameof(assemblyFile));
- if (assemblyFile.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength"));
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_ReflectionOnlyLoad"));
- }
-
- // Evidence is protected in Assembly.Load()
- [Obsolete("This method is obsolete and will be removed in a future release of the .NET Framework. Please use an overload of LoadFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- internal static Assembly LoadFrom(String assemblyFile,
- Evidence securityEvidence)
- {
- Contract.Ensures(Contract.Result<Assembly>() != null);
-
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
-
- return RuntimeAssembly.InternalLoadFrom(
- assemblyFile,
- securityEvidence,
- null, // hashValue
- AssemblyHashAlgorithm.None,
- false,// forIntrospection);
- ref stackMark);
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly LoadFrom(String assemblyFile,
- byte[] hashValue,
- AssemblyHashAlgorithm hashAlgorithm)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_AssemblyLoadFromHash"));
- }
-
- public static Assembly UnsafeLoadFrom(string assemblyFile)
- {
- return LoadFrom(assemblyFile);
- }
-
- // Locate an assembly by the long form of the assembly name.
- // eg. "Toolbox.dll, version=1.1.10.1220, locale=en, publickey=1234567890123456789012345678901234567890"
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly Load(String assemblyString)
- {
- Contract.Ensures(Contract.Result<Assembly>() != null);
- Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
-
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeAssembly.InternalLoad(assemblyString, null, ref stackMark, false /*forIntrospection*/);
- }
-
- // Returns type from the assembly while keeping compatibility with Assembly.Load(assemblyString).GetType(typeName) for managed types.
- // Calls Type.GetType for WinRT types.
- // Note: Type.GetType fails for assembly names that start with weird characters like '['. By calling it for managed types we would
- // break AppCompat.
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- internal static Type GetType_Compat(String assemblyString, String typeName)
- {
- // Normally we would get the stackMark only in public APIs. This is internal API, but it is AppCompat replacement of public API
- // call Assembly.Load(assemblyString).GetType(typeName), therefore we take the stackMark here as well, to be fully compatible with
- // the call sequence.
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
-
- RuntimeAssembly assembly;
- AssemblyName assemblyName = RuntimeAssembly.CreateAssemblyName(
- assemblyString,
- false /*forIntrospection*/,
- out assembly);
-
- if (assembly == null)
- {
- if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
- {
- return Type.GetType(typeName + ", " + assemblyString, true /*throwOnError*/, false /*ignoreCase*/);
- }
-
- assembly = RuntimeAssembly.InternalLoadAssemblyName(
- assemblyName, null, null, ref stackMark,
- true /*thrownOnFileNotFound*/, false /*forIntrospection*/);
- }
- return assembly.GetType(typeName, true /*throwOnError*/, false /*ignoreCase*/);
- }
-
- // Locate an assembly for reflection by the long form of the assembly name.
- // eg. "Toolbox.dll, version=1.1.10.1220, locale=en, publickey=1234567890123456789012345678901234567890"
- //
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly ReflectionOnlyLoad(String assemblyString)
- {
- if (assemblyString == null)
- throw new ArgumentNullException(nameof(assemblyString));
- if (assemblyString.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength"));
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_ReflectionOnlyLoad"));
- }
-
- // Locate an assembly by its name. The name can be strong or
- // weak. The assembly is loaded into the domain of the caller.
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly Load(AssemblyName assemblyRef)
- {
- Contract.Ensures(Contract.Result<Assembly>() != null);
- Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
-
- if (assemblyRef != null && assemblyRef.CodeBase != null)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_AssemblyLoadCodeBase"));
- }
-
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/);
- }
-
- // Locate an assembly by its name. The name can be strong or
- // weak. The assembly is loaded into the domain of the caller.
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- internal static Assembly Load(AssemblyName assemblyRef, IntPtr ptrLoadContextBinder)
- {
- Contract.Ensures(Contract.Result<Assembly>() != null);
- Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
-
- if (assemblyRef != null && assemblyRef.CodeBase != null)
- {
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_AssemblyLoadCodeBase"));
- }
-
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeAssembly.InternalLoadAssemblyName(assemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/, ptrLoadContextBinder);
- }
-
- [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")]
- public static Assembly LoadWithPartialName(String partialName)
- {
- if (partialName == null)
- throw new ArgumentNullException(nameof(partialName));
- return Load(partialName);
- }
-
- // Loads the assembly with a COFF based IMAGE containing
- // an emitted assembly. The assembly is loaded into the domain
- // of the caller.
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly Load(byte[] rawAssembly)
- {
- Contract.Ensures(Contract.Result<Assembly>() != null);
- Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
-
- AppDomain.CheckLoadByteArraySupported();
-
- return Load(rawAssembly, null);
- }
-
- // Loads the assembly for reflection with a COFF based IMAGE containing
- // an emitted assembly. The assembly is loaded into the domain
- // of the caller.
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly ReflectionOnlyLoad(byte[] rawAssembly)
- {
- if (rawAssembly == null)
- throw new ArgumentNullException(nameof(rawAssembly));
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_ReflectionOnlyLoad"));
- }
-
- // Loads the assembly with a COFF based IMAGE containing
- // an emitted assembly. The assembly is loaded into the domain
- // of the caller. The second parameter is the raw bytes
- // representing the symbol store that matches the assembly.
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly Load(byte[] rawAssembly,
- byte[] rawSymbolStore)
- {
- Contract.Ensures(Contract.Result<Assembly>() != null);
- Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
-
- AppDomain.CheckLoadByteArraySupported();
-
- if (rawAssembly == null)
- throw new ArgumentNullException(nameof(rawAssembly));
- AssemblyLoadContext alc = new IndividualAssemblyLoadContext();
- MemoryStream assemblyStream = new MemoryStream(rawAssembly);
- MemoryStream symbolStream = (rawSymbolStore != null) ? new MemoryStream(rawSymbolStore) : null;
- return alc.LoadFromStream(assemblyStream, symbolStream);
- }
-
- private static Dictionary<string, Assembly> s_loadfile = new Dictionary<string, Assembly>();
-
- public static Assembly LoadFile(String path)
- {
- Contract.Ensures(Contract.Result<Assembly>() != null);
- Contract.Ensures(!Contract.Result<Assembly>().ReflectionOnly);
-
- AppDomain.CheckLoadFileSupported();
-
- Assembly result = null;
- if (path == null)
- throw new ArgumentNullException(nameof(path));
-
- if (PathInternal.IsPartiallyQualified(path))
- {
- throw new ArgumentException(Environment.GetResourceString("Argument_AbsolutePathRequired"), nameof(path));
- }
-
- string normalizedPath = Path.GetFullPath(path);
-
- lock (s_loadfile)
- {
- if (s_loadfile.TryGetValue(normalizedPath, out result))
- return result;
- AssemblyLoadContext alc = new IndividualAssemblyLoadContext();
- result = alc.LoadFromAssemblyPath(normalizedPath);
- s_loadfile.Add(normalizedPath, result);
- }
- return result;
- }
-
- /*
- * Get the assembly that the current code is running from.
- */
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly GetExecutingAssembly()
- {
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return RuntimeAssembly.GetExecutingAssembly(ref stackMark);
- }
-
- [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
- public static Assembly GetCallingAssembly()
- {
- // LookForMyCallersCaller is not guarantee to return the correct stack frame
- // because of inlining, tail calls, etc. As a result GetCallingAssembly is not
- // ganranteed to return the correct result. We should document it as such.
- StackCrawlMark stackMark = StackCrawlMark.LookForMyCallersCaller;
- return RuntimeAssembly.GetExecutingAssembly(ref stackMark);
- }
-
- public static Assembly GetEntryAssembly()
- {
- AppDomainManager domainManager = AppDomain.CurrentDomain.DomainManager;
- if (domainManager == null)
- domainManager = new AppDomainManager();
- return domainManager.EntryAssembly;
- }
-
- #endregion // public static methods
-
- #region public methods
- public virtual event ModuleResolveEventHandler ModuleResolve
- {
- add
- {
- throw new NotImplementedException();
- }
- remove
- {
- throw new NotImplementedException();
- }
- }
-
- public virtual String CodeBase
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public virtual String EscapedCodeBase
- {
- get
- {
- return AssemblyName.EscapeCodeBase(CodeBase);
- }
- }
-
- public virtual AssemblyName GetName()
- {
- return GetName(false);
- }
-
- public virtual AssemblyName GetName(bool copiedName)
- {
- throw new NotImplementedException();
- }
-
- public virtual String FullName
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public virtual MethodInfo EntryPoint
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public virtual Type GetType(String name)
- {
- return GetType(name, false, false);
- }
-
- public virtual Type GetType(String name, bool throwOnError)
- {
- return GetType(name, throwOnError, false);
- }
-
- public virtual Type GetType(String name, bool throwOnError, bool ignoreCase)
- {
- throw new NotImplementedException();
- }
-
- public virtual IEnumerable<Type> ExportedTypes
- {
- get
- {
- return GetExportedTypes();
- }
- }
-
- public virtual Type[] GetExportedTypes()
- {
- throw new NotImplementedException();
- }
-
- public virtual IEnumerable<TypeInfo> DefinedTypes
- {
- get
- {
- Type[] types = GetTypes();
-
- TypeInfo[] typeinfos = new TypeInfo[types.Length];
-
- for (int i = 0; i < types.Length; i++)
- {
- TypeInfo typeinfo = types[i].GetTypeInfo();
- if (typeinfo == null)
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_NoTypeInfo", types[i].FullName));
-
- typeinfos[i] = typeinfo;
- }
-
- return typeinfos;
- }
- }
-
- public virtual Type[] GetTypes()
- {
- Module[] m = GetModules(false);
-
- int iFinalLength = 0;
- Type[][] ModuleTypes = new Type[m.Length][];
-
- for (int i = 0; i < ModuleTypes.Length; i++)
- {
- ModuleTypes[i] = m[i].GetTypes();
- iFinalLength += ModuleTypes[i].Length;
- }
-
- int iCurrent = 0;
- Type[] ret = new Type[iFinalLength];
- for (int i = 0; i < ModuleTypes.Length; i++)
- {
- int iLength = ModuleTypes[i].Length;
- Array.Copy(ModuleTypes[i], 0, ret, iCurrent, iLength);
- iCurrent += iLength;
- }
-
- return ret;
- }
-
- // Load a resource based on the NameSpace of the type.
- public virtual Stream GetManifestResourceStream(Type type, String name)
- {
- throw new NotImplementedException();
- }
-
- public virtual Stream GetManifestResourceStream(String name)
- {
- throw new NotImplementedException();
- }
-
- public virtual Assembly GetSatelliteAssembly(CultureInfo culture)
- {
- throw new NotImplementedException();
- }
-
- // Useful for binding to a very specific version of a satellite assembly
- public virtual Assembly GetSatelliteAssembly(CultureInfo culture, Version version)
- {
- throw new NotImplementedException();
- }
-
- public bool IsFullyTrusted
- {
- get
- {
- return true;
- }
- }
-
- public virtual SecurityRuleSet SecurityRuleSet
- {
- get
- {
- return SecurityRuleSet.None;
- }
- }
-
- // ISerializable implementation
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new NotImplementedException();
- }
-
- public virtual Module ManifestModule
- {
- get
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeAssembly rtAssembly = this as RuntimeAssembly;
- if (rtAssembly != null)
- return rtAssembly.ManifestModule;
-
- throw new NotImplementedException();
- }
- }
-
- public virtual IEnumerable<CustomAttributeData> CustomAttributes
- {
- get
- {
- return GetCustomAttributesData();
- }
- }
- public virtual Object[] GetCustomAttributes(bool inherit)
- {
- Contract.Ensures(Contract.Result<Object[]>() != null);
- throw new NotImplementedException();
- }
-
- public virtual Object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- Contract.Ensures(Contract.Result<Object[]>() != null);
- throw new NotImplementedException();
- }
-
- public virtual bool IsDefined(Type attributeType, bool inherit)
- {
- throw new NotImplementedException();
- }
-
- public virtual IList<CustomAttributeData> GetCustomAttributesData()
- {
- throw new NotImplementedException();
- }
-
- public virtual bool ReflectionOnly
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public Module LoadModule(String moduleName,
- byte[] rawModule)
- {
- return LoadModule(moduleName, rawModule, null);
- }
-
- public virtual Module LoadModule(String moduleName,
- byte[] rawModule,
- byte[] rawSymbolStore)
- {
- throw new NotImplementedException();
- }
-
- //
- // Locates a type from this assembly and creates an instance of it using
- // the system activator.
- //
- public Object CreateInstance(String typeName)
- {
- return CreateInstance(typeName,
- false, // ignore case
- BindingFlags.Public | BindingFlags.Instance,
- null, // binder
- null, // args
- null, // culture
- null); // activation attributes
- }
-
- public Object CreateInstance(String typeName,
- bool ignoreCase)
- {
- return CreateInstance(typeName,
- ignoreCase,
- BindingFlags.Public | BindingFlags.Instance,
- null, // binder
- null, // args
- null, // culture
- null); // activation attributes
- }
-
- public virtual Object CreateInstance(String typeName,
- bool ignoreCase,
- BindingFlags bindingAttr,
- Binder binder,
- Object[] args,
- CultureInfo culture,
- Object[] activationAttributes)
- {
- Type t = GetType(typeName, false, ignoreCase);
- if (t == null) return null;
- return Activator.CreateInstance(t,
- bindingAttr,
- binder,
- args,
- culture,
- activationAttributes);
- }
-
- public virtual IEnumerable<Module> Modules
- {
- get
- {
- return GetLoadedModules(true);
- }
- }
-
- public Module[] GetLoadedModules()
- {
- return GetLoadedModules(false);
- }
-
- public virtual Module[] GetLoadedModules(bool getResourceModules)
- {
- throw new NotImplementedException();
- }
-
- public Module[] GetModules()
- {
- return GetModules(false);
- }
-
- public virtual Module[] GetModules(bool getResourceModules)
- {
- throw new NotImplementedException();
- }
-
- public virtual Module GetModule(String name)
- {
- throw new NotImplementedException();
- }
-
- // Returns the file in the File table of the manifest that matches the
- // given name. (Name should not include path.)
- public virtual FileStream GetFile(String name)
- {
- throw new NotImplementedException();
- }
-
- public virtual FileStream[] GetFiles()
- {
- return GetFiles(false);
- }
-
- public virtual FileStream[] GetFiles(bool getResourceModules)
- {
- throw new NotImplementedException();
- }
-
- // Returns the names of all the resources
- public virtual String[] GetManifestResourceNames()
- {
- throw new NotImplementedException();
- }
-
- public virtual AssemblyName[] GetReferencedAssemblies()
- {
- throw new NotImplementedException();
- }
-
- public virtual ManifestResourceInfo GetManifestResourceInfo(String resourceName)
- {
- throw new NotImplementedException();
- }
-
- public override String ToString()
- {
- String displayName = FullName;
- if (displayName == null)
- return base.ToString();
- else
- return displayName;
- }
-
- public virtual String Location
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public virtual String ImageRuntimeVersion
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- /*
- Returns true if the assembly was loaded from the global assembly cache.
- */
- public virtual bool GlobalAssemblyCache
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public virtual Int64 HostContext
- {
- get
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeAssembly rtAssembly = this as RuntimeAssembly;
- if (rtAssembly != null)
- return rtAssembly.HostContext;
-
- throw new NotImplementedException();
- }
- }
-
- public virtual bool IsDynamic
- {
- get
- {
- return false;
- }
- }
- #endregion // public methods
-
- }
-}
if (position >= 0)
{
- ParameterInfo[] parameters = m_dynMethod.LoadParameters();
+ RuntimeParameterInfo[] parameters = m_dynMethod.LoadParameters();
parameters[position].SetName(parameterName);
parameters[position].SetAttributes(attributes);
}
internal class RTDynamicMethod : MethodInfo
{
internal DynamicMethod m_owner;
- private ParameterInfo[] m_parameters;
+ private RuntimeParameterInfo[] m_parameters;
private String m_name;
private MethodAttributes m_attributes;
private CallingConventions m_callingConvention;
// private implementation
//
- internal ParameterInfo[] LoadParameters()
+ internal RuntimeParameterInfo[] LoadParameters()
{
if (m_parameters == null)
{
Type[] parameterTypes = m_owner.m_parameterTypes;
- ParameterInfo[] parameters = new ParameterInfo[parameterTypes.Length];
+ RuntimeParameterInfo[] parameters = new RuntimeParameterInfo[parameterTypes.Length];
for (int i = 0; i < parameterTypes.Length; i++)
parameters[i] = new RuntimeParameterInfo(this, null, parameterTypes[i], i);
if (m_parameters == null)
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.Serialization;
+
+namespace System.Reflection
+{
+ public abstract partial class Module : ISerializable, ICustomAttributeProvider
+ {
+ // Used to provide implementation and overriding point for ModuleHandle.
+ // To get a module handle inside mscorlib, use GetNativeHandle instead.
+ internal virtual ModuleHandle GetModuleHandle()
+ {
+ return ModuleHandle.EmptyHandle;
+ }
+ }
+}
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Runtime.Serialization;
using System.Collections.Generic;
-using System.Diagnostics.Contracts;
+using System.Runtime.Serialization;
namespace System.Reflection
{
- [Serializable]
- public abstract class Module : ISerializable, ICustomAttributeProvider
+ public abstract partial class Module : ICustomAttributeProvider, ISerializable
{
- #region Static Constructor
- static Module()
- {
- __Filters _fltObj;
- _fltObj = new __Filters();
- FilterTypeName = new TypeFilter(_fltObj.FilterTypeName);
- FilterTypeNameIgnoreCase = new TypeFilter(_fltObj.FilterTypeNameIgnoreCase);
- }
- #endregion
-
- #region Constructor
- protected Module()
- {
- }
- #endregion
-
- #region Public Statics
- public static readonly TypeFilter FilterTypeName;
- public static readonly TypeFilter FilterTypeNameIgnoreCase;
-
- public static bool operator ==(Module left, Module right)
- {
- if (ReferenceEquals(left, right))
- return true;
+ protected Module() { }
- if ((object)left == null || (object)right == null ||
- left is RuntimeModule || right is RuntimeModule)
- {
- return false;
- }
+ public virtual Assembly Assembly { get { throw NotImplemented.ByDesign; } }
+ public virtual string FullyQualifiedName { get { throw NotImplemented.ByDesign; } }
+ public virtual string Name { get { throw NotImplemented.ByDesign; } }
- return left.Equals(right);
- }
+ public virtual int MDStreamVersion { get { throw NotImplemented.ByDesign; } }
+ public virtual Guid ModuleVersionId { get { throw NotImplemented.ByDesign; } }
+ public virtual string ScopeName { get { throw NotImplemented.ByDesign; } }
+ public ModuleHandle ModuleHandle => GetModuleHandle();
+ public virtual void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine) { throw NotImplemented.ByDesign; }
+ public virtual bool IsResource() { throw NotImplemented.ByDesign; }
- public static bool operator !=(Module left, Module right)
- {
- return !(left == right);
- }
-
- public override bool Equals(object o)
- {
- return base.Equals(o);
- }
+ public virtual bool IsDefined(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; }
+ public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData();
+ public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; }
+ public virtual object[] GetCustomAttributes(bool inherit) { throw NotImplemented.ByDesign; }
+ public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) { throw NotImplemented.ByDesign; }
- public override int GetHashCode()
+ public MethodInfo GetMethod(string name) => GetMethod(name, null);
+ public MethodInfo GetMethod(string name, Type[] types) => GetMethod(name, Module.DefaultLookup, null, CallingConventions.Any, types, null);
+ public MethodInfo GetMethod(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
{
- return base.GetHashCode();
- }
- #endregion
-
- #region Literals
- private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
- #endregion
-
- #region object overrides
- public override String ToString()
- {
- return ScopeName;
- }
- #endregion
-
- public virtual IEnumerable<CustomAttributeData> CustomAttributes
- {
- get
+ if (name == null)
+ throw new ArgumentNullException(nameof(name));
+ if (types == null)
+ throw new ArgumentNullException(nameof(types));
+ for (int i = 0; i < types.Length; i++)
{
- return GetCustomAttributesData();
+ if (types[i] == null)
+ throw new ArgumentNullException(nameof(types));
}
- }
- #region ICustomAttributeProvider Members
- public virtual Object[] GetCustomAttributes(bool inherit)
- {
- throw new NotImplementedException();
- }
-
- public virtual Object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- throw new NotImplementedException();
- }
-
- public virtual bool IsDefined(Type attributeType, bool inherit)
- {
- throw new NotImplementedException();
- }
-
- public virtual IList<CustomAttributeData> GetCustomAttributesData()
- {
- throw new NotImplementedException();
- }
- #endregion
-
- #region public instances members
- public MethodBase ResolveMethod(int metadataToken)
- {
- return ResolveMethod(metadataToken, null, null);
- }
-
- public virtual MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.ResolveMethod(metadataToken, genericTypeArguments, genericMethodArguments);
-
- throw new NotImplementedException();
- }
-
- public FieldInfo ResolveField(int metadataToken)
- {
- return ResolveField(metadataToken, null, null);
- }
-
- public virtual FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.ResolveField(metadataToken, genericTypeArguments, genericMethodArguments);
-
- throw new NotImplementedException();
- }
-
- public Type ResolveType(int metadataToken)
- {
- return ResolveType(metadataToken, null, null);
- }
-
- public virtual Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.ResolveType(metadataToken, genericTypeArguments, genericMethodArguments);
-
- throw new NotImplementedException();
+ return GetMethodImpl(name, bindingAttr, binder, callConvention, types, modifiers);
}
- public MemberInfo ResolveMember(int metadataToken)
- {
- return ResolveMember(metadataToken, null, null);
- }
+ protected virtual MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) { throw NotImplemented.ByDesign; }
- public virtual MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.ResolveMember(metadataToken, genericTypeArguments, genericMethodArguments);
-
- throw new NotImplementedException();
- }
+ public MethodInfo[] GetMethods() => GetMethods(Module.DefaultLookup);
+ public virtual MethodInfo[] GetMethods(BindingFlags bindingFlags) { throw NotImplemented.ByDesign; }
- public virtual byte[] ResolveSignature(int metadataToken)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.ResolveSignature(metadataToken);
-
- throw new NotImplementedException();
- }
+ public FieldInfo GetField(string name) => GetField(name, Module.DefaultLookup);
+ public virtual FieldInfo GetField(string name, BindingFlags bindingAttr) { throw NotImplemented.ByDesign; }
- public virtual string ResolveString(int metadataToken)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.ResolveString(metadataToken);
-
- throw new NotImplementedException();
- }
+ public FieldInfo[] GetFields() => GetFields(Module.DefaultLookup);
+ public virtual FieldInfo[] GetFields(BindingFlags bindingFlags) { throw NotImplemented.ByDesign; }
- public virtual void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- rtModule.GetPEKind(out peKind, out machine);
-
- throw new NotImplementedException();
- }
-
- public virtual int MDStreamVersion
- {
- get
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.MDStreamVersion;
-
- throw new NotImplementedException();
- }
- }
+ public virtual Type[] GetTypes() { throw NotImplemented.ByDesign; }
- public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- throw new NotImplementedException();
- }
+ public virtual Type GetType(string className) => GetType(className, throwOnError: false, ignoreCase: false);
+ public virtual Type GetType(string className, bool ignoreCase) => GetType(className, throwOnError: false, ignoreCase: ignoreCase);
+ public virtual Type GetType(string className, bool throwOnError, bool ignoreCase) { throw NotImplemented.ByDesign; }
- public virtual Type GetType(String className, bool ignoreCase)
- {
- return GetType(className, false, ignoreCase);
- }
-
- public virtual Type GetType(String className)
- {
- return GetType(className, false, false);
- }
-
- public virtual Type GetType(String className, bool throwOnError, bool ignoreCase)
- {
- throw new NotImplementedException();
- }
-
- public virtual String FullyQualifiedName
- {
- get
- {
- throw new NotImplementedException();
- }
- }
-
- public virtual Type[] FindTypes(TypeFilter filter, Object filterCriteria)
+ public virtual Type[] FindTypes(TypeFilter filter, object filterCriteria)
{
Type[] c = GetTypes();
int cnt = 0;
return ret;
}
- public virtual Type[] GetTypes()
- {
- throw new NotImplementedException();
- }
+ public virtual int MetadataToken { get { throw NotImplemented.ByDesign; } }
- public virtual Guid ModuleVersionId
- {
- get
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.ModuleVersionId;
-
- throw new NotImplementedException();
- }
- }
+ public FieldInfo ResolveField(int metadataToken) => ResolveField(metadataToken, null, null);
+ public virtual FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) { throw NotImplemented.ByDesign; }
- public virtual int MetadataToken
- {
- get
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.MetadataToken;
-
- throw new NotImplementedException();
- }
- }
+ public MemberInfo ResolveMember(int metadataToken) => ResolveMember(metadataToken, null, null);
+ public virtual MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) { throw NotImplemented.ByDesign; }
- public virtual bool IsResource()
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.IsResource();
-
- throw new NotImplementedException();
- }
+ public MethodBase ResolveMethod(int metadataToken) => ResolveMethod(metadataToken, null, null);
+ public virtual MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) { throw NotImplemented.ByDesign; }
- public FieldInfo[] GetFields()
- {
- return GetFields(Module.DefaultLookup);
- }
+ public virtual byte[] ResolveSignature(int metadataToken) { throw NotImplemented.ByDesign; }
+ public virtual string ResolveString(int metadataToken) { throw NotImplemented.ByDesign; }
- public virtual FieldInfo[] GetFields(BindingFlags bindingFlags)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.GetFields(bindingFlags);
-
- throw new NotImplementedException();
- }
+ public Type ResolveType(int metadataToken) => ResolveType(metadataToken, null, null);
+ public virtual Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) { throw NotImplemented.ByDesign; }
- public FieldInfo GetField(String name)
- {
- return GetField(name, Module.DefaultLookup);
- }
+ public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { throw NotImplemented.ByDesign; }
- public virtual FieldInfo GetField(String name, BindingFlags bindingAttr)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.GetField(name, bindingAttr);
-
- throw new NotImplementedException();
- }
+ public override bool Equals(object o) => base.Equals(o);
+ public override int GetHashCode() => base.GetHashCode();
- public MethodInfo[] GetMethods()
- {
- return GetMethods(Module.DefaultLookup);
- }
-
- public virtual MethodInfo[] GetMethods(BindingFlags bindingFlags)
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.GetMethods(bindingFlags);
-
- throw new NotImplementedException();
- }
-
- public MethodInfo GetMethod(
- String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
+ public static bool operator ==(Module left, Module right)
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
-
- if (types == null)
- throw new ArgumentNullException(nameof(types));
- Contract.EndContractBlock();
+ if (object.ReferenceEquals(left, right))
+ return true;
- for (int i = 0; i < types.Length; i++)
- {
- if (types[i] == null)
- throw new ArgumentNullException(nameof(types));
- }
+ if ((object)left == null || (object)right == null)
+ return false;
- return GetMethodImpl(name, bindingAttr, binder, callConvention, types, modifiers);
+ return left.Equals(right);
}
- public MethodInfo GetMethod(String name, Type[] types)
- {
- if (name == null)
- throw new ArgumentNullException(nameof(name));
+ public static bool operator !=(Module left, Module right) => !(left == right);
- if (types == null)
- throw new ArgumentNullException(nameof(types));
- Contract.EndContractBlock();
+ public override string ToString() => ScopeName;
- for (int i = 0; i < types.Length; i++)
- {
- if (types[i] == null)
- throw new ArgumentNullException(nameof(types));
- }
+ public static readonly TypeFilter FilterTypeName = FilterTypeNameImpl;
+ public static readonly TypeFilter FilterTypeNameIgnoreCase = FilterTypeNameIgnoreCaseImpl;
- return GetMethodImpl(name, Module.DefaultLookup, null, CallingConventions.Any, types, null);
- }
+ private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
- public MethodInfo GetMethod(String name)
+ // FilterTypeName
+ // This method will filter the class based upon the name. It supports
+ // a trailing wild card.
+ private static bool FilterTypeNameImpl(Type cls, object filterCriteria)
{
- if (name == null)
- throw new ArgumentNullException(nameof(name));
- Contract.EndContractBlock();
+ // Check that the criteria object is a String object
+ if (filterCriteria == null || !(filterCriteria is string))
+ throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritString);
- return GetMethodImpl(name, Module.DefaultLookup, null, CallingConventions.Any,
- null, null);
- }
+ string str = (string)filterCriteria;
- protected virtual MethodInfo GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder,
- CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
- {
- throw new NotImplementedException();
- }
-
- public virtual String ScopeName
- {
- get
+ // Check to see if this is a prefix or exact match requirement
+ if (str.Length > 0 && str[str.Length - 1] == '*')
{
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.ScopeName;
-
- throw new NotImplementedException();
+ str = str.Substring(0, str.Length - 1);
+ return cls.Name.StartsWith(str, StringComparison.Ordinal);
}
- }
- public virtual String Name
- {
- get
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.Name;
-
- throw new NotImplementedException();
- }
+ return cls.Name.Equals(str);
}
- public virtual Assembly Assembly
+ // FilterFieldNameIgnoreCase
+ // This method filter the Type based upon name, it ignores case.
+ private static bool FilterTypeNameIgnoreCaseImpl(Type cls, object filterCriteria)
{
- [Pure]
- get
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeModule rtModule = this as RuntimeModule;
- if (rtModule != null)
- return rtModule.Assembly;
-
- throw new NotImplementedException();
- }
- }
+ // Check that the criteria object is a String object
+ if (filterCriteria == null || !(filterCriteria is string))
+ throw new InvalidFilterCriteriaException(SR.InvalidFilterCriteriaException_CritString);
- // This API never fails, it will return an empty handle for non-runtime handles and
- // a valid handle for reflection only modules.
- public ModuleHandle ModuleHandle
- {
- get
+ string str = (string)filterCriteria;
+
+ // Check to see if this is a prefix or exact match requirement
+ if (str.Length > 0 && str[str.Length - 1] == '*')
{
- return GetModuleHandle();
+ str = str.Substring(0, str.Length - 1);
+ string name = cls.Name;
+ if (name.Length >= str.Length)
+ return (string.Compare(name, 0, str, 0, str.Length, StringComparison.OrdinalIgnoreCase) == 0);
+ else
+ return false;
}
+ return (string.Compare(str, cls.Name, StringComparison.OrdinalIgnoreCase) == 0);
}
-
- // Used to provide implementation and overriding point for ModuleHandle.
- // To get a module handle inside mscorlib, use GetNativeHandle instead.
- internal virtual ModuleHandle GetModuleHandle()
- {
- return ModuleHandle.EmptyHandle;
- }
- #endregion
}
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using System.Diagnostics.Contracts;
-using System.Runtime.Serialization;
-
-namespace System.Reflection
-{
- [Serializable]
- public class ParameterInfo : ICustomAttributeProvider, IObjectReference
- {
- #region Legacy Protected Members
- protected String NameImpl;
- protected Type ClassImpl;
- protected int PositionImpl;
- protected ParameterAttributes AttrsImpl;
- protected Object DefaultValueImpl; // cannot cache this as it may be non agile user defined enum
- protected MemberInfo MemberImpl;
- #endregion
-
- #region Legacy Private Members
- // These are here only for backwards compatibility -- they are not set
- // until this instance is serialized, so don't rely on their values from
- // arbitrary code.
-#pragma warning disable 169
- [OptionalField]
- private IntPtr _importer;
- [OptionalField]
- private int _token;
- [OptionalField]
- private bool bExtraConstChecked;
-#pragma warning restore 169
- #endregion
-
- #region Constructor
- protected ParameterInfo()
- {
- }
- #endregion
-
- #region Internal Members
- // this is an internal api for DynamicMethod. A better solution is to change the relationship
- // between ParameterInfo and ParameterBuilder so that a ParameterBuilder can be seen as a writer
- // api over a ParameterInfo. However that is a possible breaking change so it needs to go through some process first
- internal void SetName(String name)
- {
- NameImpl = name;
- }
-
- internal void SetAttributes(ParameterAttributes attributes)
- {
- AttrsImpl = attributes;
- }
- #endregion
-
- #region Public Methods
- public virtual Type ParameterType
- {
- get
- {
- return ClassImpl;
- }
- }
-
- public virtual String Name
- {
- get
- {
- return NameImpl;
- }
- }
-
- public virtual bool HasDefaultValue { get { throw new NotImplementedException(); } }
-
- public virtual Object DefaultValue { get { throw new NotImplementedException(); } }
- public virtual Object RawDefaultValue { get { throw new NotImplementedException(); } }
-
- public virtual int Position { get { return PositionImpl; } }
- public virtual ParameterAttributes Attributes { get { return AttrsImpl; } }
-
- public virtual MemberInfo Member
- {
- get
- {
- Contract.Ensures(Contract.Result<MemberInfo>() != null);
- return MemberImpl;
- }
- }
-
- public bool IsIn { get { return ((Attributes & ParameterAttributes.In) != 0); } }
- public bool IsOut { get { return ((Attributes & ParameterAttributes.Out) != 0); } }
- public bool IsLcid { get { return ((Attributes & ParameterAttributes.Lcid) != 0); } }
- public bool IsRetval { get { return ((Attributes & ParameterAttributes.Retval) != 0); } }
- public bool IsOptional { get { return ((Attributes & ParameterAttributes.Optional) != 0); } }
-
- public virtual int MetadataToken
- {
- get
- {
- // This API was made virtual in V4. Code compiled against V2 might use
- // "call" rather than "callvirt" to call it.
- // This makes sure those code still works.
- RuntimeParameterInfo rtParam = this as RuntimeParameterInfo;
- if (rtParam != null)
- return rtParam.MetadataToken;
-
- // return a null token
- return (int)MetadataTokenType.ParamDef;
- }
- }
-
- public virtual Type[] GetRequiredCustomModifiers()
- {
- return EmptyArray<Type>.Value;
- }
-
- public virtual Type[] GetOptionalCustomModifiers()
- {
- return EmptyArray<Type>.Value;
- }
- #endregion
-
- #region Object Overrides
- public override String ToString()
- {
- return ParameterType.FormatTypeName() + " " + Name;
- }
- #endregion
-
- public virtual IEnumerable<CustomAttributeData> CustomAttributes
- {
- get
- {
- return GetCustomAttributesData();
- }
- }
- #region ICustomAttributeProvider
- public virtual Object[] GetCustomAttributes(bool inherit)
- {
- return EmptyArray<Object>.Value;
- }
-
- public virtual Object[] GetCustomAttributes(Type attributeType, bool inherit)
- {
- if (attributeType == null)
- throw new ArgumentNullException(nameof(attributeType));
- Contract.EndContractBlock();
-
- return EmptyArray<Object>.Value;
- }
-
- public virtual bool IsDefined(Type attributeType, bool inherit)
- {
- if (attributeType == null)
- throw new ArgumentNullException(nameof(attributeType));
- Contract.EndContractBlock();
-
- return false;
- }
-
- public virtual IList<CustomAttributeData> GetCustomAttributesData()
- {
- throw new NotImplementedException();
- }
- #endregion
-
- #region _ParameterInfo implementation
-
- #endregion
-
- #region IObjectReference
- // In V4 RuntimeParameterInfo is introduced.
- // To support deserializing ParameterInfo instances serialized in earlier versions
- // we need to implement IObjectReference.
- public object GetRealObject(StreamingContext context)
- {
- Contract.Ensures(Contract.Result<Object>() != null);
-
- // Once all the serializable fields have come in we can set up the real
- // instance based on just two of them (MemberImpl and PositionImpl).
-
- if (MemberImpl == null)
- throw new SerializationException(Environment.GetResourceString(ResId.Serialization_InsufficientState));
-
- ParameterInfo[] args = null;
-
- switch (MemberImpl.MemberType)
- {
- case MemberTypes.Constructor:
- case MemberTypes.Method:
- if (PositionImpl == -1)
- {
- if (MemberImpl.MemberType == MemberTypes.Method)
- return ((MethodInfo)MemberImpl).ReturnParameter;
- else
- throw new SerializationException(Environment.GetResourceString(ResId.Serialization_BadParameterInfo));
- }
- else
- {
- args = ((MethodBase)MemberImpl).GetParametersNoCopy();
-
- if (args != null && PositionImpl < args.Length)
- return args[PositionImpl];
- else
- throw new SerializationException(Environment.GetResourceString(ResId.Serialization_BadParameterInfo));
- }
-
- case MemberTypes.Property:
- args = ((RuntimePropertyInfo)MemberImpl).GetIndexParametersNoCopy();
-
- if (args != null && PositionImpl > -1 && PositionImpl < args.Length)
- return args[PositionImpl];
- else
- throw new SerializationException(Environment.GetResourceString(ResId.Serialization_BadParameterInfo));
-
- default:
- throw new SerializationException(Environment.GetResourceString(ResId.Serialization_NoParameterInfo));
- }
- }
- #endregion
- }
-}
}
#endregion
+ #region Internal Methods
+ internal void SetName(string name)
+ {
+ NameImpl = name;
+ }
+
+ internal void SetAttributes(ParameterAttributes attributes)
+ {
+ AttrsImpl = attributes;
+ }
+ #endregion
+
#region VTS magic to serialize/deserialized to/from pre-Whidbey endpoints.
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-//
-//
-// This class defines the delegate methods for the COM+ implemented filters.
-// This is the reflection version of these. There is also a _Filters class in
-// runtime which is related to this.
-//
-//
-//
-//
-
-using System;
-using System.Globalization;
-
-namespace System.Reflection
-{
- [Serializable]
- internal class __Filters
- {
- // FilterTypeName
- // This method will filter the class based upon the name. It supports
- // a trailing wild card.
- public virtual bool FilterTypeName(Type cls, Object filterCriteria)
- {
- // Check that the criteria object is a String object
- if (filterCriteria == null || !(filterCriteria is String))
- throw new InvalidFilterCriteriaException(System.Environment.GetResourceString("RFLCT.FltCritString"));
-
- String str = (String)filterCriteria;
- //str = str.Trim();
-
- // Check to see if this is a prefix or exact match requirement
- if (str.Length > 0 && str[str.Length - 1] == '*')
- {
- str = str.Substring(0, str.Length - 1);
- return cls.Name.StartsWith(str, StringComparison.Ordinal);
- }
-
- return cls.Name.Equals(str);
- }
-
- // FilterFieldNameIgnoreCase
- // This method filter the Type based upon name, it ignores case.
- public virtual bool FilterTypeNameIgnoreCase(Type cls, Object filterCriteria)
- {
- // Check that the criteria object is a String object
- if (filterCriteria == null || !(filterCriteria is String))
- throw new InvalidFilterCriteriaException(System.Environment.GetResourceString("RFLCT.FltCritString"));
-
- String str = (String)filterCriteria;
- //str = str.Trim();
-
- // Check to see if this is a prefix or exact match requirement
- if (str.Length > 0 && str[str.Length - 1] == '*')
- {
- str = str.Substring(0, str.Length - 1);
- String name = cls.Name;
- if (name.Length >= str.Length)
- return (String.Compare(name, 0, str, 0, str.Length, StringComparison.OrdinalIgnoreCase) == 0);
- else
- return false;
- }
- return (String.Compare(str, cls.Name, StringComparison.OrdinalIgnoreCase) == 0);
- }
- }
-}