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


C# MARC.GetType方法代码示例

本文整理汇总了C#中MARC.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# MARC.GetType方法的具体用法?C# MARC.GetType怎么用?C# MARC.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MARC的用法示例。


在下文中一共展示了MARC.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Validate

		public virtual bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] outDetails) {
			MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.AttentionLine instance = o as MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.AttentionLine;;
			outDetails = new MARC.Everest.Connectors.IResultDetail[0]; System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail> details = new System.Collections.Generic.List<MARC.Everest.Connectors.IResultDetail>(10);;
			bool isValid = true;;
			if(instance == null && o != null) throw new System.NullReferenceException(System.String.Format("Could not cast type '{0}' to 'MARC.Everest.RMIM.UV.NE2008.MCCI_MT100200UV01.AttentionLine'!", o.GetType().FullName));if(instance == null || instance.NullFlavor != null) return true;;
			outDetails = details.ToArray();;
			return isValid;;
		}
开发者ID:oneminot,项目名称:everest,代码行数:8,代码来源:NE2008Helper.cs

示例2: Graph

        /// <summary>
        /// Graphs an object to the specified stream
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, MARC.Everest.Interfaces.IGraphable context, XmlIts1FormatterGraphResult resultContext)
        {
            ResultCode rc = ResultCode.Accepted;
            Type instanceType = o.GetType();

            // Verify o is not null
            if (o == null) throw new System.ArgumentNullException("o");

            // Attempt to get null flavor
            
            var nfp = o.GetType().GetProperty("NullFlavor");
            bool isInstanceNull = false, 
                isEntryPoint = false;
            if (nfp != null)
                isInstanceNull = nfp.GetValue(o, null) != null;

            // Interaction?
            object[] structureAttributes = instanceType.GetCustomAttributes(typeof(StructureAttribute), false);
            StructureAttribute structureAttribute = structureAttributes[0] as StructureAttribute;
            if (structureAttribute.StructureType == StructureAttribute.StructureAttributeType.Interaction)
            {
                isEntryPoint = true;
                s.WriteStartElement(structureAttribute.Name, structureAttribute.NamespaceUri);
                s.WriteAttributeString("ITSVersion","XML_1.0"); // Add ITS version
                s.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI);
            }
            else if (structureAttribute.IsEntryPoint && (s is MARC.Everest.Xml.XmlStateWriter && (s as MARC.Everest.Xml.XmlStateWriter).ElementStack.Count == 0 || s.WriteState == System.Xml.WriteState.Start))
            {
                isEntryPoint = true;
                if (isEntryPoint)
                {
                    s.WriteStartElement(structureAttribute.Name, structureAttribute.NamespaceUri);
                    s.WriteAttributeString("xmlns", "xsi", null, XmlIts1Formatter.NS_XSI);
                }
            }
                
            // Validate
            this.Host.ValidateHelper(s, o as IGraphable, this, resultContext);

            // Reflect the properties and ensure they are in the appropriate order
            List<PropertyInfo> buildProperties = GetBuildProperties(instanceType);
            
            // Attributes first
            foreach (var pi in buildProperties)
            {

                object[] propertyAttributes = pi.GetCustomAttributes(typeof(PropertyAttribute), false);
                object instance = pi.GetValue(o, null);

                if (propertyAttributes.Length == 1) // Not a choice
                {
                    PropertyAttribute pa = propertyAttributes[0] as PropertyAttribute;

                    // Validation Rule Change: We'll require the user to perform this
                    // Is this a required attribute that is null? We'll set a null flavor 
                    if ((pa.Conformance == PropertyAttribute.AttributeConformanceType.Required || pa.Conformance == PropertyAttribute.AttributeConformanceType.Populated) &&
                        pa.PropertyType != PropertyAttribute.AttributeAttributeType.Structural &&
                        pi.PropertyType.GetProperty("NullFlavor") != null &&
                        !pi.PropertyType.IsAbstract &&
                        pi.CanWrite)
                    {
                        var nullFlavorProperty = pi.PropertyType.GetProperty("NullFlavor");
                        // Locate the default property 
                        if (instance == null && Host.CreateRequiredElements && nullFlavorProperty != null)
                        {
                            ConstructorInfo ci = pi.PropertyType.GetConstructor(Type.EmptyTypes);
                            instance = ci.Invoke(null);
                            nullFlavorProperty.SetValue(instance, Util.FromWireFormat("NI", nullFlavorProperty.PropertyType), null);
                        }
                    }


                    // Property type
                    switch (pa.PropertyType)
                    {
                        case PropertyAttribute.AttributeAttributeType.Structural:
                            if ((Host.Settings & SettingsType.SuppressNullEnforcement) == 0)
                            {
                                if (instance != null && !isInstanceNull)
                                    s.WriteAttributeString(pa.Name, Util.ToWireFormat(instance));
                                else if (isInstanceNull && pi.Name == "NullFlavor")
                                    Host.WriteNullFlavorUtil(s, (IGraphable)instance);
                            }
                            else if (instance != null)
                            {
                                if (instance != null && pi.Name == "NullFlavor")
                                    Host.WriteNullFlavorUtil(s, (IGraphable)instance);
                                else if (instance != null)
                                    s.WriteAttributeString(pa.Name, Util.ToWireFormat(instance));
                            }

                            break;
                        default:

                            // Instance is null
                            if (instance == null)
                                continue;
//.........这里部分代码省略.........
开发者ID:oneminot,项目名称:everest,代码行数:101,代码来源:ReflectFormatter.cs

示例3: Validate

        /// <summary>
        /// Validates the specified object
        /// </summary>
        public bool Validate(MARC.Everest.Interfaces.IGraphable o, string location, out MARC.Everest.Connectors.IResultDetail[] details)
        {
            List<IResultDetail> dtls = new List<IResultDetail>(10);
            bool isValid = true;

            // Null return bool
            if (o == null)
            {
                details = dtls.ToArray();
                return true;
            }

            PropertyInfo nullFlavorAttrib = o.GetType().GetProperty("NullFlavor");
            if (nullFlavorAttrib != null && nullFlavorAttrib.GetValue(o, null) != null)
            {
                details = dtls.ToArray();
                return true;
            }

            // Scan property info for violations
            foreach (var pi in this.GetBuildProperties(o.GetType()))
            {

                if (pi.GetGetMethod().GetParameters().Length != 0)
                {
                    dtls.Add(new NotImplementedResultDetail(
                        ResultDetailType.Warning,
                        String.Format("Could not validate '{0}' as the property is indexed", pi.Name),
                        location
                    ));
                    continue;
                }

                object piValue = pi.GetValue(o, null);
                object[] propAttributes = pi.GetCustomAttributes(typeof(PropertyAttribute), true);
                
                if (propAttributes.Length > 0)
                {
                    PropertyAttribute pa = propAttributes[0] as PropertyAttribute;
                    if (pa.Conformance == PropertyAttribute.AttributeConformanceType.Mandatory &&
                        pi.PropertyType.GetInterface(typeof(IImplementsNullFlavor).FullName, false) != null &&
                        (piValue == null || (piValue as IImplementsNullFlavor).NullFlavor != null))
                    {
                        isValid = false;
                        dtls.Add(new MandatoryElementMissingResultDetail(ResultDetailType.Error, String.Format("Property {0} in {1} is marked mandatory and is either not assigned, or is assigned a null flavor. This is not permitted.", pi.Name, o.GetType().FullName), location));
                    }
                    else if (pa.Conformance == PropertyAttribute.AttributeConformanceType.Populated && piValue == null)
                    {
                        isValid &= Host.CreateRequiredElements;
                        dtls.Add(new RequiredElementMissingResultDetail(isValid ? ResultDetailType.Warning : ResultDetailType.Error, String.Format("Property {0} in {1} is marked 'populated' and isn't assigned (you must at minimum, assign a nullFlavor for this attribute)!", pi.Name, o.GetType().FullName), location));
                    }
                    else if (pa.MinOccurs != 0)
                    {
                        int minOccurs = pa.MinOccurs, 
                            maxOccurs = pa.MaxOccurs < 0 ? Int32.MaxValue : pa.MaxOccurs;
                        var piCollection = piValue as ICollection;
                        if(piCollection != null && (piCollection.Count > maxOccurs || piCollection.Count < minOccurs))
                        { 
                            isValid = false; 
                            dtls.Add(new InsufficientRepetitionsResultDetail(ResultDetailType.Error, String.Format("Property {0} in {2} does not have enough elements in the list, need between {1} and {3} elements!", pi.Name, minOccurs, o.GetType().FullName, maxOccurs), location));
                        }
                    }
                }
            }

            details = dtls.ToArray();
            return isValid;
        }
开发者ID:oneminot,项目名称:everest,代码行数:71,代码来源:ReflectFormatter.cs


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