本文整理汇总了C#中DataType.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DataType.GetType方法的具体用法?C# DataType.GetType怎么用?C# DataType.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataType
的用法示例。
在下文中一共展示了DataType.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDataTypeConstructorCode
/// <summary>
/// Generate code to re-construct the specified <see cref="DataType"/> with minimal specification
/// </summary>
/// <param name="dataType">Type to be re-constructed</param>
/// <returns>Code that will perform construction of the type</returns>
public string GetDataTypeConstructorCode(DataType dataType)
{
// Code generation is currently convention based and the only works for primitive types
if (!(dataType is PrimitiveDataType))
{
throw new TaupoNotSupportedException("Only primitive types are supported at this stage.");
}
string code = string.Format(
CultureInfo.InvariantCulture,
"DataTypes.{0}",
dataType.GetType().Name.Replace("DataType", string.Empty));
if (dataType.IsNullable)
{
code = string.Concat(code, ".Nullable(true)");
}
return code;
}
示例2: ResolveEntityModelSchemaType
/// <summary>
/// Resolves the specified entity model schema type and returns the Edm model type for it.
/// </summary>
/// <param name="model">The model to get the type from.</param>
/// <param name="schemaType">The entity model schema type to resolve.</param>
/// <returns>The resolved type for the specified <paramref name="schemaType"/>.</returns>
public static IEdmTypeReference ResolveEntityModelSchemaType(IEdmModel model, DataType schemaType)
{
if (schemaType == null)
{
return null;
}
PrimitiveDataType primitiveDataType = schemaType as PrimitiveDataType;
if (primitiveDataType != null)
{
return GetPrimitiveTypeReference(primitiveDataType);
}
if (model == null)
{
return null;
}
EntityDataType entityDataType = schemaType as EntityDataType;
if (entityDataType != null)
{
IEdmNamedElement edmType = model.FindType(entityDataType.Definition.FullName);
ExceptionUtilities.Assert(
edmType != null,
"The expected entity type '{0}' was not found in the entity model for this test.",
entityDataType.Definition.FullName);
IEdmEntityType entityType = edmType as IEdmEntityType;
ExceptionUtilities.Assert(
entityType != null,
"The expected entity type '{0}' is not defined as entity type in the test's metadata.",
entityDataType.Definition.FullName);
return entityType.ToTypeReference();
}
ComplexDataType complexDataType = schemaType as ComplexDataType;
if (complexDataType != null)
{
return GetComplexType(model, complexDataType);
}
CollectionDataType collectionDataType = schemaType as CollectionDataType;
if (collectionDataType != null)
{
DataType collectionElementType = collectionDataType.ElementDataType;
PrimitiveDataType primitiveElementType = collectionElementType as PrimitiveDataType;
if (primitiveElementType != null)
{
IEdmPrimitiveTypeReference primitiveElementTypeReference = GetPrimitiveTypeReference(primitiveElementType);
return primitiveElementTypeReference.ToCollectionTypeReference();
}
ComplexDataType complexElementType = collectionElementType as ComplexDataType;
if (complexElementType != null)
{
IEdmComplexTypeReference complexElementTypeReference = GetComplexType(model, complexElementType);
return complexElementTypeReference.ToCollectionTypeReference();
}
EntityDataType entityElementType = collectionElementType as EntityDataType;
if (entityElementType != null)
{
IEdmEntityTypeReference entityElementTypeReference = GetEntityType(model, entityElementType);
return entityElementTypeReference.ToCollectionTypeReference();
}
throw new NotSupportedException("Collection types only support primitive, complex, and entity element types.");
}
StreamDataType streamType = schemaType as StreamDataType;
if (streamType != null)
{
Type systemType = streamType.GetFacet<PrimitiveClrTypeFacet>().Value;
ExceptionUtilities.Assert(systemType == typeof(Stream), "Expected the system type 'System.IO.Stream' for a stream reference property.");
return MetadataUtils.GetPrimitiveTypeReference(systemType);
}
throw new NotImplementedException("Unrecognized schema type " + schemaType.GetType().Name + ".");
}
示例3: SerializeTo
public static void SerializeTo(BinaryWriter writer, DataType type)
{
writer.Write((byte) type.SqlType);
if (type.IsPrimitive) {
if (type is NumericType) {
var numericType = (NumericType) type;
writer.Write(numericType.Size);
writer.Write(numericType.Scale);
} else if (type is StringType) {
var stringType = (StringType) type;
writer.Write(stringType.MaxSize);
if (stringType.Locale != null) {
writer.Write((byte) 1);
writer.Write(stringType.Locale.Name);
} else {
writer.Write((byte) 0);
}
} else if (type is BinaryType) {
var binaryType = (BinaryType) type;
writer.Write(binaryType.MaxSize);
} else if (type is BooleanType ||
type is IntervalType ||
type is DateType ||
type is NullType) {
// nothing to add to the SQL Type Code
} else if (type is UserType) {
var userType = (UserType) type;
writer.Write((byte)1); // The code of custom type
writer.Write(userType.FullName.FullName);
} else {
throw new NotSupportedException(String.Format("The data type '{0}' cannot be serialized.", type.GetType().FullName));
}
} else {
throw new NotSupportedException();
}
}