Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
thisdir = class/System.ComponentModel.Composition
SUBDIRS =
include ../../build/rules.make
LIBRARY = System.ComponentModel.Composition.dll
LIB_MCS_FLAGS = -r:System.dll -r:System.Core.dll -d:CLR40 -resource:$(STRING_MESSAGES) -d:USE_ECMA_KEY,FEATURE_REFLECTIONCONTEXT,FEATURE_REFLECTIONFILEIO,FEATURE_SERIALIZATION,FEATURE_SLIMLOCK -nowarn:219,414
STRING_MESSAGES = Microsoft.Internal.Strings.resources
CLEAN_FILES += $(STRING_MESSAGES)
EXTRA_DISTFILES = \
src/ComponentModel/Strings.resx
VALID_PROFILE := $(filter net_4_0 net_4_5 monotouch monodroid xammac mobile_static, $(PROFILE))
ifndef VALID_PROFILE
LIBRARY_NAME = dummy-System.ComponentModel.Composition.dll
NO_INSTALL = yes
NO_SIGN_ASSEMBLY = yes
NO_TEST = yes
endif
include ../../build/library.make
$(the_lib): $(STRING_MESSAGES)
$(STRING_MESSAGES): src/ComponentModel/Strings.resx
$(RESGEN) $< $@

View File

@@ -0,0 +1,178 @@
src/Assembly/AssemblyInfo.cs
../../build/common/Consts.cs
src/ComponentModel/ContractAdditions.cs
src/ComponentModel/PlatformWorkarounds.cs
src/ComponentModel/Strings.Designer.cs
src/ComponentModel/SuppressMessages.cs
src/ComponentModel/SuppressMessagesBaselined.cs
src/ComponentModel/Microsoft/Internal/ContractServices.cs
src/ComponentModel/Microsoft/Internal/AttributeServices.cs
src/ComponentModel/Microsoft/Internal/Lock.Reader.cs
src/ComponentModel/Microsoft/Internal/LazyServices.cs
src/ComponentModel/Microsoft/Internal/ReflectionInvoke.cs
src/ComponentModel/Microsoft/Internal/Lock.cs
src/ComponentModel/Microsoft/Internal/Assumes.cs
src/ComponentModel/Microsoft/Internal/Assumes.InternalErrorException.cs
src/ComponentModel/Microsoft/Internal/StringComparers.cs
src/ComponentModel/Microsoft/Internal/Lock.Writer.cs
src/ComponentModel/Microsoft/Internal/Requires.cs
src/ComponentModel/Microsoft/Internal/ReflectionServices.cs
src/ComponentModel/Microsoft/Internal/GenerationServices.cs
src/ComponentModel/Microsoft/Internal/Runtime/Serialization/SerializationServices.cs
src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.cs
src/ComponentModel/Microsoft/Internal/Collections/WeakReferenceCollection.cs
src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionaryDebuggerProxy.cs
src/ComponentModel/Microsoft/Internal/Collections/CollectionServices.CollectionOfObject.cs
src/ComponentModel/Microsoft/Internal/Collections/EnumerableCardinality.cs
src/ComponentModel/Microsoft/Internal/Collections/ReadOnlyDictionary.cs
src/ComponentModel/System/LazyOfTTMetadata.cs
src/ComponentModel/System/ComponentModel/Composition/PartMetadataAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/ExceptionBuilder.cs
src/ComponentModel/System/ComponentModel/Composition/ImportCardinalityMismatchException.cs
src/ComponentModel/System/ComponentModel/Composition/ExportCardinalityCheckResult.cs
src/ComponentModel/System/ComponentModel/Composition/MetadataServices.cs
src/ComponentModel/System/ComponentModel/Composition/MetadataAttributeAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/CompositionContractMismatchException.cs
src/ComponentModel/System/ComponentModel/Composition/ChangeRejectedException.cs
src/ComponentModel/System/ComponentModel/Composition/ExportFactoryOfT.cs
src/ComponentModel/System/ComponentModel/Composition/CompositionError.cs
src/ComponentModel/System/ComponentModel/Composition/CreationPolicy.cs
src/ComponentModel/System/ComponentModel/Composition/AttributedModelServices.cs
src/ComponentModel/System/ComponentModel/Composition/CompositionExceptionDebuggerProxy.cs
src/ComponentModel/System/ComponentModel/Composition/ICompositionService.cs
src/ComponentModel/System/ComponentModel/Composition/ExportServices.DisposableLazy.cs
src/ComponentModel/System/ComponentModel/Composition/MetadataViewGenerator.cs
src/ComponentModel/System/ComponentModel/Composition/ConstraintServices.cs
src/ComponentModel/System/ComponentModel/Composition/ExportLifetimeContextOfT.cs
src/ComponentModel/System/ComponentModel/Composition/ImportingConstructorAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/ImportManyAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/ImportSource.cs
src/ComponentModel/System/ComponentModel/Composition/MetadataViewProvider.cs
src/ComponentModel/System/ComponentModel/Composition/ExportAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/IPartImportsSatisfiedNotification.cs
src/ComponentModel/System/ComponentModel/Composition/CompositionException.cs
src/ComponentModel/System/ComponentModel/Composition/ContractNameServices.cs
src/ComponentModel/System/ComponentModel/Composition/ImportCardinalityMismatchExceptionDebuggerProxy.cs
src/ComponentModel/System/ComponentModel/Composition/CompositionErrorDebuggerProxy.cs
src/ComponentModel/System/ComponentModel/Composition/ImportAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/ExportFactoryOfTTMetadata.cs
src/ComponentModel/System/ComponentModel/Composition/PartCreationPolicyAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/PartNotDiscoverableAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/ExportServices.cs
src/ComponentModel/System/ComponentModel/Composition/MetadataViewImplementationAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/ExportMetadataAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/InheritedExportAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/ErrorBuilder.cs
src/ComponentModel/System/ComponentModel/Composition/CompositionResultOfT.cs
src/ComponentModel/System/ComponentModel/Composition/IAttributedImport.cs
src/ComponentModel/System/ComponentModel/Composition/CompositionErrorId.cs
src/ComponentModel/System/ComponentModel/Composition/CompositionResult.cs
src/ComponentModel/System/ComponentModel/Composition/CatalogReflectionContextAttribute.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ApplicationCatalog.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/AtomicCompositionExtensions.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/TypeCatalog.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/INotifyComposablePartCatalogChanged.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionBatch.SingleExportComposablePart.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ImportEngine.PartManager.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/AssemblyCatalogDebuggerProxy.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionBatch.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionLock.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/AtomicComposition.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionScopeDefinitionDebuggerProxy.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionContainer.CompositionServiceShim.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CatalogExportProvider.FactoryExport.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ImportEngine.RecompositionManager.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/AssemblyCatalog.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionConstants.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionOptions.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ComposablePartCatalogChangeEventArgs.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ComposablePartExportProvider.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionScopeDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionServices.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CatalogExtensions.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionContainer.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CatalogExportProvider.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CompositionService.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/FilteredCatalog.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CatalogExportProvider.CatalogExport.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CatalogExportProvider.ScopeFactoryExport.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/FilteredCatalog.Traversal.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/FilteredCatalog.DependentsTraversal.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ScopingExtensions.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ImportSourceImportDefinitionHelpers.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/DirectoryCatalog.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CatalogExportProvider.ScopeManager.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportsChangeEventArgs.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/FilteredCatalog.IComposablePartCatalogTraversal.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ImportEngine.EngineContext.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ExportProvider.GetExportOverrides.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/FilteredCatalog.DependenciesTraversal.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ComposablePartCatalogCollection.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/ImportEngine.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CatalogExportProvider.CatalogChangeProxy.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/DirectoryCatalog.DirectoryCatalogDebuggerProxy.cs
src/ComponentModel/System/ComponentModel/Composition/Hosting/CatalogExportProvider.PartCreatorExport.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/SerializableCompositionElement.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ImportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ComposablePartCatalogDebuggerProxy.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ComposablePartDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ComposablePartExceptionDebuggerProxy.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/IPartCreatorImportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ContractBasedImportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ExportedDelegate.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ICompositionElement.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/Export.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/CompositionElement.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ComposablePart.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/CompositionElementExtensions.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ExportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ImportCardinality.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ComposablePartException.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/PrimitivesServices.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/CompositionElementDebuggerProxy.cs
src/ComponentModel/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs
src/ComponentModel/System/ComponentModel/Composition/AttributedModel/AttributedExportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/AttributedModel/AttributedModelDiscovery.cs
src/ComponentModel/System/ComponentModel/Composition/AttributedModel/AttributedPartCreationInfo.cs
src/ComponentModel/System/ComponentModel/Composition/Diagnostics/CompositionTraceId.cs
src/ComponentModel/System/ComponentModel/Composition/Diagnostics/CompositionTraceSource.cs
src/ComponentModel/System/ComponentModel/Composition/Diagnostics/CompositionTrace.cs
src/ComponentModel/System/ComponentModel/Composition/Diagnostics/TraceSourceTraceWriter.cs
src/ComponentModel/System/ComponentModel/Composition/Diagnostics/TraceWriter.cs
src/ComponentModel/System/ComponentModel/Composition/Diagnostics/SilverlightTraceWriter.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionExtensions.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionProperty.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ImportingParameter.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionImportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/LazyMemberInfo.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionParameterImportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/PartCreatorMemberImportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionItem.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/GenericSpecializationPartCreationInfo.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionComposablePartDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/PartCreatorExportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ExportingMember.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionMemberExportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ImportingItem.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionModelServices.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/GenericServices.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ImportingMember.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/IReflectionPartCreationInfo.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/DisposableReflectionComposablePart.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionParameter.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionComposablePart.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionItemType.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionType.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionField.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/PartCreatorParameterImportDefinition.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionMethod.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ImportType.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionMember.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.LifetimeContext.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionWritableMember.cs
src/ComponentModel/System/ComponentModel/Composition/ReflectionModel/ReflectionMemberImportDefinition.cs

