本文整理汇总了C#中System.Type.Type类的典型用法代码示例。如果您正苦于以下问题:C# Type.Type类的具体用法?C# Type.Type怎么用?C# Type.Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Type.Type类属于System命名空间,在下文中一共展示了Type.Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FullTextFilters
public IList<FilterDef> FullTextFilters(Type type)
{
return AttributeUtil
.GetAttributes<FullTextFilterDefAttribute>(type, false)
.Select(CreateFilterDefinition)
.ToList();
}
示例2: DocumentMapping
public DocumentMapping(Type mappedClass) {
this.MappedClass = mappedClass;
this.ClassBridges = new List<ClassBridgeMapping>();
this.Fields = new List<FieldMapping>();
this.Embedded = new List<EmbeddedMapping>();
this.ContainedIn = new List<ContainedInMapping>();
this.FullTextFilterDefinitions = new List<FilterDef>();
}
示例3: ObjectSubclassInfo
public ObjectSubclassInfo(Type type, ConstructorInfo constructor) {
TypeInfo = type.GetTypeInfo();
ClassName = GetClassName(TypeInfo);
Constructor = constructor;
PropertyMappings = type.GetProperties()
.Select(prop => Tuple.Create(prop, prop.GetCustomAttribute<ParseFieldNameAttribute>(true)))
.Where(t => t.Item2 != null)
.Select(t => Tuple.Create(t.Item1, t.Item2.FieldName))
.ToDictionary(t => t.Item1.Name, t => t.Item2);
}
示例4: IsTypeValid
public bool IsTypeValid(String className, Type type) {
ObjectSubclassInfo subclassInfo = null;
mutex.EnterReadLock();
registeredSubclasses.TryGetValue(className, out subclassInfo);
mutex.ExitReadLock();
return subclassInfo == null
? type == typeof(ParseObject)
: subclassInfo.TypeInfo == type.GetTypeInfo();
}
示例5: EntityPropertyMappingInfo
public EntityPropertyMappingInfo(EntityPropertyMappingAttribute attribute, Type definingType, ClientType actualPropertyType)
{
Debug.Assert(attribute != null, "attribute != null");
Debug.Assert(definingType != null, "definingType != null");
Debug.Assert(actualPropertyType != null, "actualPropertyType != null");
this.attribute = attribute;
this.definingType = definingType;
this.actualPropertyType = actualPropertyType;
Debug.Assert(!string.IsNullOrEmpty(attribute.SourcePath), "Invalid source path");
this.segmentedSourcePath = attribute.SourcePath.Split('/');
}
示例6: RegisterSubclass
public void RegisterSubclass(Type type) {
TypeInfo typeInfo = type.GetTypeInfo();
if (!typeInfo.IsSubclassOf(typeof(ParseObject))) {
throw new ArgumentException("Cannot register a type that is not a subclass of ParseObject");
}
String className = ObjectSubclassInfo.GetClassName(typeInfo);
try {
// Perform this as a single independent transaction, so we can never get into an
// intermediate state where we *theoretically* register the wrong class due to a
// TOCTTOU bug.
mutex.EnterWriteLock();
ObjectSubclassInfo previousInfo = null;
if (registeredSubclasses.TryGetValue(className, out previousInfo)) {
if (typeInfo.IsAssignableFrom(previousInfo.TypeInfo)) {
// Previous subclass is more specific or equal to the current type, do nothing.
return;
} else if (previousInfo.TypeInfo.IsAssignableFrom(typeInfo)) {
// Previous subclass is parent of new child, fallthrough and actually register
// this class.
/* Do nothing */
} else {
throw new ArgumentException(
"Tried to register both " + previousInfo.TypeInfo.FullName + " and " + typeInfo.FullName +
" as the ParseObject subclass of " + className + ". Cannot determine the right class " +
"to use because neither inherits from the other."
);
}
}
ConstructorInfo constructor = type.FindConstructor();
if (constructor == null) {
throw new ArgumentException("Cannot register a type that does not implement the default constructor!");
}
registeredSubclasses[className] = new ObjectSubclassInfo(type, constructor);
} finally {
mutex.ExitWriteLock();
}
Action toPerform = null;
if (registerActions.TryGetValue(className, out toPerform)) {
toPerform();
}
}
示例7: InstantiateObject
internal Object InstantiateObject(Type objectType)
{
/*if (TCU.GetTypeInfo(objectType).IsInterface || TCU.GetTypeInfo(objectType).IsAbstract || TCU.GetTypeInfo(objectType).IsValueType)
{
throw new JsonTypeCoercionException(
String.Format(TypeCoercionUtility.ErrorCannotInstantiate, new System.Object[] {objectType.FullName}));
}
ConstructorInfo ctor = objectType.GetConstructor(Type.EmptyTypes);
if (ConstructorInfo.Equals (ctor, null)) {
throw new JsonTypeCoercionException (
String.Format (TypeCoercionUtility.ErrorDefaultCtor, new System.Object[] { objectType.FullName }));
}
Object result;
try
{
// always try-catch Invoke() to expose real exception
result = ctor.Invoke(null);
}
catch (TargetInvocationException ex)
{
if (ex.InnerException != null)
{
throw new JsonTypeCoercionException(ex.InnerException.Message, ex.InnerException);
}
throw new JsonTypeCoercionException("Error instantiating " + objectType.FullName, ex);
}*/
return System.Activator.CreateInstance (objectType);
//return result;
}
示例8: ClassBridges
public IList<IClassBridgeDefinition> ClassBridges(Type type)
{
return AttributeUtil.GetAttributes<ClassBridgeAttribute>(type);
}
示例9: Indexed
public IIndexedDefinition Indexed(Type type)
{
return AttributeUtil.GetAttribute<IndexedAttribute>(type);
}
示例10: WriteJson
public abstract Dictionary<string,object> WriteJson (Type type, object value);
示例11: Write
public void Write (JsonWriter writer, Type type, object value) {
Dictionary<string,object> dict = WriteJson (type,value);
writer.Write (dict);
}
示例12: GetConverter
/** Returns the converter for the specified type */
public virtual JsonConverter GetConverter (Type type) {
for (int i=0;i<converters.Count;i++)
if (converters[i].CanConvert (type))
return converters[i];
return null;
}
示例13: CoerceType
internal object CoerceType(Type targetType, object value)
{
bool isNullable = TypeCoercionUtility.IsNullable(targetType);
if (value == null)
{
if (!allowNullValueTypes &&
TypeCoercionUtility.GetTypeInfo(targetType).IsValueType &&
!isNullable)
{
throw new JsonTypeCoercionException(String.Format(TypeCoercionUtility.ErrorNullValueType, new System.Object[] {targetType.FullName}));
}
return value;
}
if (isNullable)
{
// nullable types have a real underlying struct
Type[] genericArgs = targetType.GetGenericArguments();
if (genericArgs.Length == 1)
{
targetType = genericArgs[0];
}
}
Type actualType = value.GetType();
if (TypeCoercionUtility.GetTypeInfo(targetType).IsAssignableFrom(TypeCoercionUtility.GetTypeInfo(actualType)))
{
return value;
}
if (TypeCoercionUtility.GetTypeInfo(targetType).IsEnum)
{
if (value is String)
{
if (!Enum.IsDefined(targetType, value))
{
// if isn't a defined value perhaps it is the JsonName
foreach (FieldInfo field in TypeCoercionUtility.GetTypeInfo(targetType).GetFields())
{
string jsonName = JsonNameAttribute.GetJsonName(field);
if (((string)value).Equals(jsonName))
{
value = field.Name;
break;
}
}
}
return Enum.Parse(targetType, (string)value);
}
else
{
value = this.CoerceType(Enum.GetUnderlyingType(targetType), value);
return Enum.ToObject(targetType, value);
}
}
if (value is IDictionary)
{
Dictionary<string, MemberInfo> memberMap;
return this.CoerceType(targetType, (IDictionary)value, out memberMap);
}
if (TypeCoercionUtility.GetTypeInfo(typeof(IEnumerable)).IsAssignableFrom(TypeCoercionUtility.GetTypeInfo(targetType)) &&
TypeCoercionUtility.GetTypeInfo(typeof(IEnumerable)).IsAssignableFrom(TypeCoercionUtility.GetTypeInfo(actualType)))
{
return this.CoerceList(targetType, actualType, (IEnumerable)value);
}
if (value is String)
{
if (Type.Equals (targetType, typeof(DateTime))) {
DateTime date;
if (DateTime.TryParse(
(string)value,
DateTimeFormatInfo.InvariantInfo,
DateTimeStyles.RoundtripKind | DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.NoCurrentDateDefault,
out date)) {
return date;
}
} else if (Type.Equals (targetType, typeof(Guid))) {
// try-catch is pointless since will throw upon generic conversion
return new Guid((string)value);
} else if (Type.Equals (targetType, typeof(Char))) {
if (((string)value).Length == 1) {
return ((string)value)[0];
}
} else if (Equals (targetType, typeof(Uri))) {
Uri uri;
if (Uri.TryCreate ((string)value, UriKind.RelativeOrAbsolute, out uri)) {
return uri;
}
} else if (Type.Equals (targetType, typeof(Version))) {
// try-catch is pointless since will throw upon generic conversion
return new Version ((string)value);
}
}
else if (Type.Equals (targetType, typeof(TimeSpan))) {
return new TimeSpan ((long)this.CoerceType (typeof(Int64), value));
}
//.........这里部分代码省略.........
示例14: SetMemberValue
/// <summary>
/// Helper method to set value of either property or field
/// </summary>
/// <param name="result"></param>
/// <param name="memberType"></param>
/// <param name="memberInfo"></param>
/// <param name="value"></param>
internal void SetMemberValue(Object result, Type memberType, MemberInfo memberInfo, object value)
{
try
{
if (memberInfo is PropertyInfo)
{
// set value of public property
((PropertyInfo) memberInfo).SetValue(
result,
this.CoerceType(memberType, value),
null);
}
else if (memberInfo is FieldInfo)
{
// set value of public field
((FieldInfo) memberInfo).SetValue(
result,
this.CoerceType(memberType, value));
}
}
catch (Exception e)
{
throw;
}
// all other values are ignored
}
示例15: CreateMemberMap
/** Creates a member map for the type */
private Dictionary<string, MemberInfo> CreateMemberMap(Type objectType)
{
Dictionary<string, MemberInfo> memberMap;
if (this.MemberMapCache.TryGetValue(objectType, out memberMap))
{
// map was stored in cache
return memberMap;
}
// create a new map
memberMap = new Dictionary<string, MemberInfo>();
// load properties into property map
Type tp = objectType;
while (tp != null) {
PropertyInfo[] properties = TypeCoercionUtility.GetTypeInfo(tp).GetProperties( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance );
for ( int i = 0 ; i < properties.Length; i++ )
{
PropertyInfo info = properties [i];
if (!info.CanRead || !info.CanWrite) {
continue;
}
if (JsonIgnoreAttribute.IsJsonIgnore (info)) {
continue;
}
string jsonName = JsonNameAttribute.GetJsonName (info);
if (String.IsNullOrEmpty (jsonName)) {
memberMap[info.Name] = info;
} else {
memberMap[jsonName] = info;
}
}
// load public fields into property map
FieldInfo[] fields = TypeCoercionUtility.GetTypeInfo(tp).GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance );
foreach (FieldInfo info in fields)
{
if (!info.IsPublic &&
#if WINDOWS_STORE
info.GetCustomAttribute<JsonMemberAttribute>(false) == null
#else
info.GetCustomAttributes(typeof(JsonMemberAttribute), false).Length == 0
#endif
) {
continue;
}
if (JsonIgnoreAttribute.IsJsonIgnore (info)) {
continue;
}
string jsonName = JsonNameAttribute.GetJsonName (info);
if (String.IsNullOrEmpty (jsonName)) {
memberMap[info.Name] = info;
} else {
memberMap[jsonName] = info;
}
}
tp = tp.BaseType;
}
// store in cache for repeated usage
this.MemberMapCache[objectType] = memberMap;
return memberMap;
}