本文整理汇总了C#中Composite.Data.DynamicTypes.DataTypeDescriptor类的典型用法代码示例。如果您正苦于以下问题:C# DataTypeDescriptor类的具体用法?C# DataTypeDescriptor怎么用?C# DataTypeDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataTypeDescriptor类属于Composite.Data.DynamicTypes命名空间,在下文中一共展示了DataTypeDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetType
internal static Type TryGetType(DataTypeDescriptor dataTypeDescriptor, bool forceReCompilation, out bool codeGenerationNeeded)
{
Verify.ArgumentNotNull(dataTypeDescriptor, "dataTypeDescriptor");
codeGenerationNeeded = false;
Type type;
if (!forceReCompilation)
{
type = TypeManager.TryGetType(dataTypeDescriptor.GetFullInterfaceName());
if (type != null) return type;
if (!dataTypeDescriptor.IsCodeGenerated)
{
type = TypeManager.TryGetType(dataTypeDescriptor.TypeManagerTypeName);
if (type != null) return type;
}
}
if (!dataTypeDescriptor.IsCodeGenerated)
{
return null;
}
if (forceReCompilation)
{
type = TypeManager.TryGetType(dataTypeDescriptor.GetFullInterfaceName());
if (type != null) return type;
}
codeGenerationNeeded = true;
return null;
}
示例2: GetType
/// <summary>
/// This method will return type given by the dataTypeDescriptor.
/// If the data type does not exist, one will be dynamically
/// runtime code generated.
/// </summary>
/// <param name="dataTypeDescriptor"></param>
/// <param name="forceReCompilation">If this is true a new type will be compiled regardless if one already exists.</param>
/// <returns></returns>
public static Type GetType(DataTypeDescriptor dataTypeDescriptor, bool forceReCompilation = false)
{
bool codeGenerationNeeded;
Type type = TryGetType(dataTypeDescriptor, forceReCompilation, out codeGenerationNeeded);
if (type != null)
{
return type;
}
if (codeGenerationNeeded)
{
lock (_lock)
{
type = TypeManager.TryGetType(dataTypeDescriptor.GetFullInterfaceName());
if (type != null) return type;
var codeGenerationBuilder = new CodeGenerationBuilder("DataInterface: " + dataTypeDescriptor.Name);
InterfaceCodeGenerator.AddAssemblyReferences(codeGenerationBuilder, dataTypeDescriptor);
InterfaceCodeGenerator.AddInterfaceTypeCode(codeGenerationBuilder, dataTypeDescriptor);
IEnumerable<Type> types = CodeGenerationManager.CompileRuntimeTempTypes(codeGenerationBuilder);
return types.Single();
}
}
return null;
}
示例3: AddAssemblyReferences
/// <summary>
/// Adds the assembly references required by the supplied <see cref="DataTypeDescriptor"/> to the supplied <see cref="CodeGenerationBuilder"/>
/// </summary>
/// <param name="codeGenerationBuilder">Assembly refences is added to this builder</param>
/// <param name="dataTypeDescriptor">Data type descriptor which may contain references to assemblies</param>
public static void AddAssemblyReferences(CodeGenerationBuilder codeGenerationBuilder, DataTypeDescriptor dataTypeDescriptor)
{
foreach (Assembly assembly in GetReferencedAssemblies(dataTypeDescriptor))
{
codeGenerationBuilder.AddReference(assembly);
}
}
示例4: XmlDataTypeStore
public XmlDataTypeStore(DataTypeDescriptor dataTypeDescriptor, Type dataProviderHelperType, Type dataIdClassType, IEnumerable<XmlDataTypeStoreDataScope> xmlDateTypeStoreDataScopes, bool isGeneratedDataType)
{
if (dataProviderHelperType == null) throw new ArgumentNullException("dataProviderHelperType");
if (dataIdClassType == null) throw new ArgumentNullException("dataIdClassType");
DataTypeDescriptor = dataTypeDescriptor;
DataProviderHelperType = dataProviderHelperType;
DataIdClassType = dataIdClassType;
IsGeneratedDataType = isGeneratedDataType;
_xmlDateTypeStoreDataScopes = xmlDateTypeStoreDataScopes.Evaluate();
var ordering = new List<Func<XElement, IComparable>>();
foreach (string key in dataTypeDescriptor.KeyPropertyNames)
{
XName localKey = key;
ordering.Add(f => (string)f.Attribute(localKey) ?? "");
}
Func<IEnumerable<XElement>, IOrderedEnumerable<XElement>> orderer = f => ordering.Skip(1).Aggregate(f.OrderBy(ordering.First()), Enumerable.ThenBy);
foreach (XmlDataTypeStoreDataScope xmlDataTypeStoreDataScope in _xmlDateTypeStoreDataScopes)
{
DataScopeIdentifier dataScopeIdentifier = DataScopeIdentifier.Deserialize(xmlDataTypeStoreDataScope.DataScopeName);
CultureInfo culture = CultureInfo.CreateSpecificCulture(xmlDataTypeStoreDataScope.CultureName);
Type dataType = dataTypeDescriptor.GetInterfaceType();
Action cacheFlush = () => DataEventSystemFacade.FireExternalStoreChangedEvent(dataType, dataScopeIdentifier.ToPublicationScope(), culture);
XmlDataProviderDocumentCache.RegisterExternalFileChangeAction(xmlDataTypeStoreDataScope.Filename, cacheFlush);
XmlDataProviderDocumentWriter.RegisterFileOrderer(xmlDataTypeStoreDataScope.Filename, orderer);
}
}
示例5: AddNew
/// <summary>
/// Create an invariant store
/// </summary>
/// <param name="providerName"></param>
/// <param name="dataTypeDescriptor"></param>
public static void AddNew(string providerName, DataTypeDescriptor dataTypeDescriptor)
{
var xmlDataProviderConfiguration = new XmlDataProviderConfiguration(providerName);
string interfaceType = dataTypeDescriptor.TypeManagerTypeName;
if (interfaceType != null)
{
object key = xmlDataProviderConfiguration.Section.Interfaces.GetKey(dataTypeDescriptor);
if (key != null)
{
Log.LogWarning(LogTitle,
"Configuration file '{0}' already contains an interface type '{1} 'with id '{2}'. "
+ "Possibly there are multiple AppDomain-s running.",
xmlDataProviderConfiguration.ConfigurationFilePath, dataTypeDescriptor, dataTypeDescriptor.DataTypeId);
return;
}
}
XmlProviderInterfaceConfigurationElement configurationElement = BuildXmlProviderInterfaceConfigurationElement(dataTypeDescriptor);
XmlDataProviderStoreManipulator.CreateStore(providerName, configurationElement);
xmlDataProviderConfiguration.Section.Interfaces.Add(configurationElement);
xmlDataProviderConfiguration.Save();
}
示例6: Validate
/// <summary>
/// This method validates if the existing .NET runtime type match the recorded meta data (DataTypeDescriptor).
/// In case there is a mismatch, changes might have been done to the runtime type and an update on
/// the existing store(s)could not be performed.
/// </summary>
/// <param name="interfaceType"></param>
/// <param name="existingDataTypeDescriptor"></param>
/// <param name="errorMessage"></param>
/// <returns></returns>
public static bool Validate(Type interfaceType, DataTypeDescriptor existingDataTypeDescriptor, out string errorMessage)
{
DataTypeDescriptor newDataTypeDescriptor;
try
{
newDataTypeDescriptor = DynamicTypeManager.BuildNewDataTypeDescriptor(interfaceType);
}
catch (Exception)
{
errorMessage = null;
return true;
}
try
{
new DataTypeChangeDescriptor(existingDataTypeDescriptor, newDataTypeDescriptor);
}
catch (Exception ex)
{
errorMessage = ex.Message;
return false;
}
errorMessage = null;
return true;
}
示例7: CreateCodeTypeDeclaration
/// <summary>
/// Given a <see cref="DataTypeDescriptor"/> creates a interface declaration inheriting from IData, a valid C1 Datatype.
/// </summary>
/// <param name="dataTypeDescriptor">A description of the data type to generate interface for</param>
/// <returns>The generated interface</returns>
public static CodeTypeDeclaration CreateCodeTypeDeclaration(DataTypeDescriptor dataTypeDescriptor)
{
try
{
var codeTypeDeclaration = new CodeTypeDeclaration(dataTypeDescriptor.Name)
{
IsInterface = true
};
codeTypeDeclaration.BaseTypes.Add(new CodeTypeReference(typeof(IData)));
var propertyNamesToSkip = new List<string>();
foreach (Type superInterface in dataTypeDescriptor.SuperInterfaces)
{
codeTypeDeclaration.BaseTypes.Add(new CodeTypeReference(superInterface));
propertyNamesToSkip.AddRange(superInterface.GetAllProperties().Select(p => p.Name));
}
AddInterfaceAttributes(codeTypeDeclaration, dataTypeDescriptor);
AddInterfaceProperties(codeTypeDeclaration, dataTypeDescriptor, propertyNamesToSkip);
return codeTypeDeclaration;
}
catch (Exception ex)
{
throw new InvalidOperationException(string.Format("Failed to generate interface for type '{0}'", dataTypeDescriptor.TypeManagerTypeName), ex);
}
}
示例8: EntityBaseClassGenerator
public EntityBaseClassGenerator(DataTypeDescriptor dataTypeDescriptor, string entityBaseClassName, string dataIdClassName, string providerName)
{
_entityBaseClassName = entityBaseClassName;
_dataIdClassName = dataIdClassName;
_dataTypeDescriptor = dataTypeDescriptor;
_providerName = providerName;
}
示例9: MakeFileName
internal static string MakeFileName(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScopeIdentifier, string cultureName)
{
string typeFullName = StringExtensionMethods.CreateNamespace(dataTypeDescriptor.Namespace, dataTypeDescriptor.Name, '.');
string publicationScopePart = "";
switch (dataScopeIdentifier.Name)
{
case DataScopeIdentifier.PublicName:
break;
case DataScopeIdentifier.AdministratedName:
publicationScopePart = "_" + PublicationScope.Unpublished;
break;
default:
throw new InvalidOperationException("Unsupported data scope identifier: '{0}'".FormatWith(dataScopeIdentifier.Name));
}
string cultureNamePart = "";
if (cultureName != "")
{
cultureNamePart = "_" + cultureName;
}
return typeFullName + publicationScopePart + cultureNamePart + ".xml";
}
示例10: AddLocale
internal void AddLocale(DataTypeDescriptor typeDescriptor, CultureInfo cultureInfo)
{
foreach (DataScopeIdentifier dataScope in typeDescriptor.DataScopes)
{
CreateStore(typeDescriptor, dataScope, cultureInfo);
}
}
示例11: AddDataType
internal void AddDataType(DataTypeDescriptor dataTypeDescriptor, IEnumerable<SqlDataTypeStoreDataScope> sqlDataTypeStoreDataScopes)
{
Type interfaceType = DataTypeTypesManager.GetDataType(dataTypeDescriptor);
if (interfaceType == null) return;
IEnumerable<Tuple<string, string>> names;
SqlProviderCodeGenerator codeGenerator = new SqlProviderCodeGenerator(_providerName);
IEnumerable<CodeTypeDeclaration> codeTypeDeclarations = codeGenerator.CreateCodeDOMs(dataTypeDescriptor, sqlDataTypeStoreDataScopes, out names);
codeTypeDeclarations.ForEach(f => _codeGenerationBuilder.AddType(_namespaceName, f));
_entityClassNamesAndDataContextFieldNames.AddRange(names);
_codeGenerationBuilder.AddReference(interfaceType.Assembly);
// Property serializer for entity tokens and more
string dataIdClassFullName = NamesCreator.MakeDataIdClassFullName(dataTypeDescriptor, _providerName);
var keyPropertiesDictionary = new Dictionary<string, Type>();
var keyPropertiesList = new List<Tuple<string, Type>>();
foreach (var keyField in dataTypeDescriptor.KeyFields)
{
Verify.That(!keyPropertiesDictionary.ContainsKey(keyField.Name), "Key field with name '{0}' already present. Data type: {1}. Check for multiple [KeyPropertyName(...)] attributes", keyField.Name, dataTypeDescriptor.Namespace + "." + dataTypeDescriptor.Name);
keyPropertiesDictionary.Add(keyField.Name, keyField.InstanceType);
keyPropertiesList.Add(new Tuple<string, Type>(keyField.Name, keyField.InstanceType));
}
PropertySerializerTypeCodeGenerator.AddPropertySerializerTypeCode(_codeGenerationBuilder, dataIdClassFullName, keyPropertiesList);
}
示例12: RemoveLocale
internal void RemoveLocale(string providerName, DataTypeDescriptor typeDescriptor, CultureInfo cultureInfo)
{
foreach (DataScopeIdentifier dataScope in typeDescriptor.DataScopes)
{
DropStore(typeDescriptor, dataScope, cultureInfo);
}
}
示例13: CreateScopeData
private void CreateScopeData(DataTypeDescriptor typeDescriptor, DataScopeIdentifier dataScope)
{
foreach (var cultureInfo in GetCultures(typeDescriptor))
{
CreateStore(typeDescriptor, dataScope, cultureInfo);
}
}
示例14: AddPendingDataTypeDescritpor
/// <summary>
/// Use this method to register data type descriptors that have been validated and will be
/// intstalled.
/// </summary>
/// <param name="interfaceName"></param>
/// <param name="dataTypeDescriptor"></param>
public void AddPendingDataTypeDescritpor(string interfaceName, DataTypeDescriptor dataTypeDescriptor)
{
Verify.ArgumentNotNullOrEmpty(interfaceName, "interfaceName");
Verify.ArgumentNotNull(dataTypeDescriptor, "dataTypeDescriptor");
_pendingDataTypeDescriptors.Add(interfaceName, dataTypeDescriptor);
}
示例15: Validate
/// <summary>
///
/// </summary>
/// <param name="interfaceType"></param>
/// <param name="existingDataTypeDescriptor">Use null to get existing data type descriptor</param>
/// <param name="errorMessage"></param>
/// <returns></returns>
public static bool Validate(Type interfaceType, DataTypeDescriptor existingDataTypeDescriptor, out string errorMessage)
{
if (existingDataTypeDescriptor == null)
{
existingDataTypeDescriptor = DataMetaDataFacade.GetDataTypeDescriptor(interfaceType.GetImmutableTypeId());
if (existingDataTypeDescriptor == null)
{
errorMessage = null;
return true;
}
}
errorMessage = _typeSpecificValidations.GetOrAdd(
interfaceType,
f =>
{
string message;
bool isValid = DataTypeValidator.Validate(interfaceType, existingDataTypeDescriptor, out message);
if (isValid) return null;
var sb = new StringBuilder();
sb.AppendLine(string.Format("The data type interface '{0}' did not validate and can't be used at the moment.", interfaceType));
sb.AppendLine(message);
return sb.ToString();
}
);
return errorMessage == null;
}