本文整理汇总了C#中Type.Assembly方法的典型用法代码示例。如果您正苦于以下问题:C# Type.Assembly方法的具体用法?C# Type.Assembly怎么用?C# Type.Assembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.Assembly方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindRow
public virtual DataRow FindRow(Type hintType, Func<DataRow, bool> selector, IEnumerable<DataRow> dataRows)
{
DebugCheck.NotNull(selector);
DebugCheck.NotNull(dataRows);
const int assemblyQualifiedNameIndex = 3;
var assemblyHint = hintType == null ? null : new AssemblyName(hintType.Assembly().FullName);
foreach (var row in dataRows)
{
var assemblyQualifiedTypeName = (string)row[assemblyQualifiedNameIndex];
AssemblyName rowProviderFactoryAssemblyName = null;
// Parse the provider factory assembly qualified type name
Type.GetType(
assemblyQualifiedTypeName,
a =>
{
rowProviderFactoryAssemblyName = a;
return null;
},
(_, __, ___) => null);
if (rowProviderFactoryAssemblyName != null
&& (hintType == null
|| string.Equals(
assemblyHint.Name,
rowProviderFactoryAssemblyName.Name,
StringComparison.OrdinalIgnoreCase)))
{
try
{
if (selector(row))
{
return row;
}
}
catch (Exception ex)
{
Debug.Fail("GetFactory failed with: " + ex);
// Ignore bad providers.
}
}
}
return null;
}
示例2: GetRelationshipTypeExpensiveWay
public virtual AssociationType GetRelationshipTypeExpensiveWay(Type entityClrType, string relationshipName)
{
DebugCheck.NotNull(entityClrType);
DebugCheck.NotEmpty(relationshipName);
var typesInLoading = LoadTypesExpensiveWay(entityClrType.Assembly());
if (typesInLoading != null)
{
EdmType edmType;
// Look in typesInLoading for relationship type
if (typesInLoading.TryGetValue(relationshipName, out edmType)
&& Helper.IsRelationshipType(edmType))
{
return (AssociationType)edmType;
}
}
return null;
}
示例3: CreateAndAddEnumProperty
// <summary>
// Creates an Enum property based on <paramref name="clrProperty" /> and adds it to the parent structural type.
// </summary>
// <param name="type">
// CLR type owning <paramref name="clrProperty" /> .
// </param>
// <param name="ospaceType"> OSpace type the created property will be added to. </param>
// <param name="cspaceProperty"> Corresponding property from CSpace. </param>
// <param name="clrProperty"> CLR property used to build an Enum property. </param>
private void CreateAndAddEnumProperty(Type type, StructuralType ospaceType, EdmProperty cspaceProperty, PropertyInfo clrProperty)
{
EdmType propertyType;
if (CspaceToOspace.TryGetValue(cspaceProperty.TypeUsage.EdmType, out propertyType))
{
if (clrProperty.CanRead
&& clrProperty.CanWriteExtended())
{
AddScalarMember(type, clrProperty, ospaceType, cspaceProperty, propertyType);
}
else
{
LogError(
Strings.Validator_OSpace_Convention_ScalarPropertyMissginGetterOrSetter(
clrProperty.Name, type.FullName, type.Assembly().FullName),
cspaceProperty.TypeUsage.EdmType);
}
}
else
{
LogError(
Strings.Validator_OSpace_Convention_MissingOSpaceType(cspaceProperty.TypeUsage.EdmType.FullName),
cspaceProperty.TypeUsage.EdmType);
}
}
示例4: TryFindAndCreatePrimitiveProperties
private bool TryFindAndCreatePrimitiveProperties(
Type type, StructuralType cspaceType, StructuralType ospaceType, IEnumerable<PropertyInfo> clrProperties)
{
foreach (
var cspaceProperty in
cspaceType.GetDeclaredOnlyMembers<EdmProperty>().Where(p => Helper.IsPrimitiveType(p.TypeUsage.EdmType)))
{
var clrProperty = clrProperties.FirstOrDefault(p => MemberMatchesByConvention(p, cspaceProperty));
if (clrProperty != null)
{
PrimitiveType propertyType;
if (TryGetPrimitiveType(clrProperty.PropertyType, out propertyType))
{
if (clrProperty.CanRead
&& clrProperty.CanWriteExtended())
{
AddScalarMember(type, clrProperty, ospaceType, cspaceProperty, propertyType);
}
else
{
var message = Strings.Validator_OSpace_Convention_ScalarPropertyMissginGetterOrSetter(
clrProperty.Name, type.FullName, type.Assembly().FullName);
LogLoadMessage(message, cspaceType);
return false;
}
}
else
{
var message = Strings.Validator_OSpace_Convention_NonPrimitiveTypeProperty(
clrProperty.Name, type.FullName, clrProperty.PropertyType.FullName);
LogLoadMessage(message, cspaceType);
return false;
}
}
else
{
var message = Strings.Validator_OSpace_Convention_MissingRequiredProperty(cspaceProperty.Name, type.FullName);
LogLoadMessage(message, cspaceType);
return false;
}
}
return true;
}
示例5: IsProxyType
// <summary>
// Determine if the specified type represents a known proxy type.
// </summary>
// <param name="type"> The Type to be examined. </param>
// <returns> True if the type is a known proxy type; otherwise false. </returns>
internal static bool IsProxyType(Type type)
{
DebugCheck.NotNull(type);
return type != null && _proxyRuntimeAssemblies.Contains(type.Assembly());
}
示例6: AssertTypeIsInExpectedAssembly
private void AssertTypeIsInExpectedAssembly(Type type)
{
#if NET40
Assert.Same(EntityFrameworkAssembly, type.Assembly);
#else
Assert.Same(SystemComponentModelDataAnnotationsAssembly, type.Assembly());
#endif
}
示例7: TrackClosure
private void TrackClosure(Type type)
{
if (SourceAssembly != type.Assembly()
&& !CacheEntry.ClosureAssemblies.Contains(type.Assembly())
&& IsSchemaAttributePresent(type.Assembly())
&& !(type.IsGenericType() &&
(
EntityUtil.IsAnICollection(type) || // EntityCollection<>, List<>, ICollection<>
type.GetGenericTypeDefinition() == typeof(EntityReference<>) ||
type.GetGenericTypeDefinition() == typeof(Nullable<>)
)
)
)
{
CacheEntry.ClosureAssemblies.Add(type.Assembly());
}
if (type.IsGenericType())
{
foreach (var genericArgument in type.GetGenericArguments())
{
TrackClosure(genericArgument);
}
}
}
示例8: LoadType
// <summary>
// Load metadata of the given type - when you call this method, you should check and make sure that the type has
// edm attribute. If it doesn't,we won't load the type and it will be returned as null
// </summary>
private void LoadType(Type clrType)
{
Debug.Assert(clrType.Assembly() == SourceAssembly, "Why are we loading a type that is not in our assembly?");
Debug.Assert(!SessionData.TypesInLoading.ContainsKey(clrType.FullName), "Trying to load a type that is already loaded???");
Debug.Assert(!clrType.IsGenericType(), "Generic type is not supported");
EdmType edmType = null;
var typeAttributes = clrType.GetCustomAttributes<EdmTypeAttribute>(inherit: false);
// the CLR doesn't allow types to have duplicate/multiple attribute declarations
if (typeAttributes.Any())
{
if (clrType.IsNested)
{
SessionData.EdmItemErrors.Add(
new EdmItemError(Strings.NestedClassNotSupported(clrType.FullName, clrType.Assembly().FullName)));
return;
}
var typeAttribute = typeAttributes.First();
var cspaceTypeName = String.IsNullOrEmpty(typeAttribute.Name) ? clrType.Name : typeAttribute.Name;
if (String.IsNullOrEmpty(typeAttribute.NamespaceName)
&& clrType.Namespace == null)
{
SessionData.EdmItemErrors.Add(new EdmItemError(Strings.Validator_TypeHasNoNamespace));
return;
}
var cspaceNamespaceName = String.IsNullOrEmpty(typeAttribute.NamespaceName)
? clrType.Namespace
: typeAttribute.NamespaceName;
if (typeAttribute.GetType() == typeof(EdmEntityTypeAttribute))
{
edmType = new ClrEntityType(clrType, cspaceNamespaceName, cspaceTypeName);
}
else if (typeAttribute.GetType() == typeof(EdmComplexTypeAttribute))
{
edmType = new ClrComplexType(clrType, cspaceNamespaceName, cspaceTypeName);
}
else
{
Debug.Assert(typeAttribute is EdmEnumTypeAttribute, "Invalid type attribute encountered");
// Note that TryGetPrimitiveType() will return false not only for types that are not primitive
// but also for CLR primitive types that are valid underlying enum types in CLR but are not
// a valid Edm primitive types (e.g. ulong)
PrimitiveType underlyingEnumType;
if (!ClrProviderManifest.Instance.TryGetPrimitiveType(clrType.GetEnumUnderlyingType(), out underlyingEnumType))
{
SessionData.EdmItemErrors.Add(
new EdmItemError(
Strings.Validator_UnsupportedEnumUnderlyingType(clrType.GetEnumUnderlyingType().FullName)));
return;
}
edmType = new ClrEnumType(clrType, cspaceNamespaceName, cspaceTypeName);
}
}
else
{
// not a type we are interested
return;
}
Debug.Assert(
!CacheEntry.ContainsType(edmType.Identity), "This type must not be already present in the list of types for this assembly");
// Also add this to the list of the types for this assembly
CacheEntry.TypesInAssembly.Add(edmType);
// Add this to the known type map so we won't try to load it again
SessionData.TypesInLoading.Add(clrType.FullName, edmType);
// Load properties for structural type
if (Helper.IsStructuralType(edmType))
{
//Load base type only for entity type - not sure if we will allow complex type inheritance
if (Helper.IsEntityType(edmType))
{
TrackClosure(clrType.BaseType());
AddTypeResolver(
() => edmType.BaseType = ResolveBaseType(clrType.BaseType()));
}
// Load the properties for this type
LoadPropertiesFromType((StructuralType)edmType);
}
return;
}
示例9: TryGetCachedEdmType
private bool TryGetCachedEdmType(Type clrType, out EdmType edmType)
{
Debug.Assert(
!SessionData.TypesInLoading.ContainsKey(clrType.FullName), "This should be called only after looking in typesInLoading");
Debug.Assert(
SessionData.EdmItemErrors.Count > 0 || // had an error during loading
!clrType.GetCustomAttributes<EdmTypeAttribute>(inherit: false).Any() || // not a type we track
SourceAssembly != clrType.Assembly(), // not from this assembly
"Given that we don't have any error, if the type is part of this assembly, it should not be loaded from the cache");
ImmutableAssemblyCacheEntry immutableCacheEntry;
if (SessionData.LockedAssemblyCache.TryGetValue(clrType.Assembly(), out immutableCacheEntry))
{
Debug.Assert(
SessionData.KnownAssemblies.Contains(clrType.Assembly(), SessionData.LoaderCookie, SessionData.EdmItemCollection),
"We should only be loading things directly from the cache if they are already in the collection");
return immutableCacheEntry.TryGetEdmType(clrType.FullName, out edmType);
}
edmType = null;
return false;
}
示例10: PushConfiguration
public virtual bool PushConfiguration(AppConfig config, Type contextType)
{
DebugCheck.NotNull(config);
DebugCheck.NotNull(contextType);
Debug.Assert(typeof(DbContext).IsAssignableFrom(contextType));
// Perf optimization: if there is no change to the default app-domain config and if the
// context assembly has already been checked for configurations, then avoid creating
// and pushing a new configuration since it would be the same as the current one anyway.
if (config == AppConfig.DefaultInstance
&& (contextType == typeof(DbContext) || _knownAssemblies.ContainsKey(contextType.Assembly())))
{
return false;
}
var configuration = (_loader.TryLoadFromConfig(config)
?? _finder.TryFindConfigurationType(contextType)
?? typeof(DbConfiguration))
.CreateInstance<DbConfiguration>(Strings.CreateInstance_BadDbConfigurationType)
.InternalConfiguration;
configuration.SwitchInRootResolver(_configuration.Value.RootResolver);
configuration.AddAppConfigResolver(new AppConfigDependencyResolver(config, configuration));
lock (_lock)
{
_configurationOverrides.Value.Add(Tuple.Create(config, configuration));
}
configuration.Lock();
return true;
}
示例11: EnsureLoadedForContext
public virtual void EnsureLoadedForContext(Type contextType)
{
DebugCheck.NotNull(contextType);
Debug.Assert(typeof(DbContext).IsAssignableFrom(contextType));
EnsureLoadedForAssembly(contextType.Assembly(), contextType);
}