本文整理汇总了C#中System.Type.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Type.Contains方法的具体用法?C# Type.Contains怎么用?C# Type.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadMappingFrom
public static HbmMapping LoadMappingFrom(params Assembly[] assemblies)
{
Require.NotNull(assemblies, "assemblies");
var baseTypes = new Type[] {
typeof(ClassMapping<>),
typeof(JoinedSubclassMapping<>),
typeof(UnionSubclassMapping<>),
typeof(SubclassMapping<>)
};
var mapper = new ModelMapper();
foreach (var asm in assemblies)
{
foreach (var type in asm.GetTypes())
{
if (!type.IsClass || type.IsAbstract || type.IsInterface || !type.BaseType.IsGenericType) continue;
if (!baseTypes.Contains(type.BaseType.GetGenericTypeDefinition())) continue;
mapper.AddMapping(type);
}
}
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
mapping.autoimport = false;
return mapping;
}
示例2: CreateProxy
/// <inheritdoc />
public object CreateProxy (Type baseType, Type[] implementedInterfaces, object[] constructorArguments)
{
if (baseType.IsInterface) {
// TODO: should Moq.Core do this work? It's the same for
// Castle and LinFu and presumably other (future?) libraries
var fixedInterfaces = new Type[implementedInterfaces.Length + 1];
fixedInterfaces[0] = baseType;
implementedInterfaces.CopyTo (fixedInterfaces, 1);
implementedInterfaces = fixedInterfaces;
baseType = typeof (object);
}
if (!implementedInterfaces.Contains(typeof(IProxy))) {
var fixedInterfaces = new Type[implementedInterfaces.Length + 1];
fixedInterfaces[0] = typeof(IProxy);
implementedInterfaces.CopyTo (fixedInterfaces, 1);
implementedInterfaces = fixedInterfaces;
}
// TODO: the proxy factory should automatically detect requests to proxy
// delegates and generate an interface on the fly for them, without Moq
// having to know about it at all.
return generator.CreateClassProxy (baseType, implementedInterfaces, proxyOptions, constructorArguments, new Interceptor ());
}
示例3: AllEntitiesInheritEntityBase
public void AllEntitiesInheritEntityBase()
{
var failed = false;
var exclusions = new Type[] { };
foreach (var testType in TestTypes)
{
var types =
testType.Assembly.GetTypes().Where(t => t.Namespace.IfNullOrEmpty("").Contains(".Entities")).OrderBy(t => t.Name);
foreach (var type in types)
{
if (exclusions.Contains(type) || type.IsAbstract || type.IsSealed || type.IsEnum || type.Namespace.IfNullOrEmpty("").EndsWith("Entities.Components"))
continue;
if(typeof (EntityBase).IsAssignableFrom(type))
{
Debug.WriteLine("PASS | " + type.Name);
continue;
}
failed = true;
Debug.WriteLine("FAIL | " + type.Name);
}
}
Assert.IsFalse(failed);
}
示例4: OfType
/// <summary>
///
/// </summary>
/// <param name="attributes">The list of available attributes</param>
/// <param name="container">This is the type of container we are searchig attributes for.</param>
/// <returns>The attributes matching the <see cref="EdiStructureType"/></returns>
public static IEnumerable<EdiAttribute> OfType(this IEnumerable<EdiAttribute> attributes, EdiStructureType container) {
var typesToSearch = new Type[0];
switch (container) {
case EdiStructureType.None:
case EdiStructureType.Interchange:
break;
case EdiStructureType.Group:
typesToSearch = new [] { typeof(EdiGroupAttribute) };
break;
case EdiStructureType.Message:
typesToSearch = new [] { typeof(EdiMessageAttribute) };
break;
case EdiStructureType.SegmentGroup:
typesToSearch = new [] { typeof(EdiSegmentGroupAttribute) };
break;
case EdiStructureType.Segment:
typesToSearch = new [] { typeof(EdiSegmentAttribute), typeof(EdiSegmentGroupAttribute) };
break;
case EdiStructureType.Element:
typesToSearch = new [] { typeof(EdiElementAttribute) };
break;
default:
break;
}
return null == typesToSearch ? Enumerable.Empty<EdiAttribute>() : attributes.Where(a => typesToSearch.Contains(a.GetType()));
}
示例5: HasSupportFor
public bool HasSupportFor(Type[] scenarios)
{
if (IsTravis && scenarios.Contains(Type.Integration))
{
return false;
}
return true;
}
示例6: FindCommandTypeInMethodParameters
private static Type FindCommandTypeInMethodParameters(Type[] commandTypes, MethodInfo handlerMethod)
{
var commandParam =
handlerMethod.GetParameters().FirstOrDefault(p => commandTypes.Contains(p.ParameterType));
if (commandParam != null)
return commandParam.ParameterType;
return null;
}
示例7: IsBetterChoice
private bool IsBetterChoice(ConstructorInfo current, ConstructorInfo candidate, Type[] existingTypes)
{
if (current == null)
return true;
if (candidate.GetParameters()
.Where(x => !existingTypes.Contains(x.ParameterType))
.Any(x => x.ParameterType.IsSealed && !x.ParameterType.IsArray))
return false;
return current.GetParameters().Length < candidate.GetParameters().Length;
}
示例8: Search
/// <summary>
/// Search an IQueryable's fields for the keywords (objects) - this does not iterate through levels of an object
/// </summary>
/// <param name="list_to_search">IQueryable to search</param>
/// <param name="types_to_explore">array of types to search, others will be ignored</param>
/// <param name="keywords">objects to search for</param>
/// <returns>IQueryable of the inputed type filtered by the search specifications</returns>
public static IQueryable Search( this IQueryable list_to_search, Type[] types_to_explore, object[] keywords )
{
list_to_search.NotNull();
Dictionary<string, Type> dic = new Dictionary<string, Type>();
foreach( var item in list_to_search.Take( 1 ) )
{
foreach( PropertyInfo pi in item.GetType().GetProperties() )
{
if( types_to_explore.Contains( pi.PropertyType ) )
{
dic.Add( pi.Name, pi.PropertyType );
}
}
}
return list_to_search.Search( dic, keywords );
}
示例9: Contains
public static bool Contains(this Exception e, Type[] exceptionTypes)
{
bool result = false;
while (e != null)
{
if (exceptionTypes.Contains(e.GetType()))
{
result = true;
break;
}
e = e.InnerException;
}
return result;
}
示例10: AllEntitiesInitializeComponents
public void AllEntitiesInitializeComponents()
{
var failed = false;
var exclusions = new Type[] { };
foreach (var testType in TestTypes)
{
var types =
testType.Assembly.GetTypes().Where(t => t.Namespace.IfNullOrEmpty("").Contains(".Entities")).OrderBy(t => t.Name);
foreach (var type in types)
{
if (exclusions.Contains(type) || type.IsAbstract || type.IsSealed || type.IsEnum || type.Namespace.IfNullOrEmpty("").EndsWith("Entities.Components"))
continue;
if (typeof(EntityBase).IsAssignableFrom(type))
{
var components = type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(t => t.PropertyType.Namespace.EndsWith("Entities.Components"));
if (components.Any())
{
var obj = Activator.CreateInstance(type);
foreach (var list in components)
{
var val = list.GetValue(obj, null);
if (val == null)
{
Debug.WriteLine("FAIL | " + type.Name + "." + list.Name);
failed = true;
}
else
Debug.WriteLine("PASS | " + type.Name + "." + list.Name);
}
}
}
}
}
Assert.IsFalse(failed);
}
示例11: Run
/*
* output - a destination to write results out to. To write output
* to the standard output, pass in System.Console.Out
*/
public static void Run(TextWriter output, Result result)
{
Assert.Output = output;
Suite suite = new Suite();
Type[] entryAssemblyTypes = Assembly.GetEntryAssembly().GetTypes();
Type[] forbiddenTypes = new Type[] {
GetTypeFromAssemblyTypes(entryAssemblyTypes, "TestRunner")
, GetTypeFromAssemblyTypes(entryAssemblyTypes, "WasRunObj")
, GetTypeFromAssemblyTypes(entryAssemblyTypes, "WasRunSetUpFailed")
};
foreach (Type t in entryAssemblyTypes) {
if (t.IsSubclassOf(typeof(TDDUnit.Case))
&& !forbiddenTypes.Contains(t)) {
suite.Add(t);
}
}
foreach (string test in suite.FailedTests(result)) {
output.WriteLine("Failed: " + test);
}
output.WriteLine(result.Summary);
}
示例12: ValidateNoDanglingAttributes
public void ValidateNoDanglingAttributes()
{
// This list represents attributes that have been cleared to ship without deriving
// from ArgMetadata. This test is here to make sure that, by default, the attributes
// in this project behave like most of the others. That is, most attributes should
// derive from ArgMetadata.
var whitelist = new Type[]
{
typeof(ArgReviverAttribute),
};
var iArgMetadataSubInterfaces = typeof(Args).Assembly.GetTypes().Where(t =>
t.IsInterface &&
t.GetInterfaces().Contains(typeof(IArgMetadata))).ToList();
// In general, attributes in this project should derive from ArgMetadata
var danglingAttrs = typeof(Args).Assembly.GetTypes().Where(t =>
t.IsSubclassOf(typeof(Attribute)) == true &&
t.GetInterfaces().Contains(typeof(IArgMetadata)) == false &&
whitelist.Contains(t) == false
).ToList();
// In general, attibutes should use more specific IArgMetadata interfaces
var danglingAttrs2 = typeof(Args).Assembly.GetTypes().Where(t =>
t.GetInterfaces().Contains(typeof(Attribute)) == true &&
(from i in t.GetInterfaces() where iArgMetadataSubInterfaces.Contains(i) select i).Count() == 0 &&
whitelist.Contains(t) == false
).ToList();
Assert.AreEqual(0, danglingAttrs.Count);
Assert.AreEqual(0, danglingAttrs2.Count);
}
示例13: TryGetGenericType
private static bool TryGetGenericType(this Type type, Type[] acceptableTypes, out Type collectionOf)
{
if (!type.IsGenericType)
{
collectionOf = null;
return false;
}
var genericType = type.GetGenericTypeDefinition();
if (acceptableTypes.Contains(genericType))
{
collectionOf = type.GetGenericArguments()[0];
return true;
}
collectionOf = null;
return false;
}
示例14: ConvertToCode
/// <summary>
/// Returns code to instantiate an equivalent instance of the given value
/// </summary>
/// <param name="value">value to instantiate</param>
/// <returns>code to instantiate the value</returns>
private string ConvertToCode(object value)
{
Globalization.CultureInfo realCulture = Globalization.CultureInfo.CurrentCulture;
// null is easy
//
if (value == null)
return "null";
try
{
System.Threading.Thread.CurrentThread.CurrentCulture = Globalization.CultureInfo.InvariantCulture;
// switch based on the type
Type type = value.GetType();
Type[] simpleTypes = new Type[] { typeof(bool), typeof(int) };
Type[] castTypes = new Type[] { typeof(byte), typeof(short), typeof(ushort), typeof(sbyte) };
if (simpleTypes.Contains(type))
return value.ToString().ToLower();
else if (castTypes.Contains(type))
return "(" + type.FullName + ")(" + value.ToString() + ")";
else if (type == typeof(uint))
return value.ToString() + "U";
else if (type == typeof(long))
return value.ToString() + "L";
else if (type == typeof(ulong))
return value.ToString() + "UL";
else if (type == typeof(decimal))
return value.ToString() + "M";
else if (type == typeof(float))
{
if (float.IsNegativeInfinity((float)value))
return "float.NegativeInfinity";
if (float.IsPositiveInfinity((float)value))
return "float.PositiveInfinity";
if (float.IsNaN((float)value))
return "float.NaN";
if ((float)value == float.MaxValue)
return "float.MaxValue";
if ((float)value == float.MinValue)
return "float.MinValue";
return value.ToString() + "f";
}
else if (type == typeof(double))
{
if (double.IsNegativeInfinity((double)value))
return "double.NegativeInfinity";
if (double.IsPositiveInfinity((double)value))
return "double.PositiveInfinity";
if (double.IsNaN((double)value))
return "double.NaN";
if ((double)value == double.MaxValue)
return "double.MaxValue";
if ((double)value == double.MinValue)
return "double.MinValue";
return value.ToString() + "d";
}
else if (type == typeof(string))
return "\"" + value + "\"";
else if (type == typeof(byte[]))
return "new byte[] { " + string.Join(", ", (value as byte[]).Select(b => b.ToString()).ToArray()) + "}";
else if (type == typeof(Guid))
return "new Guid(\"" + value.ToString() + "\")";
else if (type == typeof(DateTime))
{
DateTime dt = (DateTime)value;
return "new DateTime(" + dt.Ticks + ", DateTimeKind." + dt.Kind.ToString() + ")";
}
else
{
// may need to add more cases in the future, for now this is sufficient
throw new NotSupportedException();
}
}
finally
{
System.Threading.Thread.CurrentThread.CurrentCulture = realCulture;
}
}
示例15: IsAuthorizedCall
/// <summary>
/// Validates that the required ISteamAuthenticator object is attached to the client prior to initiating execution
/// </summary>
/// <param name="validAuthMethods">List of valid authenticators for API access.</param>
/// <returns>Returns 'true' if the proper authenticator is attached. Throws <see cref="SteamAuthenticationException"/> otherwise.</returns>
internal bool IsAuthorizedCall( Type[] validAuthMethods )
{
if( Authenticator == null || !validAuthMethods.Contains( Authenticator.GetType() ) )
throw new SteamAuthenticationException( "API call has not been properly authenticated. Please ensure the proper ISteamAuthenticator object is added to the SteamClient (SteamClient.Authenticator)." );
return true;
}