[ClassInterface(ClassInterfaceType.None)]
[StructLayout (LayoutKind.Sequential)]
#if MOBILE
- public partial class Assembly : ICustomAttributeProvider, _Assembly {
-#elif MOONLIGHT
- public abstract class Assembly : ICustomAttributeProvider, _Assembly {
-#elif NET_4_0
- public abstract class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable {
+ public partial class Assembly : ICustomAttributeProvider {
#else
- public partial class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable {
+ public abstract class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable {
#endif
internal class ResolveEventHolder {
public event ModuleResolveEventHandler ModuleResolve;
}
+ internal class UnmanagedMemoryStreamForModule : UnmanagedMemoryStream
+ {
+ Module module;
+
+ public unsafe UnmanagedMemoryStreamForModule (byte* pointer, long length, Module module)
+ : base (pointer, length)
+ {
+ this.module = module;
+ }
+
+ protected override void Dispose (bool disposing)
+ {
+ if (!closed) {
+ /*
+ * The returned pointer points inside metadata, so
+ * we have to increase the refcount of the module, and decrease
+ * it when the stream is finalized.
+ */
+ module = null;
+ }
+
+ base.Dispose (disposing);
+ }
+ }
+
// Note: changes to fields must be reflected in _MonoReflectionAssembly struct (object-internals.h)
#pragma warning disable 649
private IntPtr _mono_assembly;
#pragma warning restore 649
private ResolveEventHolder resolve_event_holder;
+#if !MOBILE
private Evidence _evidence;
internal PermissionSet _minimum; // for SecurityAction.RequestMinimum
internal PermissionSet _optional; // for SecurityAction.RequestOptional
internal PermissionSet _refuse; // for SecurityAction.RequestRefuse
private PermissionSet _granted; // for the resolved assembly granted permissions
private PermissionSet _denied; // for the resolved assembly denied permissions
+#else
+ object _evidence, _minimum, _optional, _refuse, _granted, _denied;
+#endif
private bool fromByteArray;
private string assemblyName;
-#if NET_4_0 || MOONLIGHT || MOBILE
protected
-#else
- internal
-#endif
Assembly ()
{
resolve_event_holder = new ResolveEventHolder ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
get;
}
-#if !MOONLIGHT
+
public virtual Evidence Evidence {
[SecurityPermission (SecurityAction.Demand, ControlEvidence = true)]
get { return UnprotectedGetEvidence (); }
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal extern bool get_global_assembly_cache ();
-#endif
internal bool FromByteArray {
set { fromByteArray = value; }
}
}
}
- [SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
{
- if (info == null)
- throw new ArgumentNullException ("info");
-
- UnitySerializationHolder.GetAssemblyData (this, info, context);
+ throw new NotImplementedException ();
}
public virtual bool IsDefined (Type attributeType, bool inherit)
{
string[] names = (string[]) GetFilesInternal (null, getResourceModules);
if (names == null)
- return new FileStream [0];
+ return EmptyArray<FileStream>.Value;
string location = Location;
string location = Path.GetDirectoryName (Location);
string filename = Path.Combine (location, info.FileName);
-#if MOONLIGHT
- // we don't control the content of 'info.FileName' so we want to make sure we keep to ourselves
- filename = Path.GetFullPath (filename);
- if (!filename.StartsWith (location))
- throw new SecurityException ("non-rooted access to manifest resource");
-#endif
return new FileStream (filename, FileMode.Open, FileAccess.Read);
}
else {
UnmanagedMemoryStream stream;
unsafe {
- stream = new UnmanagedMemoryStream ((byte*) data, size);
+ stream = new UnmanagedMemoryStreamForModule ((byte*) data, size, module);
}
- /*
- * The returned pointer points inside metadata, so
- * we have to increase the refcount of the module, and decrease
- * it when the stream is finalized.
- */
- stream.Closed += new EventHandler (new ResourceCloseHandler (module).OnClose);
return stream;
}
}
[MonoTODO ("copiedName == true is not supported")]
public virtual AssemblyName GetName (Boolean copiedName)
{
+#if !MOBILE
// CodeBase, which is restricted, will be copied into the AssemblyName object so...
if (SecurityManager.SecurityEnabled) {
GetCodeBase (true); // this will ensure the Demand is made
}
+#endif
return UnprotectedGetName ();
}
// Try the assembly directory
string location = Path.GetDirectoryName (Location);
string fullName = Path.Combine (location, Path.Combine (culture.Name, aname.Name + ".dll"));
-#if MOONLIGHT
- // it's unlikely that culture.Name or aname.Name could contain stuff like ".." but...
- fullName = Path.GetFullPath (fullName);
- if (!fullName.StartsWith (location)) {
- if (throwOnError)
- throw new SecurityException ("non-rooted access to satellite assembly");
- return null;
- }
-#endif
if (!throwOnError && !File.Exists (fullName))
return null;
return LoadFrom (fullName);
}
+#if !MOBILE
Type _Assembly.GetType ()
{
// Required or object::GetType becomes virtual final
return base.GetType ();
}
-
+#endif
+
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern static Assembly LoadFrom (String assemblyFile, bool refonly);
return LoadFrom (assemblyFile, false);
}
-#if NET_4_0
[Obsolete]
-#endif
public static Assembly LoadFrom (String assemblyFile, Evidence securityEvidence)
{
Assembly a = LoadFrom (assemblyFile, false);
return a;
}
-#if NET_4_0
[Obsolete]
-#endif
[MonoTODO("This overload is not currently implemented")]
// FIXME: What are we missing?
public static Assembly LoadFrom (String assemblyFile, Evidence securityEvidence, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
throw new NotImplementedException ();
}
-#if NET_4_0
[MonoTODO]
public static Assembly LoadFrom (String assemblyFile, byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm)
{
throw new NotImplementedException ();
}
-#endif
-#if NET_4_0
public static Assembly UnsafeLoadFrom (String assemblyFile)
{
return LoadFrom (assemblyFile);
}
-#endif
-#if NET_4_0
[Obsolete]
-#endif
public static Assembly LoadFile (String path, Evidence securityEvidence)
{
if (path == null)
return AppDomain.CurrentDomain.Load (assemblyString);
}
-#if NET_4_0
[Obsolete]
-#endif
public static Assembly Load (String assemblyString, Evidence assemblySecurity)
{
return AppDomain.CurrentDomain.Load (assemblyString, assemblySecurity);
return AppDomain.CurrentDomain.Load (assemblyRef);
}
-#if NET_4_0
[Obsolete]
-#endif
public static Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
{
return AppDomain.CurrentDomain.Load (assemblyRef, assemblySecurity);
return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore);
}
-#if NET_4_0
[Obsolete]
-#endif
public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore,
Evidence securityEvidence)
{
return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore, securityEvidence);
}
-#if NET_4_0
[MonoLimitation ("Argument securityContextSource is ignored")]
public static Assembly Load (byte [] rawAssembly, byte [] rawSymbolStore, SecurityContextSource securityContextSource)
{
return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore);
}
-#endif
public static Assembly ReflectionOnlyLoad (byte[] rawAssembly)
{
[MonoTODO ("Not implemented")]
public
-#if NET_4_0 || MOONLIGHT || MOBILE
virtual
-#endif
Module LoadModule (string moduleName, byte [] rawModule, byte [] rawSymbolStore)
{
throw new NotImplementedException ();
}
public
-#if NET_4_0 || MOONLIGHT || MOBILE
virtual
-#endif
Object CreateInstance (String typeName, Boolean ignoreCase,
BindingFlags bindingAttr, Binder binder,
Object[] args, CultureInfo culture,
[MethodImplAttribute (MethodImplOptions.InternalCall)]
internal virtual extern Module[] GetModulesInternal ();
-
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal extern string[] GetNamespaces ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern virtual String[] GetManifestResourceNames ();
return null;
}
- private class ResourceCloseHandler {
-#pragma warning disable 169, 414
- Module module;
-#pragma warning restore 169, 414
-
- public ResourceCloseHandler (Module module) {
- this.module = module;
- }
-
- public void OnClose (object sender, EventArgs e) {
- // The module dtor will take care of things
- module = null;
- }
- }
-
- //
- // The following functions are only for the Mono Debugger.
- //
-
- [MethodImplAttribute (MethodImplOptions.InternalCall)]
- internal static extern int MonoDebugger_GetMethodToken (MethodBase method);
-
[MonoTODO ("Currently it always returns zero")]
[ComVisible (false)]
public
-#if NET_4_0 || MOONLIGHT || MOBILE
virtual
-#endif
long HostContext {
get { return 0; }
}
}
}
-#if NET_4_0
public virtual PermissionSet PermissionSet {
get { return this.GrantedPermissionSet; }
}
public virtual SecurityRuleSet SecurityRuleSet {
get { throw CreateNIE (); }
}
-#endif
#endif
-#if NET_4_0 || MOONLIGHT || MOBILE
static Exception CreateNIE ()
{
return new NotImplementedException ("Derived classes must implement it");
return true;
return !left.Equals (right);
}
-#endif
+
+ public virtual IEnumerable<TypeInfo> DefinedTypes {
+ get {
+ foreach (var type in GetTypes ()) {
+ yield return type.GetTypeInfo ();
+ }
+ }
+ }
+
+ public virtual IEnumerable<Type> ExportedTypes {
+ get { return GetExportedTypes (); }
+ }
+
+ public virtual IEnumerable<Module> Modules {
+ get { return GetModules (); }
+ }
+
+ public virtual IEnumerable<CustomAttributeData> CustomAttributes {
+ get { return GetCustomAttributesData (); }
+ }
}
}