当前位置: 首页>>代码示例>>C#>>正文


C# Type.IsDefined方法代码示例

本文整理汇总了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);
        }
    }
开发者ID:Awesome-MQP,项目名称:Storybook,代码行数:24,代码来源:SerializedVersionInfo.cs

示例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;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:40,代码来源:WorkflowServiceHost.cs

示例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;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:26,代码来源:DataContractSet.cs

示例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;
		}
开发者ID:shana,项目名称:moon,代码行数:19,代码来源:ManagedObject.cs


注:本文中的Type.IsDefined方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。