本文整理汇总了C#中System.Type类的典型用法代码示例。如果您正苦于以下问题:C# Type类的具体用法?C# Type怎么用?C# Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于System命名空间,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanConvertTo
public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
{
if (context == null)
return false;
var p = context.GetService (typeof (IXamlNameProvider)) as IXamlNameProvider;
return p != null && destinationType == typeof (string);
}
示例2: ConvertTo
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (context == null)
return null;
var p = context.GetService (typeof (IXamlNameProvider)) as IXamlNameProvider;
return p != null ? p.GetName (value) : null;
}
示例3: Convert
public object Convert(object[] values,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
if (values == null ||
values.Length != 2)
{
return Visibility.Collapsed;
}
if (values[0] is IEnumerable<string>)
{
var a = (IEnumerable<string>)values[0];
var b = values[1];
if (a.Contains(b) == true)
{
return Visibility.Collapsed;
}
}
else if (values[0] is ItemCollection)
{
var a = (ItemCollection)values[0];
var b = values[1];
if (a.Contains(b) == true)
{
return Visibility.Collapsed;
}
}
return Visibility.Visible;
}
示例4: ConvertBack
public object[] ConvertBack(object value,
Type[] targetTypes,
object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
示例5: GetModule
private IEnumerable<PluginWrapper> GetModule(string pFileName, Type pTypeInterface)
{
var plugins = new List<PluginWrapper>();
try
{
var assembly = Assembly.LoadFrom(pFileName);
foreach(var type in assembly.GetTypes())
{
try
{
if(!type.IsPublic || type.IsAbstract)
continue;
var typeInterface = type.GetInterface(pTypeInterface.ToString(), true);
if(typeInterface == null)
continue;
var instance = Activator.CreateInstance(type) as IPlugin;
if(instance != null)
plugins.Add(new PluginWrapper(pFileName, instance));
}
catch(Exception ex)
{
Logger.WriteLine("Error Loading " + pFileName + ":\n" + ex, "PluginManager");
}
}
}
catch(Exception ex)
{
Logger.WriteLine("Error Loading " + pFileName + ":\n" + ex, "PluginManager");
}
return plugins;
}
示例6: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType != typeof(bool))
throw new InvalidOperationException("The target must be boolean.");
return !(bool)value;
}
示例7: ClassInfo
public ClassInfo(bool isAbstract, Type superClass, Db4objects.Db4o.Reflect.Self.FieldInfo
[] fieldInfo)
{
_isAbstract = isAbstract;
_superClass = superClass;
_fieldInfo = fieldInfo;
}
示例8: GetLoadableTypes
public IEnumerable<Type> GetLoadableTypes(Assembly assembly, Type ofBaseType)
{
var types = GetLoadableTypes(assembly);
return types != null
? types.Where(ofBaseType.IsAssignableFrom)
: null;
}
示例9: CreateInOutParamTypes
protected override Type[] CreateInOutParamTypes(Uiml.Param[] parameters, out Hashtable outputPlaceholder)
{
outputPlaceholder = null;
Type[] tparamTypes = new Type[parameters.Length];
int i=0;
try
{
for(i=0; i<parameters.Length; i++)
{
tparamTypes[i] = Type.GetType(parameters[i].Type);
int j = 0;
while(tparamTypes[i] == null)
tparamTypes[i] = ((Assembly)ExternalLibraries.Instance.Assemblies[j++]).GetType(parameters[i].Type);
//also prepare a placeholder when this is an output parameter
if(parameters[i].IsOut)
{
if(outputPlaceholder == null)
outputPlaceholder = new Hashtable();
outputPlaceholder.Add(parameters[i].Identifier, null);
}
}
return tparamTypes;
}
catch(ArgumentOutOfRangeException aore)
{
Console.WriteLine("Can not resolve type {0} of parameter {1} while calling method {2}",parameters[i].Type ,i , Call.Name);
Console.WriteLine("Trying to continue without executing {0}...", Call.Name);
throw aore;
}
}
示例10: TestRoute
public void TestRoute(string url, string verb, Type type, string actionName)
{
//Arrange
url = url.Replace("{apiVersionNumber}", this.ApiVersionNumber);
url = Host + url;
//Act
HttpRequestMessage request = new HttpRequestMessage(new HttpMethod(verb), url);
IHttpControllerSelector controller = this.GetControllerSelector();
IHttpActionSelector action = this.GetActionSelector();
IHttpRouteData route = this.Config.Routes.GetRouteData(request);
request.Properties[HttpPropertyKeys.HttpRouteDataKey] = route;
request.Properties[HttpPropertyKeys.HttpConfigurationKey] = this.Config;
HttpControllerDescriptor controllerDescriptor = controller.SelectController(request);
HttpControllerContext context = new HttpControllerContext(this.Config, route, request)
{
ControllerDescriptor = controllerDescriptor
};
var actionDescriptor = action.SelectAction(context);
//Assert
Assert.NotNull(controllerDescriptor);
Assert.NotNull(actionDescriptor);
Assert.Equal(type, controllerDescriptor.ControllerType);
Assert.Equal(actionName, actionDescriptor.ActionName);
}
示例11: InternalGetAjaxMethods
private static Dictionary<string, AsyncMethodInfo> InternalGetAjaxMethods(Type type)
{
var ret = new Dictionary<string, AsyncMethodInfo>();
var mis = CoreHelper.GetMethodsFromType(type);
foreach (MethodInfo mi in mis)
{
string methodName = mi.Name;
var method = CoreHelper.GetMemberAttribute<AjaxMethodAttribute>(mi);
if (method != null)
{
if (!string.IsNullOrEmpty(method.Name))
{
methodName = method.Name;
}
if (!ret.ContainsKey(methodName))
{
AsyncMethodInfo asyncMethod = new AsyncMethodInfo();
asyncMethod.Method = mi;
asyncMethod.Async = method.Async;
ret[methodName] = asyncMethod;
}
}
}
return ret;
}
示例12: DeleteById
public void DeleteById(Type type, string key, string value)
{
string sql = "delete from " + type.Name;
sql += " where " + key + "=" + value;
DBExtBase.ExeNonQueryBySqlText(this.dataCtx, sql);
}
示例13: Help
/// <summary>
/// Displays help for the specified command.
/// <param name="Command">Command type.</param>
/// </summary>
public static void Help(Type Command)
{
string Description;
List<string> Params;
GetTypeHelp(Command, out Description, out Params);
LogHelp(Command, Description, Params);
}
示例14: GetSchema
public override List<ExplorerItem> GetSchema(IConnectionInfo connectionInfo, Type customType)
{
var indexDirectory = connectionInfo.DriverData.FromXElement<LuceneDriverData>().IndexDirectory;
//TODO: Fields with configured delimiters should show up as a tree
//TODO: Show Numeric and String fields with their types
//TODO: If the directory selected contains sub-directories, maybe we should show them all...
using (var directory = FSDirectory.Open(new DirectoryInfo(indexDirectory)))
using (var indexReader = IndexReader.Open(directory, true))
{
return indexReader
.GetFieldNames(IndexReader.FieldOption.ALL)
.Select(fieldName =>
{
//var field = //TODO: Get the first document with this field and get its types.
return new ExplorerItem(fieldName, ExplorerItemKind.QueryableObject, ExplorerIcon.Column)
{
IsEnumerable = false, //TODO: Should be true when its a multi-field
ToolTipText = "Cool tip"
};
})
.ToList();
}
}
示例15: Deserialize
// public methods
/// <summary>
/// Deserializes an object from a BsonReader.
/// </summary>
/// <param name="bsonReader">The BsonReader.</param>
/// <param name="nominalType">The nominal type of the object.</param>
/// <param name="actualType">The actual type of the object.</param>
/// <param name="options">The serialization options.</param>
/// <returns>An object.</returns>
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
Type actualType,
IBsonSerializationOptions options)
{
VerifyTypes(nominalType, actualType, typeof(double));
var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Double:
return bsonReader.ReadDouble();
case BsonType.Int32:
return representationSerializationOptions.ToDouble(bsonReader.ReadInt32());
case BsonType.Int64:
return representationSerializationOptions.ToDouble(bsonReader.ReadInt64());
case BsonType.String:
return XmlConvert.ToDouble(bsonReader.ReadString());
default:
var message = string.Format("Cannot deserialize Double from BsonType {0}.", bsonType);
throw new FileFormatException(message);
}
}