View File

@@ -0,0 +1,62 @@
//
// AssemblyInfo.cs
//
// Authors:
// Marek Safar (marek.safar@gmail.com)
//
// Copyright 2011 Xamarin Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Reflection;
using System.Resources;
using System.Security;
using System.Security.Permissions;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about the assembly
[assembly: AssemblyTitle ("System.ComponentModel.Composition.dll")]
[assembly: AssemblyDescription ("System.ComponentModel.Composition.dll")]
[assembly: AssemblyDefaultAlias ("System.ComponentModel.Composition.dll")]
[assembly: AssemblyCompany (Consts.MonoCompany)]
[assembly: AssemblyProduct (Consts.MonoProduct)]
[assembly: AssemblyCopyright("(c) Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyVersion (Consts.FxVersion)]
[assembly: SatelliteContractVersion (Consts.FxVersion)]
[assembly: AssemblyInformationalVersion (Consts.FxFileVersion)]
[assembly: AssemblyFileVersion (Consts.FxFileVersion)]
[assembly: NeutralResourcesLanguage ("en-US")]
[assembly: CLSCompliant (true)]
[assembly: AssemblyDelaySign (true)]
[assembly: AssemblyKeyFile ("../ecma.pub")]
[assembly: SecurityCritical]
[assembly: AllowPartiallyTrustedCallers]
[assembly: ComVisible (false)]

View File

@@ -0,0 +1,113 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Primitives;
using System.Linq;
namespace System.Diagnostics.Contracts
{
#if CONTRACTS_FULL
[ContractClassFor(typeof(ComposablePart))]
internal abstract class ComposablePartContract : ComposablePart
{
public override IEnumerable<ExportDefinition> ExportDefinitions
{
get
{
Contract.Ensures(Contract.Result<IEnumerable<ExportDefinition>>() != null);
throw new NotImplementedException();
}
}
public override IEnumerable<ImportDefinition> ImportDefinitions
{
get
{
Contract.Ensures(Contract.Result<IEnumerable<ImportDefinition>>() != null);
throw new NotImplementedException();
}
}
public override object GetExportedValue(ExportDefinition definition)
{
Contract.Requires(definition != null);
throw new NotImplementedException();
}
public override void SetImport(ImportDefinition definition, IEnumerable<Export> exports)
{
Contract.Requires(definition != null);
Contract.Requires(exports != null);
throw new NotImplementedException();
}
}
[ContractClassFor(typeof(ComposablePartDefinition))]
internal abstract class ComposablePartDefinitionContract : ComposablePartDefinition
{
public override IEnumerable<ExportDefinition> ExportDefinitions
{
get
{
Contract.Ensures(Contract.Result<IEnumerable<ExportDefinition>>() != null);
Contract.Ensures(Contract.ForAll(Contract.Result<IEnumerable<ExportDefinition>>(), e => e != null));
throw new NotImplementedException();
}
}
public override IEnumerable<ImportDefinition> ImportDefinitions
{
get
{
Contract.Ensures(Contract.Result<IEnumerable<ImportDefinition>>() != null);
Contract.Ensures(Contract.ForAll(Contract.Result<IEnumerable<ImportDefinition>>(), i => i != null));
throw new NotImplementedException();
}
}
public override ComposablePart CreatePart()
{
Contract.Ensures(Contract.Result<ComposablePart>() != null);
throw new NotImplementedException();
}
}
[ContractClassFor(typeof(ICompositionElement))]
internal abstract class ICompositionElementContract : ICompositionElement
{
public string DisplayName
{
get
{
Contract.Ensures(!string.IsNullOrEmpty(Contract.Result<string>()));
throw new NotImplementedException();
}
}
public ICompositionElement Origin
{
get { throw new NotImplementedException(); }
}
}
[ContractClassFor(typeof(ICompositionService))]
internal abstract class ICompositionServiceContract : ICompositionService
{
public void SatisfyImportsOnce(ComposablePart part)
{
Contract.Requires(part != null);
throw new NotImplementedException();
}
}
#endif
}

View File

@@ -0,0 +1,32 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.Serialization;
namespace Microsoft.Internal
{
partial class Assumes
{
// The exception that is thrown when an internal assumption failed.
[Serializable]
[SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic")]
private class InternalErrorException : Exception
{
public InternalErrorException(string message)
: base(string.Format(CultureInfo.CurrentCulture, Strings.InternalExceptionMessage, message))
{
}
#if FEATURE_SERIALIZATION
[System.Security.SecuritySafeCritical]
protected InternalErrorException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endif
}
}
}

View File

@@ -0,0 +1,79 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.Serialization;
namespace Microsoft.Internal
{
internal static partial class Assumes
{
[DebuggerStepThrough]
internal static void NotNull<T>(T value)
where T : class
{
IsTrue(value != null);
}
[DebuggerStepThrough]
internal static void NotNull<T1, T2>(T1 value1, T2 value2)
where T1 : class
where T2 : class
{
NotNull(value1);
NotNull(value2);
}
[DebuggerStepThrough]
internal static void NotNull<T1, T2, T3>(T1 value1, T2 value2, T3 value3)
where T1 : class
where T2 : class
where T3 : class
{
NotNull(value1);
NotNull(value2);
NotNull(value3);
}
[DebuggerStepThrough]
internal static void NotNullOrEmpty(string value)
{
NotNull(value);
IsTrue(value.Length > 0);
}
[DebuggerStepThrough]
internal static void IsTrue(bool condition)
{
if (!condition)
{
throw UncatchableException(null);
}
}
[DebuggerStepThrough]
internal static void IsTrue(bool condition, [Localizable(false)]string message)
{
if (!condition)
{
throw UncatchableException(message);
}
}
[DebuggerStepThrough]
internal static T NotReachable<T>()
{
throw UncatchableException("Code path should never be reached!");
}
[DebuggerStepThrough]
private static Exception UncatchableException([Localizable(false)]string message)
{
return new InternalErrorException(message);
}
}
}

View File

@@ -0,0 +1,43 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Microsoft.Internal
{
internal static class AttributeServices
{
public static T[] GetAttributes<T>(this ICustomAttributeProvider attributeProvider) where T : class
{
return (T[])attributeProvider.GetCustomAttributes(typeof(T), false);
}
public static T[] GetAttributes<T>(this ICustomAttributeProvider attributeProvider, bool inherit) where T : class
{
return (T[])attributeProvider.GetCustomAttributes(typeof(T), inherit);
}
public static T GetFirstAttribute<T>(this ICustomAttributeProvider attributeProvider) where T : class
{
return GetAttributes<T>(attributeProvider).FirstOrDefault();
}
public static T GetFirstAttribute<T>(this ICustomAttributeProvider attributeProvider, bool inherit) where T : class
{
return GetAttributes<T>(attributeProvider, inherit).FirstOrDefault();
}
public static bool IsAttributeDefined<T>(this ICustomAttributeProvider attributeProvider) where T : class
{
return attributeProvider.IsDefined(typeof(T), false);
}
public static bool IsAttributeDefined<T>(this ICustomAttributeProvider attributeProvider, bool inherit) where T : class
{
return attributeProvider.IsDefined(typeof(T), inherit);
}
}
}

View File

@@ -0,0 +1,147 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
namespace Microsoft.Internal.Collections
{
internal static partial class CollectionServices
{
public static ICollection<object> GetCollectionWrapper(Type itemType, object collectionObject)
{
Assumes.NotNull(itemType, collectionObject);
var underlyingItemType = itemType.UnderlyingSystemType;
if (underlyingItemType == typeof(object))
{
return (ICollection<object>)collectionObject;
}
// Most common .Net collections implement IList as well so for those
// cases we can optimize the wrapping instead of using reflection to create
// a generic type.
if (typeof(IList).IsAssignableFrom(collectionObject.GetType()))
{
return new CollectionOfObjectList((IList)collectionObject);
}
Type collectionType = typeof(CollectionOfObject<>).MakeGenericType(underlyingItemType);
return (ICollection<object>)Activator.CreateInstance(collectionType, collectionObject);
}
private class CollectionOfObjectList : ICollection<object>
{
private readonly IList _list;
public CollectionOfObjectList(IList list)
{
this._list = list;
}
public void Add(object item)
{
this._list.Add(item);
}
public void Clear()
{
this._list.Clear();
}
public bool Contains(object item)
{
return Assumes.NotReachable<bool>();
}
public void CopyTo(object[] array, int arrayIndex)
{
Assumes.NotReachable<object>();
}
public int Count
{
get { return Assumes.NotReachable<int>(); }
}
public bool IsReadOnly
{
get { return this._list.IsReadOnly; }
}
public bool Remove(object item)
{
return Assumes.NotReachable<bool>();
}
public IEnumerator<object> GetEnumerator()
{
return Assumes.NotReachable<IEnumerator<object>>();
}
IEnumerator IEnumerable.GetEnumerator()
{
return Assumes.NotReachable<IEnumerator>();
}
}
private class CollectionOfObject<T> : ICollection<object>
{
private readonly ICollection<T> _collectionOfT;
public CollectionOfObject(object collectionOfT)
{
this._collectionOfT = (ICollection<T>)collectionOfT;
}
public void Add(object item)
{
this._collectionOfT.Add((T) item);
}
public void Clear()
{
this._collectionOfT.Clear();
}
public bool Contains(object item)
{
return Assumes.NotReachable<bool>();
}
public void CopyTo(object[] array, int arrayIndex)
{
Assumes.NotReachable<object>();
}
public int Count
{
get { return Assumes.NotReachable<int>(); }
}
public bool IsReadOnly
{
get { return this._collectionOfT.IsReadOnly; }
}
public bool Remove(object item)
{
return Assumes.NotReachable<bool>();
}
public IEnumerator<object> GetEnumerator()
{
return Assumes.NotReachable<IEnumerator<object>>();
}
IEnumerator IEnumerable.GetEnumerator()
{
return Assumes.NotReachable<IEnumerator>();
}
}
}
}

View File

@@ -0,0 +1,270 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
namespace Microsoft.Internal.Collections
{
internal static partial class CollectionServices
{
private static readonly Type StringType = typeof(string);
private static readonly Type IEnumerableType = typeof(IEnumerable);
private static readonly Type IEnumerableOfTType = typeof(IEnumerable<>);
private static readonly Type ICollectionOfTType = typeof(ICollection<>);
public static bool IsEnumerableOfT(Type type)
{
if (type.IsGenericType)
{
Type genericType = type.GetGenericTypeDefinition().UnderlyingSystemType;
if (genericType == IEnumerableOfTType)
{
return true;
}
}
return false;
}
public static Type GetEnumerableElementType(Type type)
{
if (type.UnderlyingSystemType == StringType || !IEnumerableType.IsAssignableFrom(type))
{
return null;
}
Type closedType;
if (ReflectionServices.TryGetGenericInterfaceType(type, IEnumerableOfTType, out closedType))
{
return closedType.GetGenericArguments()[0];
}
return null;
}
public static Type GetCollectionElementType(Type type)
{
Type closedType;
if (ReflectionServices.TryGetGenericInterfaceType(type, ICollectionOfTType, out closedType))
{
return closedType.GetGenericArguments()[0];
}
return null;
}
public static ReadOnlyCollection<T> ToReadOnlyCollection<T>(this IEnumerable<T> source)
{
Assumes.NotNull(source);
return new ReadOnlyCollection<T>(source.AsArray());
}
public static IEnumerable<T> ConcatAllowingNull<T>(this IEnumerable<T> source, IEnumerable<T> second)
{
if (second == null || !second.FastAny())
{
return source;
}
if (source == null || !source.FastAny())
{
return second;
}
return source.Concat(second);
}
public static ICollection<T> ConcatAllowingNull<T>(this ICollection<T> source, ICollection<T> second)
{
if (second == null || (second.Count == 0))
{
return source;
}
if (source == null || (source.Count == 0))
{
return second;
}
List<T> result = new List<T>(source);
result.AddRange(second);
return result;
}
public static List<T> FastAppendToListAllowNulls<T>(this List<T> source, IEnumerable<T> second)
{
if (second == null)
{
return source;
}
// if there's nothing in the source, return the second
if ((source == null) || (source.Count == 0))
{
return second.AsList();
}
// if the second is List<T>, and contains very few elements there's no need for AddRange
List<T> secondAsList = second as List<T>;
if (secondAsList != null)
{
if (secondAsList.Count == 0)
{
return source;
}
else if (secondAsList.Count == 1)
{
source.Add(secondAsList[0]);
return source;
}
}
// last resort - nothing is null, need to append
source.AddRange(second);
return source;
}
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
{
foreach(T t in source)
{
action.Invoke(t);
}
}
public static EnumerableCardinality GetCardinality<T>(this IEnumerable<T> source)
{
Assumes.NotNull(source);
// Cast to ICollection instead of ICollection<T> for performance reasons.
ICollection collection = source as ICollection;
if (collection != null)
{
switch (collection.Count)
{
case 0:
return EnumerableCardinality.Zero;
case 1:
return EnumerableCardinality.One;
default:
return EnumerableCardinality.TwoOrMore;
}
}
using (var enumerator = source.GetEnumerator())
{
if (!enumerator.MoveNext())
{
return EnumerableCardinality.Zero;
}
if (!enumerator.MoveNext())
{
return EnumerableCardinality.One;
}
return EnumerableCardinality.TwoOrMore;
}
}
public static bool FastAny<T>(this IEnumerable<T> source)
{
// Enumerable.Any<T> underneath doesn't cast to ICollection,
// like it does with many of the other LINQ methods.
// Below is significantly (4x) when mainly working with ICollection
// sources and a little slower if working with mainly IEnumerable<T>
// sources.
// Cast to ICollection instead of ICollection<T> for performance reasons.
ICollection collection = source as ICollection;
if (collection != null)
{
return collection.Count > 0;
}
return source.Any();
}
public static Stack<T> Copy<T>(this Stack<T> stack)
{
Assumes.NotNull(stack);
// Stack<T>.GetEnumerator walks from top to bottom
// of the stack, whereas Stack<T>(IEnumerable<T>)
// pushes to bottom from top, so we need to reverse
// the stack to get them in the right order.
return new Stack<T>(stack.Reverse());
}
public static T[] AsArray<T>(this IEnumerable<T> enumerable)
{
T[] array = enumerable as T[];
if (array != null)
{
return array;
}
return enumerable.ToArray();
}
public static List<T> AsList<T>(this IEnumerable<T> enumerable)
{
List<T> list = enumerable as List<T>;
if (list != null)
{
return list;
}
return enumerable.ToList();
}
public static bool IsArrayEqual<T>(this T[] thisArray, T[] thatArray)
{
if (thisArray.Length != thatArray.Length)
{
return false;
}
for(int i=0; i< thisArray.Length; i++)
{
if (!thisArray[i].Equals( thatArray[i]))
{
return false;
}
}
return true;
}
public static bool IsCollectionEqual<T>(this IList<T> thisList, IList<T> thatList)
{
if (thisList.Count != thatList.Count)
{
return false;
}
for (int i = 0; i < thisList.Count; i++)
{
if (!thisList[i].Equals(thatList[i]))
{
return false;
}
}
return true;
}
}
}

View File

@@ -0,0 +1,14 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
namespace Microsoft.Internal.Collections
{
internal enum EnumerableCardinality : int
{
Zero = 0,
One = 1,
TwoOrMore = 2,
}
}

View File

@@ -0,0 +1,106 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Internal;
// This is using the desktop namespace for ReadOnlyDictionary, the source code is in Microsoft\Internal\Collections to keep it seperate from the main MEF codebase.
namespace System.Collections.ObjectModel
{
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(ReadOnlyDictionaryDebuggerProxy<,>))]
internal sealed partial class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
{
private readonly IDictionary<TKey, TValue> _innerDictionary;
public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionary)
{
this._innerDictionary = dictionary ?? new Dictionary<TKey, TValue>(0);
}
public int Count
{
get { return this._innerDictionary.Count; }
}
public bool IsReadOnly
{
get { return true; }
}
public ICollection<TKey> Keys
{
get { return this._innerDictionary.Keys; }
}
public TValue this[TKey key]
{
get { return this._innerDictionary[key]; }
set { throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary); }
}
public ICollection<TValue> Values
{
get { return this._innerDictionary.Values; }
}
public bool Contains(KeyValuePair<TKey, TValue> item)
{
return this._innerDictionary.Contains(item);
}
public bool ContainsKey(TKey key)
{
return this._innerDictionary.ContainsKey(key);
}
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
{
this._innerDictionary.CopyTo(array, arrayIndex);
}
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return this._innerDictionary.GetEnumerator();
}
public bool TryGetValue(TKey key, out TValue value)
{
return this._innerDictionary.TryGetValue(key, out value);
}
IEnumerator IEnumerable.GetEnumerator()
{
return this._innerDictionary.GetEnumerator();
}
void IDictionary<TKey, TValue>.Add(TKey key, TValue value)
{
throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
}
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
{
throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
}
void ICollection<KeyValuePair<TKey, TValue>>.Clear()
{
throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
}
bool IDictionary<TKey, TValue>.Remove(TKey key)
{
throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
}
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
{
throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
}
}
}

