本文整理汇总了C#中Type类的典型用法代码示例。如果您正苦于以下问题:C# Type类的具体用法?C# Type怎么用?C# Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于命名空间,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToCode
internal static InternalPrimitiveTypeE ToCode(Type type) =>
type == null ? ToPrimitiveTypeEnum(TypeCode.Empty) :
type.GetTypeInfo().IsPrimitive ? ToPrimitiveTypeEnum(type.GetTypeCode()) :
ReferenceEquals(type, s_typeofDateTime) ? InternalPrimitiveTypeE.DateTime :
ReferenceEquals(type, s_typeofTimeSpan) ? InternalPrimitiveTypeE.TimeSpan :
ReferenceEquals(type, s_typeofDecimal) ? InternalPrimitiveTypeE.Decimal :
InternalPrimitiveTypeE.Invalid;
示例2: GetSmartPartInfo
/// <summary>
/// Gets the smart part info.
/// </summary>
/// <param name="smartPartInfoType">Type of the smart part info.</param>
/// <returns></returns>
public override ISmartPartInfo GetSmartPartInfo(Type smartPartInfoType)
{
ToolsSmartPartInfo tinfo = new ToolsSmartPartInfo();
if (BindingSource != null)
{
if (BindingSource.Current != null)
{
tinfo.Title = _stage.Id != null
? (_mode == "Complete"
? GetLocalResourceObject("DialogTitleComplete").ToString()
: GetLocalResourceObject("DialogTitleEdit").ToString())
: GetLocalResourceObject("DialogTitleAdd").ToString();
}
}
foreach (Control c in Form_LTools.Controls)
{
tinfo.LeftTools.Add(c);
}
foreach (Control c in Form_CTools.Controls)
{
tinfo.CenterTools.Add(c);
}
foreach (Control c in Form_RTools.Controls)
{
tinfo.RightTools.Add(c);
}
return tinfo;
}
示例3: VarEnumSelector
internal VarEnumSelector(Type[] explicitArgTypes) {
_variantBuilders = new VariantBuilder[explicitArgTypes.Length];
for (int i = 0; i < explicitArgTypes.Length; i++) {
_variantBuilders[i] = GetVariantBuilder(explicitArgTypes[i]);
}
}
示例4: ConvertTo
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
if (destinationType == typeof(string)) {
return "EmbeddedMailObject";
}
return base.ConvertTo(context, culture, value, destinationType);
}
示例5: CoordinatorScratchpad
internal CoordinatorScratchpad(Type elementType)
{
_elementType = elementType;
_nestedCoordinatorScratchpads = new List<CoordinatorScratchpad>();
_expressionWithErrorHandlingMap = new Dictionary<Expression, Expression>();
_inlineDelegates = new HashSet<LambdaExpression>();
}
示例6: TryGetType
/// <summary>
/// Given a clrType attempt to return the corresponding target type from
/// the worksapce
/// </summary>
/// <param name="clrType"> The clr type to resolve </param>
/// <param name="outTypeUsage"> an out param for the typeUsage to be resolved to </param>
/// <returns> true if a TypeUsage can be found for the target type </returns>
internal bool TryGetType(Type clrType, out TypeUsage outTypeUsage)
{
return TryGetTypeByName(
clrType.FullNameWithNesting(),
false /*ignoreCase*/,
out outTypeUsage);
}
示例7: CodeTypeReference
public CodeTypeReference (Type baseType)
{
#if NET_2_0
if (baseType == null) {
throw new ArgumentNullException ("baseType");
}
if (baseType.IsGenericParameter) {
this.baseType = baseType.Name;
this.referenceOptions = CodeTypeReferenceOptions.GenericTypeParameter;
}
else if (baseType.IsGenericTypeDefinition)
this.baseType = baseType.FullName;
else if (baseType.IsGenericType) {
this.baseType = baseType.GetGenericTypeDefinition ().FullName;
foreach (Type arg in baseType.GetGenericArguments ()) {
if (arg.IsGenericParameter)
TypeArguments.Add (new CodeTypeReference (new CodeTypeParameter (arg.Name)));
else
TypeArguments.Add (new CodeTypeReference (arg));
}
}
else
#endif
if (baseType.IsArray) {
this.arrayRank = baseType.GetArrayRank ();
this.arrayElementType = new CodeTypeReference (baseType.GetElementType ());
this.baseType = arrayElementType.BaseType;
} else {
Parse (baseType.FullName);
}
this.isInterface = baseType.IsInterface;
}
示例8: ComMethodInformation
internal ComMethodInformation(bool hasvarargs, bool hasoptional, ParameterInformation[] arguments, Type returnType, int dispId, COM.INVOKEKIND invokekind)
: base(hasvarargs, hasoptional, arguments)
{
this.ReturnType = returnType;
this.DispId = dispId;
this.InvokeKind = invokekind;
}
示例9: GetNullableType
internal static Type GetNullableType(Type type) {
Debug.Assert(type != null, "type cannot be null");
if (type.IsValueType && !IsNullableType(type)) {
return typeof(Nullable<>).MakeGenericType(type);
}
return type;
}
示例10: Element
// snippet moved from FileIOPermission (nickd) to be reused in all derived classes
internal static SecurityElement Element (Type type, int version)
{
SecurityElement se = new SecurityElement ("IPermission");
se.AddAttribute ("class", type.FullName + ", " + type.Assembly.ToString ().Replace ('\"', '\''));
se.AddAttribute ("version", version.ToString ());
return se;
}
示例11: GetSerializableFields
private static FieldInfo[] GetSerializableFields(Type type)
{
if (type.GetTypeInfo().IsInterface)
{
return Array.Empty<FieldInfo>();
}
if (!type.GetTypeInfo().IsSerializable)
{
throw new SerializationException(SR.Format(SR.Serialization_NonSerType, type.GetTypeInfo().FullName, type.GetTypeInfo().Assembly.FullName));
}
var results = new List<FieldInfo>();
for (Type t = type; t != typeof(object); t = t.GetTypeInfo().BaseType)
{
foreach (FieldInfo field in t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
{
if ((field.Attributes & FieldAttributes.NotSerialized) != FieldAttributes.NotSerialized)
{
results.Add(field);
}
}
}
return results.ToArray();
}
示例12: Main
static void Main(string[] args)
{
AssemblyName an = new AssemblyName();
an.Name = "HelloWorld";
AssemblyBuilder ab = Thread.GetDomain().DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave);
ModuleBuilder module = ab.DefineDynamicModule("b.dll");
TypeBuilder tb = module.DefineType("type", TypeAttributes.Public | TypeAttributes.Class);
MethodBuilder mb = tb.DefineMethod("test",
MethodAttributes.HideBySig | MethodAttributes.Static |
MethodAttributes.Public, typeof(void), null);
ILGenerator ig = mb.GetILGenerator();
//
// This is the actual test:
// Generate a method signature that contains modopts and modreqs
// and call that. It has no name or anything, not sure how this
// is actually used, but we at least generate the stuff
//
SignatureHelper sh = SignatureHelper.GetMethodSigHelper (module, CallingConventions.HasThis, typeof(int));
sh.AddArgument (typeof (bool));
Type [] req = new Type [] { typeof (System.Runtime.CompilerServices.IsBoxed) };
sh.AddArgument (typeof (string), req, null);
Type [] opt = new Type [] { typeof (System.Runtime.CompilerServices.IsConst) };
sh.AddArgument (typeof (byte), null, opt);
sh.AddArgument (typeof (int), null, opt);
sh.AddArgument (typeof (long), null, opt);
ig.Emit (OpCodes.Call, sh);
ig.Emit(OpCodes.Ret);
tb.CreateType();
ab.Save ("b.dll");
}
示例13: IsValid
private static bool IsValid(Type type, TypeInfo typeInfo)
{
if (!ReferenceEquals(null, type))
{
if (typeInfo.IsArray)
{
type = type.GetElementType();
}
if (typeInfo.IsAnonymousType || type.IsAnonymousType())
{
var properties = type.GetProperties().Select(x => x.Name).ToList();
var propertyNames = typeInfo.Properties.Select(x => x.Name).ToList();
var match =
type.IsAnonymousType() &&
typeInfo.IsAnonymousType &&
properties.Count == propertyNames.Count &&
propertyNames.All(x => properties.Contains(x));
if (!match)
{
return false;
}
}
return true;
}
return false;
}
示例14: CreateShelfService
public CreateShelfService(string serviceName, ShelfType shelfType, Type bootstrapperType, AssemblyName[] assemblyNames)
{
ServiceName = serviceName;
ShelfType = shelfType;
BootstrapperType = bootstrapperType;
AssemblyNames = assemblyNames;
}
示例15: CanConvertFrom
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return true;
return base.CanConvertFrom(context, sourceType);
}