本文整理汇总了C#中System.Type.Type类的典型用法代码示例。如果您正苦于以下问题:C# Type.Type类的具体用法?C# Type.Type怎么用?C# Type.Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Type.Type类属于System命名空间,在下文中一共展示了Type.Type类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: FullTextFilters
public IList<FilterDef> FullTextFilters(Type type)
{
return AttributeUtil
.GetAttributes<FullTextFilterDefAttribute>(type, false)
.Select(CreateFilterDefinition)
.ToList();
}
开发者ID:vcaraulean,项目名称:NHibernate.Search,代码行数:7,代码来源:AttributedMappingDefinition.cs
示例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>();
}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:9,代码来源:DocumentMapping.cs
示例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);
}
开发者ID:Julien-Mialon,项目名称:Parse.UWP.Sample,代码行数:10,代码来源:ObjectSubclassInfo.cs
示例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();
}
开发者ID:mehul9595,项目名称:Parse-SDK-dotNET,代码行数:11,代码来源:ObjectSubclassingController.cs
示例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('/');
}
开发者ID:junleqian,项目名称:Mobile-Restaurant,代码行数:13,代码来源:EntityPropertyMappingInfo.cs
示例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();
}
}
开发者ID:mehul9595,项目名称:Parse-SDK-dotNET,代码行数:47,代码来源:ObjectSubclassingController.cs
示例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;
}
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:30,代码来源:TypeCoercionUtility.cs
示例8: ClassBridges
public IList<IClassBridgeDefinition> ClassBridges(Type type)
{
return AttributeUtil.GetAttributes<ClassBridgeAttribute>(type);
}
开发者ID:vcaraulean,项目名称:NHibernate.Search,代码行数:4,代码来源:AttributedMappingDefinition.cs
示例9: Indexed
public IIndexedDefinition Indexed(Type type)
{
return AttributeUtil.GetAttribute<IndexedAttribute>(type);
}
开发者ID:vcaraulean,项目名称:NHibernate.Search,代码行数:4,代码来源:AttributedMappingDefinition.cs
示例10: WriteJson
public abstract Dictionary<string,object> WriteJson (Type type, object value);
开发者ID:KyleMassacre,项目名称:PlanetServer,代码行数:1,代码来源:JsonWriterSettings.cs
示例11: Write
public void Write (JsonWriter writer, Type type, object value) {
Dictionary<string,object> dict = WriteJson (type,value);
writer.Write (dict);
}
开发者ID:KyleMassacre,项目名称:PlanetServer,代码行数:4,代码来源:JsonWriterSettings.cs
示例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;
}
开发者ID:KyleMassacre,项目名称:PlanetServer,代码行数:8,代码来源:JsonWriterSettings.cs
示例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));
}
//.........这里部分代码省略.........
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:101,代码来源:TypeCoercionUtility.cs
示例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
}
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:34,代码来源:TypeCoercionUtility.cs
示例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;
}
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:72,代码来源:TypeCoercionUtility.cs
示例16: GetMemberMap
/** Returns a member map if suitable for the object type.
* Dictionary types will make this method return null
*/
public Dictionary<string, MemberInfo> GetMemberMap (Type objectType) {
// don't incurr the cost of member map for dictionaries
if (TypeCoercionUtility.GetTypeInfo(typeof(IDictionary)).IsAssignableFrom(TypeCoercionUtility.GetTypeInfo(objectType)))
{
return null;
}
else
{
return this.CreateMemberMap(objectType);
}
}
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:14,代码来源:TypeCoercionUtility.cs
示例17: GetMemberWritingMap
public void GetMemberWritingMap (Type objectType, JsonWriterSettings settings, out KeyValuePair<string,FieldInfo>[] outFields, out KeyValuePair<string,PropertyInfo>[] outProps) {
if ( writingMaps == null ) {
writingMaps = new Dictionary<Type,KeyValuePair< KeyValuePair<string,FieldInfo>[] , KeyValuePair<string,PropertyInfo>[] >> ();
}
KeyValuePair< KeyValuePair<string,FieldInfo>[] , KeyValuePair<string,PropertyInfo>[]> pair;
if (writingMaps.TryGetValue (objectType, out pair)) {
outFields = pair.Key;
outProps = pair.Value;
return;
}
bool anonymousType = objectType.IsGenericType && objectType.Name.StartsWith(JsonWriter.AnonymousTypePrefix);
Type tp = objectType;
if (fieldList == null)
fieldList = new List<KeyValuePair<string, FieldInfo>> ();
if (propList == null)
propList = new List<KeyValuePair<string, PropertyInfo>> ();
fieldList.Clear ();
propList.Clear ();
while (tp != null) {
FieldInfo[] fields = tp.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
for (int j = 0; j < fields.Length; j++ )
{
FieldInfo field = fields[j];
if (field.IsStatic || (!field.IsPublic && field.GetCustomAttributes (typeof(JsonMemberAttribute), true).Length == 0)) {
//if (Settings.DebugMode)
// Console.WriteLine ("Cannot serialize " + field.Name + " : not public or is static (and does not have a JsonMember attribute)");
continue;
}
if (settings.IsIgnored (objectType, field, null)) {
//if (Settings.DebugMode)
// Console.WriteLine ("Cannot serialize " + field.Name + " : ignored by settings");
continue;
}
// use Attributes here to control naming
string fieldName = JsonNameAttribute.GetJsonName (field);
if (String.IsNullOrEmpty (fieldName))
fieldName = field.Name;
fieldList.Add (new KeyValuePair<string, FieldInfo> (fieldName, field));
}
PropertyInfo[] properties = tp.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
for (int j = 0; j < properties.Length; j++ )
{
PropertyInfo property = properties[j];
//Console.WriteLine (property.Name);
if (!property.CanRead) {
//if (Settings.DebugMode)
// Console.WriteLine ("Cannot serialize "+property.Name+" : cannot read");
continue;
}
if (!property.CanWrite && !anonymousType) {
//if (Settings.DebugMode)
// Console.WriteLine ("Cannot serialize "+property.Name+" : cannot write");
continue;
}
if (settings.IsIgnored(objectType, property, null)) {
//if (Settings.DebugMode)
// Console.WriteLine ("Cannot serialize "+property.Name+" : is ignored by settings");
continue;
}
if (property.GetIndexParameters ().Length != 0) {
//if (Settings.DebugMode)
// Console.WriteLine ("Cannot serialize "+property.Name+" : is indexed");
continue;
}
// use Attributes here to control naming
string propertyName = JsonNameAttribute.GetJsonName(property);
if (String.IsNullOrEmpty(propertyName))
propertyName = property.Name;
propList.Add ( new KeyValuePair<string, PropertyInfo>(propertyName, property));
}
tp = tp.BaseType;
}
outFields = fieldList.ToArray();
outProps = propList.ToArray();
pair = new KeyValuePair< KeyValuePair<string,FieldInfo>[] , KeyValuePair<string,PropertyInfo>[]> ( outFields, outProps );
//.........这里部分代码省略.........
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:101,代码来源:TypeCoercionUtility.cs
示例18: UnregisterSubclass
public void UnregisterSubclass(Type type) {
mutex.EnterWriteLock();
registeredSubclasses.Remove(GetClassName(type));
mutex.ExitWriteLock();
}
开发者ID:mehul9595,项目名称:Parse-SDK-dotNET,代码行数:5,代码来源:ObjectSubclassingController.cs
示例19: CanConvert
/** Test if this converter can convert the specified type */
public abstract bool CanConvert (Type t);
开发者ID:KyleMassacre,项目名称:PlanetServer,代码行数:2,代码来源:JsonWriterSettings.cs
示例20: CoerceList
private object CoerceList(Type targetType, Type arrayType, IEnumerable value)
{
if (targetType.IsArray)
{
return this.CoerceArray(targetType.GetElementType(), value);
}
// targetType serializes as a JSON array but is not an array
// assume is an ICollection / IEnumerable with AddRange, Add,
// or custom Constructor with which we can populate it
// many ICollection types take an IEnumerable or ICollection
// as a constructor argument. look through constructors for
// a compatible match.
ConstructorInfo[] ctors = targetType.GetConstructors();
ConstructorInfo defaultCtor = null;
foreach (ConstructorInfo ctor in ctors)
{
ParameterInfo[] paramList = ctor.GetParameters();
if (paramList.Length == 0)
{
// save for in case cannot find closer match
defaultCtor = ctor;
continue;
}
if (paramList.Length == 1 &&
TypeCoercionUtility.GetTypeInfo(paramList[0].ParameterType).IsAssignableFrom(TypeCoercionUtility.GetTypeInfo(arrayType)))
{
try
{
// invoke first constructor that can take this value as an argument
return ctor.Invoke(
new object[] { value }
);
}
catch
{
// there might exist a better match
continue;
}
}
}
if (ConstructorInfo.Equals (defaultCtor, null)) {
throw new JsonTypeCoercionException (
String.Format (TypeCoercionUtility.ErrorDefaultCtor, new System.Object[] { targetType.FullName }));
}
object collection;
try
{
// always try-catch Invoke() to expose real exception
collection = defaultCtor.Invoke(null);
}
catch (TargetInvocationException ex)
{
if (ex.InnerException != null)
{
throw new JsonTypeCoercionException(ex.InnerException.Message, ex.InnerException);
}
throw new JsonTypeCoercionException("Error instantiating " + targetType.FullName, ex);
}
// many ICollection types have an AddRange method
// which adds all items at once
#if WINDOWS_STORE
/** \todo Not sure if this finds the correct methods */
MethodInfo method = TCU.GetTypeInfo(targetType).GetDeclaredMethod("AddRange");
#else
MethodInfo method = TypeCoercionUtility.GetTypeInfo(targetType).GetMethod("AddRange");
#endif
ParameterInfo[] parameters = (MethodInfo.Equals (method, null)) ?
null : method.GetParameters();
Type paramType = (parameters == null || parameters.Length != 1) ?
null : parameters[0].ParameterType;
if (!Type.Equals (paramType, null) &&
TypeCoercionUtility.GetTypeInfo(paramType).IsAssignableFrom (TypeCoercionUtility.GetTypeInfo(arrayType)))
{
try
{
// always try-catch Invoke() to expose real exception
// add all members in one method
method.Invoke(
collection,
new object[] { value });
}
catch (TargetInvocationException ex)
{
if (ex.InnerException != null)
{
throw new JsonTypeCoercionException(ex.InnerException.Message, ex.InnerException);
}
throw new JsonTypeCoercionException("Error calling AddRange on " + targetType.FullName, ex);
}
return collection;
}
else
{
// many ICollection types have an Add method
//.........这里部分代码省略.........
开发者ID:dorofiykolya,项目名称:csharp-bjson,代码行数:101,代码来源:TypeCoercionUtility.cs
注:本文中的System.Type.Type类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论