View File

@@ -0,0 +1,34 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.Internal;
namespace System.Collections.ObjectModel
{
// NOTE: This type cannot be a nested proxy of ReadOnlyDictionary due to a bug
// in the Visual Studio Debugger which causes it to ignore nested generic proxies.
internal class ReadOnlyDictionaryDebuggerProxy<TKey, TValue>
{
private readonly ReadOnlyDictionary<TKey, TValue> _dictionary;
public ReadOnlyDictionaryDebuggerProxy(ReadOnlyDictionary<TKey, TValue> dictionary)
{
Requires.NotNull(dictionary, "dictionary");
_dictionary = dictionary;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyValuePair<TKey, TValue>[] Items
{
// NOTE: This shouldn't be cached, so that on every query of
// the current value of the underlying dictionary is respected.
get { return this._dictionary.ToArray(); }
}
}
}

View File

@@ -0,0 +1,85 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Internal;
using Microsoft.Internal.Collections;
namespace Microsoft.Internal.Collections
{
internal class WeakReferenceCollection<T> where T : class
{
private readonly List<WeakReference> _items = new List<WeakReference>();
public void Add(T item)
{
// Only cleanup right before we need to reallocate space.
if (this._items.Capacity == this._items.Count)
{
this.CleanupDeadReferences();
}
this._items.Add(new WeakReference(item));
}
public void Remove(T item)
{
int index = IndexOf(item);
if (index != -1)
{
this._items.RemoveAt(index);
}
}
public bool Contains(T item)
{
return IndexOf(item) >= 0;
}
public void Clear()
{
this._items.Clear();
}
// Should be executed under at least a read lock.
private int IndexOf(T item)
{
int count = this._items.Count;
for (int i = 0; i < count; i++)
{
if (object.ReferenceEquals(this._items[i].Target, item))
{
return i;
}
}
return -1;
}
// Should be executed under a write lock
private void CleanupDeadReferences()
{
this._items.RemoveAll(w => !w.IsAlive);
}
public List<T> AliveItemsToList()
{
List<T> aliveItems = new List<T>();
foreach (var weakItem in this._items)
{
T item = weakItem.Target as T;
if (item != null)
{
aliveItems.Add(item);
}
}
return aliveItems;
}
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Text;
using System.Threading;
using System.ComponentModel.Composition.Primitives;
namespace Microsoft.Internal
{
internal static class ContractServices
{
public static bool TryCast(Type contractType, object value, out object result)
{
if (value == null)
{
result = null;
return true;
}
if (contractType.IsInstanceOfType(value))
{
result = value;
return true;
}
// We couldn't cast see if a delegate works for us.
if (typeof(Delegate).IsAssignableFrom(contractType))
{
ExportedDelegate exportedDelegate = value as ExportedDelegate;
if (exportedDelegate != null)
{
result = exportedDelegate.CreateDelegate(contractType.UnderlyingSystemType);
return (result != null);
}
}
result = null;
return false;
}
}
}

View File

@@ -0,0 +1,335 @@
#if !FULL_AOT_RUNTIME
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
namespace Microsoft.Internal
{
internal static class GenerationServices
{
// Type.GetTypeFromHandle
private static readonly MethodInfo _typeGetTypeFromHandleMethod = typeof(Type).GetMethod("GetTypeFromHandle");
// typeofs are pretty expensive, so we cache them statically
private static readonly Type TypeType = typeof(System.Type);
private static readonly Type StringType = typeof(System.String);
private static readonly Type CharType = typeof(System.Char);
private static readonly Type BooleanType = typeof(System.Boolean);
private static readonly Type ByteType = typeof(System.Byte);
private static readonly Type SByteType = typeof(System.SByte);
private static readonly Type Int16Type = typeof(System.Int16);
private static readonly Type UInt16Type = typeof(System.UInt16);
private static readonly Type Int32Type = typeof(System.Int32);
private static readonly Type UInt32Type = typeof(System.UInt32);
private static readonly Type Int64Type = typeof(System.Int64);
private static readonly Type UInt64Type = typeof(System.UInt64);
private static readonly Type DoubleType = typeof(System.Double);
private static readonly Type SingleType = typeof(System.Single);
private static readonly Type IEnumerableTypeofT = typeof(System.Collections.Generic.IEnumerable<>);
private static readonly Type IEnumerableType = typeof(System.Collections.IEnumerable);
private static readonly MethodInfo ExceptionGetData = typeof(Exception).GetProperty("Data").GetGetMethod();
private static readonly MethodInfo DictionaryAdd = typeof(IDictionary).GetMethod("Add");
private static readonly ConstructorInfo ObjectCtor = typeof(object).GetConstructor(Type.EmptyTypes);
public static ILGenerator CreateGeneratorForPublicConstructor(this TypeBuilder typeBuilder, Type[] ctrArgumentTypes)
{
ConstructorBuilder ctorBuilder = typeBuilder.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
ctrArgumentTypes);
ILGenerator ctorIL = ctorBuilder.GetILGenerator();
ctorIL.Emit(OpCodes.Ldarg_0);
ctorIL.Emit(OpCodes.Call, ObjectCtor);
return ctorIL;
}
/// Generates the code that loads the supplied value on the stack
/// This is not as simple as it seems, as different instructions need to be generated depending
/// on its type.
/// We support:
/// 1. All primitive types
/// 2. Strings
/// 3. Enums
/// 4. typeofs
/// 5. nulls
/// 6. Enumerables
/// 7. Delegates on static functions or any of the above
/// Everything else cannot be represented as literals
/// <param name="ilGenerator"></param>
/// <param name="item"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static void LoadValue(this ILGenerator ilGenerator, object value)
{
Assumes.NotNull(ilGenerator);
//
// Get nulls out of the way - they are basically typeless, so we just load null
//
if (value == null)
{
ilGenerator.LoadNull();
return;
}
//
// Prepare for literal loading - decide whether we should box, and handle enums properly
//
Type valueType = value.GetType();
object rawValue = value;
if (valueType.IsEnum)
{
// enums are special - we need to load the underlying constant on the stack
rawValue = Convert.ChangeType(value, Enum.GetUnderlyingType(valueType), null);
valueType = rawValue.GetType();
}
//
// Generate IL depending on the valueType - this is messier than it should ever be, but sadly necessary
//
if (valueType == GenerationServices.StringType)
{
// we need to check for strings before enumerables, because strings are IEnumerable<char>
ilGenerator.LoadString((string)rawValue);
}
else if (GenerationServices.TypeType.IsAssignableFrom(valueType))
{
ilGenerator.LoadTypeOf((Type)rawValue);
}
else if (GenerationServices.IEnumerableType.IsAssignableFrom(valueType))
{
// NOTE : strings and dictionaries are also enumerables, but we have already handled those
ilGenerator.LoadEnumerable((IEnumerable) rawValue);
}
else if (
(valueType == GenerationServices.CharType) ||
(valueType == GenerationServices.BooleanType) ||
(valueType == GenerationServices.ByteType) ||
(valueType == GenerationServices.SByteType) ||
(valueType == GenerationServices.Int16Type) ||
(valueType == GenerationServices.UInt16Type) ||
(valueType == GenerationServices.Int32Type)
)
{
// NOTE : Everything that is 32 bit or less uses ldc.i4. We need to pass int32, even if the actual types is shorter - this is IL memory model
// direct casting to (int) won't work, because the value is boxed, thus we need to use Convert.
// Sadly, this will not work for all cases - namely large uint32 - because they can't semantically fit into 32 signed bits
// We have a special case for that next
ilGenerator.LoadInt((int)Convert.ChangeType(rawValue, typeof(int), CultureInfo.InvariantCulture));
}
else if (valueType == GenerationServices.UInt32Type)
{
// NOTE : This one is a bit tricky. Ldc.I4 takes an Int32 as an argument, although it really treats it as a 32bit number
// That said, some UInt32 values are larger that Int32.MaxValue, so the Convert call above will fail, which is why
// we need to treat this case individually and cast to uint, and then - unchecked - to int.
ilGenerator.LoadInt(unchecked((int)((uint)rawValue)));
}
else if (valueType == GenerationServices.Int64Type)
{
ilGenerator.LoadLong((long)rawValue);
}
else if (valueType == GenerationServices.UInt64Type)
{
// NOTE : This one is a bit tricky. Ldc.I8 takes an Int64 as an argument, although it really treats it as a 64bit number
// That said, some UInt64 values are larger that Int64.MaxValue, so the direct case we use above (or Convert, for that matter)will fail, which is why
// we need to treat this case individually and cast to ulong, and then - unchecked - to long.
ilGenerator.LoadLong(unchecked((long)((ulong)rawValue)));
}
else if (valueType == GenerationServices.SingleType)
{
ilGenerator.LoadFloat((float)rawValue);
}
else if (valueType == GenerationServices.DoubleType)
{
ilGenerator.LoadDouble((double)rawValue);
}
else
{
throw new InvalidOperationException(
string.Format(CultureInfo.CurrentCulture, Strings.InvalidMetadataValue, value.GetType().FullName));
}
}
/// Generates the code that adds an object to a dictionary stored in a local variable
/// <param name="ilGenerator"></param>
/// <param name="dictionary"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static void AddItemToLocalDictionary(this ILGenerator ilGenerator, LocalBuilder dictionary, object key, object value)
{
Assumes.NotNull(ilGenerator);
Assumes.NotNull(dictionary);
Assumes.NotNull(key);
Assumes.NotNull(value);
ilGenerator.Emit(OpCodes.Ldloc, dictionary);
ilGenerator.LoadValue(key);
ilGenerator.LoadValue(value);
ilGenerator.Emit(OpCodes.Callvirt, DictionaryAdd);
}
/// Generates the code that adds an object from a local variable to a dictionary also stored in a local
/// <param name="ilGenerator"></param>
/// <param name="dictionary"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static void AddLocalToLocalDictionary(this ILGenerator ilGenerator, LocalBuilder dictionary, object key, LocalBuilder value)
{
Assumes.NotNull(ilGenerator);
Assumes.NotNull(dictionary);
Assumes.NotNull(key);
Assumes.NotNull(value);
ilGenerator.Emit(OpCodes.Ldloc, dictionary);
ilGenerator.LoadValue(key);
ilGenerator.Emit(OpCodes.Ldloc, value);
ilGenerator.Emit(OpCodes.Callvirt, DictionaryAdd);
}
/// Generates the code to get the type of an object and store it in a local
/// <param name="ilGenerator"></param>
/// <param name="dictionary"></param>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static void GetExceptionDataAndStoreInLocal(this ILGenerator ilGenerator, LocalBuilder exception, LocalBuilder dataStore)
{
Assumes.NotNull(ilGenerator);
Assumes.NotNull(exception);
Assumes.NotNull(dataStore);
ilGenerator.Emit(OpCodes.Ldloc, exception);
ilGenerator.Emit(OpCodes.Callvirt, ExceptionGetData);
ilGenerator.Emit(OpCodes.Stloc, dataStore);
}
private static void LoadEnumerable(this ILGenerator ilGenerator, IEnumerable enumerable)
{
Assumes.NotNull(ilGenerator);
Assumes.NotNull(enumerable);
// We load enumerable as an array - this is the most compact and efficient way of representing it
Type elementType = null;
Type closedType = null;
if (ReflectionServices.TryGetGenericInterfaceType(enumerable.GetType(), GenerationServices.IEnumerableTypeofT, out closedType))
{
elementType = closedType.GetGenericArguments()[0];
}
else
{
elementType = typeof(object);
}
//
// elem[] array = new elem[<enumerable.Count()>]
//
Type generatedArrayType = elementType.MakeArrayType();
LocalBuilder generatedArrayLocal = ilGenerator.DeclareLocal(generatedArrayType);
ilGenerator.LoadInt(enumerable.Cast<object>().Count());
ilGenerator.Emit(OpCodes.Newarr, elementType);
ilGenerator.Emit(OpCodes.Stloc, generatedArrayLocal);
int index = 0;
foreach (object value in enumerable)
{
//
//array[<index>] = value;
//
ilGenerator.Emit(OpCodes.Ldloc, generatedArrayLocal);
ilGenerator.LoadInt(index);
ilGenerator.LoadValue(value);
if (GenerationServices.IsBoxingRequiredForValue(value) && !elementType.IsValueType)
{
ilGenerator.Emit(OpCodes.Box, value.GetType());
}
ilGenerator.Emit(OpCodes.Stelem, elementType);
index++;
}
ilGenerator.Emit(OpCodes.Ldloc, generatedArrayLocal);
}
private static bool IsBoxingRequiredForValue(object value)
{
if (value == null)
{
return false;
}
else
{
return value.GetType().IsValueType;
}
}
private static void LoadNull(this ILGenerator ilGenerator)
{
ilGenerator.Emit(OpCodes.Ldnull);
}
private static void LoadString(this ILGenerator ilGenerator, string s)
{
Assumes.NotNull(ilGenerator);
if (s == null)
{
ilGenerator.LoadNull();
}
else
{
ilGenerator.Emit(OpCodes.Ldstr, s);
}
}
private static void LoadInt(this ILGenerator ilGenerator, int value)
{
Assumes.NotNull(ilGenerator);
ilGenerator.Emit(OpCodes.Ldc_I4, value);
}
private static void LoadLong(this ILGenerator ilGenerator, long value)
{
Assumes.NotNull(ilGenerator);
ilGenerator.Emit(OpCodes.Ldc_I8, value);
}
private static void LoadFloat(this ILGenerator ilGenerator, float value)
{
Assumes.NotNull(ilGenerator);
ilGenerator.Emit(OpCodes.Ldc_R4, value);
}
private static void LoadDouble(this ILGenerator ilGenerator, double value)
{
Assumes.NotNull(ilGenerator);
ilGenerator.Emit(OpCodes.Ldc_R8, value);
}
private static void LoadTypeOf(this ILGenerator ilGenerator, Type type)
{
Assumes.NotNull(ilGenerator);
//typeofs() translate into ldtoken and Type::GetTypeFromHandle call
ilGenerator.Emit(OpCodes.Ldtoken, type);
ilGenerator.EmitCall(OpCodes.Call, GenerationServices._typeGetTypeFromHandleMethod, null);
}
}
}
#endif

View File

@@ -0,0 +1,26 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Globalization;
using System.Threading;
namespace Microsoft.Internal
{
internal static class LazyServices
{
public static T GetNotNullValue<T>(this Lazy<T> lazy, string argument)
where T : class
{
Assumes.NotNull(lazy);
T value = lazy.Value;
if (value == null)
{
throw new InvalidOperationException(
string.Format(CultureInfo.CurrentCulture, Strings.LazyServices_LazyResolvesToNull, typeof(T), argument));
}
return value;
}
}
}

View File

@@ -0,0 +1,32 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Microsoft.Internal
{
internal struct ReadLock : IDisposable
{
private readonly Lock _lock;
private int _isDisposed;
public ReadLock(Lock @lock)
{
this._isDisposed = 0;
this._lock = @lock;
this._lock.EnterReadLock();
}
public void Dispose()
{
if (Interlocked.CompareExchange(ref this._isDisposed, 1, 0) == 0)
{
this._lock.ExitReadLock();
}
}
}
}

View File

@@ -0,0 +1,32 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Microsoft.Internal
{
internal struct WriteLock : IDisposable
{
private readonly Lock _lock;
private int _isDisposed;
public WriteLock(Lock @lock)
{
this._isDisposed = 0;
this._lock = @lock;
this._lock.EnterWriteLock();
}
public void Dispose()
{
if (Interlocked.CompareExchange(ref this._isDisposed, 1, 0) == 0)
{
this._lock.ExitWriteLock();
}
}
}
}

View File

@@ -0,0 +1,79 @@
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Microsoft.Internal
{
internal sealed class Lock : IDisposable
{
#if (FEATURE_SLIMLOCK)
private ReaderWriterLockSlim _thisLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
private int _isDisposed = 0;
public void EnterReadLock()
{
this._thisLock.EnterReadLock();
}
public void EnterWriteLock()
{
this._thisLock.EnterWriteLock();
}
public void ExitReadLock()
{
this._thisLock.ExitReadLock();
}
public void ExitWriteLock()
{
this._thisLock.ExitWriteLock();
}
public void Dispose()
{
if (Interlocked.CompareExchange(ref this._isDisposed, 1, 0) == 0)
{
this._thisLock.Dispose();
}
}
#else
// ReaderWriterLockSlim is not yet implemented on SilverLight
// Satisfies our requirements until it is implemented
object _thisLock = new object();
public Lock()
{
}
public void EnterReadLock()
{
Monitor.Enter(this._thisLock);
}
public void EnterWriteLock()
{
Monitor.Enter(this._thisLock);
}
public void ExitReadLock()
{
Monitor.Exit(this._thisLock);
}
public void ExitWriteLock()
{
Monitor.Exit(this._thisLock);
}
public void Dispose()
{
}
#endif
}
}

View File

@@ -0,0 +1,119 @@
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
namespace Microsoft.Internal
{
internal static class ReflectionInvoke
{
public static object SafeCreateInstance(this Type type, params object[] arguments)
{
DemandMemberAccessIfNeeded(type);
return Activator.CreateInstance(type, arguments);
}
public static object SafeInvoke(this ConstructorInfo constructor, params object[] arguments)
{
DemandMemberAccessIfNeeded(constructor);
return constructor.Invoke(arguments);
}
public static object SafeInvoke(this MethodInfo method, object instance, params object[] arguments)
{
DemandMemberAccessIfNeeded(method);
return method.Invoke(instance, arguments);
}
public static object SafeGetValue(this FieldInfo field, object instance)
{
DemandMemberAccessIfNeeded(field);
return field.GetValue(instance);
}
public static void SafeSetValue(this FieldInfo field, object instance, object value)
{
DemandMemberAccessIfNeeded(field);
field.SetValue(instance, value);
}
#if FEATURE_CAS_APTCA
private static readonly ReflectionPermission _memberAccess = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
private static readonly ReflectionPermission _restrictedMemberAccess = new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess);
public static void DemandMemberAccessIfNeeded(MethodInfo method)
{
if (!method.IsVisible())
{
DemandMemberAccess(method);
}
}
private static void DemandMemberAccessIfNeeded(FieldInfo field)
{
if (!field.IsVisible())
{
DemandMemberAccess(field);
}
}
public static void DemandMemberAccessIfNeeded(Type type)
{
// Consult UnderlyingSystemType this is the type that Activator.CreateInstance creates
if (!type.UnderlyingSystemType.IsVisible)
{
DemandMemberAccess(type);
}
}
private static void DemandMemberAccessIfNeeded(ConstructorInfo constructor)
{
if (!constructor.IsVisible())
{
DemandMemberAccess(constructor);
}
}
[System.Security.SecuritySafeCritical]
private static void DemandMemberAccess(MemberInfo target)
{
try
{
_memberAccess.Demand();
}
catch (SecurityException)
{ // The caller doesn't have member access, but let's see whether they have access to
// members of assemblies with less or equal permissions (this mimics Reflection's behavior)
DemandRestrictedMemberAccess(target);
}
}
[System.Security.SecuritySafeCritical]
private static void DemandRestrictedMemberAccess(MemberInfo target)
{
Assembly targetAssembly = target.Assembly();
PermissionSet targetGrantSet = UnsafePermissionSet(targetAssembly);
targetGrantSet.AddPermission(_restrictedMemberAccess);
targetGrantSet.Demand();
}
[SecuritySafeCritical] // PermissionSet is [SecurityCritical]
private static PermissionSet UnsafePermissionSet(Assembly assembly)
{
return assembly.PermissionSet;
}
#else
public static void DemandMemberAccessIfNeeded(MethodInfo method) { }
private static void DemandMemberAccessIfNeeded(ConstructorInfo constructor) { }
private static void DemandMemberAccessIfNeeded(FieldInfo field) { }
public static void DemandMemberAccessIfNeeded(Type type) { }
#endif //FEATURE_CAS_APTCA
}
}

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