本文整理汇总了C#中Type.IsDefined方法的典型用法代码示例。如果您正苦于以下问题:C# Type.IsDefined方法的具体用法?C# Type.IsDefined怎么用?C# Type.IsDefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.IsDefined方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
/// <summary>
/// Create version info from the type info
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static SerializedVersionInfo Create(Type type)
{
if (type.IsDefined(typeof (VersionAttribute), false))
{
VersionAttribute versionInfo = (VersionAttribute) type.GetCustomAttributes(typeof (VersionAttribute), false)[0];
string typeName = type.FullName;
int versionNumber = versionInfo.VersionNumber;
return new SerializedVersionInfo(typeName, versionNumber);
}
else
{
string typeName = type.FullName;
const int versionNumber = 0;
return new SerializedVersionInfo(typeName, versionNumber);
}
}
示例2: AddServiceEndpoint
public ServiceEndpoint AddServiceEndpoint(Type implementedContract, Binding binding, Uri address, Uri listenUri)
{
if (implementedContract == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("implementedContract"));
}
if (!implementedContract.IsDefined(typeof(ServiceContractAttribute), false))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.ServiceContractAttributeNotFound, new object[] { implementedContract.FullName })));
}
if (this.reflectedContracts == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.ReflectedContractsNotInitialized, new object[] { implementedContract.FullName })));
}
if (!reflectedContracts.Contains(implementedContract))
{
if (ServiceMetadataBehavior.IsMetadataImplementedType(implementedContract))
{
if (!this.Description.Behaviors.Contains(
typeof(ServiceMetadataBehavior)))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.MetadataEndpointCannotBeAdded, new object[] { implementedContract.FullName })));
}
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.ReflectedContractKeyNotFound, new object[] { implementedContract.FullName, this.workflowDefinitionContext.WorkflowName })));
}
}
ServiceEndpoint endpoint = base.AddServiceEndpoint(ContractDescription.GetContract(implementedContract).ConfigurationName, binding, address);
if (listenUri != null)
{
listenUri = base.MakeAbsoluteUri(listenUri, binding);
endpoint.ListenUri = listenUri;
}
return endpoint;
}
示例3: IsTypeReferenceable
private static bool IsTypeReferenceable(Type type)
{
Type itemType;
try
{
return (type.IsSerializable ||
type.IsDefined(Globals.TypeOfDataContractAttribute, false) ||
(Globals.TypeOfIXmlSerializable.IsAssignableFrom(type) && !type.IsGenericTypeDefinition) ||
CollectionDataContract.IsCollection(type, out itemType) ||
ClassDataContract.IsNonAttributedTypeValidForSerialization(type));
}
catch (Exception ex)
{
// An exception can be thrown in the designer when a project has a runtime binding redirection for a referenced assembly or a reference dependent assembly.
// Type.IsDefined is known to throw System.IO.FileLoadException.
// ClassDataContract.IsNonAttributedTypeValidForSerialization is known to throw System.IO.FileNotFoundException.
// We guard against all non-critical exceptions.
if (DiagnosticUtility.IsFatal(ex))
{
throw;
}
}
return false;
}
示例4: IsScriptable
public static bool IsScriptable (Type t)
{
if (t.IsDefined (typeof(ScriptableTypeAttribute), true))
return true;
foreach (MethodInfo mi in t.GetMethods ())
if (mi.IsDefined (typeof(ScriptableMemberAttribute), true))
return true;
foreach (PropertyInfo pi in t.GetProperties ())
if (pi.IsDefined (typeof(ScriptableMemberAttribute), true))
return true;
foreach (EventInfo ei in t.GetEvents ())
if (ei.IsDefined (typeof(ScriptableMemberAttribute), true))
return true;
return false;
}