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


C# Property.GetType方法代码示例

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


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

示例1: ValueCollectionEntry

 public ValueCollectionEntry(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Property prop)
     : base(_host, ctx)
 {
     if (!(prop is ValueTypeProperty || prop is CompoundObjectProperty))
     {
         throw new ArgumentOutOfRangeException("prop",
             String.Format("Property has to be either ValueTypeProperty or CompoundObjectProperty, but is {0}", prop.GetType().FullName));
     }
     this.prop = prop;
 }
开发者ID:daszat,项目名称:zetbox,代码行数:10,代码来源:ValueCollectionEntry.cs

示例2: CreateObject

        /// <summary>
        ///   Builds object from property
        /// </summary>
        /// <param name = "property"></param>
        /// <returns></returns>
        public object CreateObject(Property property, object copyToObject = null)
        {
            if (property == null) {
                throw new ArgumentNullException("property");
            }

            // Is it NullProperty?
            var nullProperty = property as NullProperty;
            if (nullProperty != null) {
                return null;
            }

            if (property.Type == null) {
                // there is no property type and no expected type defined. Give up!
                throw new InvalidOperationException(string.Format("Property type is not defined. Property: \"{0}\"", property.Name));
            }

            // Is it SimpleProperty?
            var simpleProperty = property as SimpleProperty;
            if (simpleProperty != null) {
                return CreateObjectFromSimpleProperty(simpleProperty);
            }

            var referenceTarget = property as ReferenceTargetProperty;
            if (referenceTarget == null) {
                return null;
            }

            if (copyToObject != null) {
                return CreateObjectFromComplexProperty(referenceTarget as ComplexProperty, copyToObject);
            }

            if (referenceTarget.Reference != null) {
                if (!referenceTarget.Reference.IsProcessed) {
                    // object was created already
                    // get object from cache
                    return _objectCache[referenceTarget.Reference.Id];
                }
            }

            var value = CreateObjectCore(referenceTarget);
            if (value != null) {
                return value;
            }

            // No idea what it is
            throw new InvalidOperationException(string.Format("Unknown Property type: {0}", property.GetType().Name));
        }
开发者ID:jerkka,项目名称:Olan,代码行数:53,代码来源:ObjectFactory.cs

示例3: CreateObject

        /// <summary>
        /// Builds object from property
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        public object CreateObject(Property property)
        {
            if (property == null) throw new ArgumentNullException("property");

            // Is it NullProperty?
            var nullProperty = property as NullProperty;
            if (nullProperty != null)
            {
                return null;
            }

            if (property.Type == null)
            {
                // there is no property type and no expected type defined. Give up!
                throw new InvalidOperationException(string.Format("Property type is not defined. Property: \"{0}\"", property.Name));
            }

            // Is it SimpleProperty?
            var simpleProperty = property as SimpleProperty;
            if (simpleProperty != null)
            {
                return createObjectFromSimpleProperty(simpleProperty);
            }

            // Is it multidimensional array?
            var multiDimensionalArrayProperty = property as MultiDimensionalArrayProperty;
            if (multiDimensionalArrayProperty != null)
            {
                return createObjectFromMultidimensionalArrayProperty(multiDimensionalArrayProperty);
            }

            // Is it singledimensional array?
            var singleDimensionalArrayProperty = property as SingleDimensionalArrayProperty;
            if (singleDimensionalArrayProperty != null)
            {
                return createObjectFromSingleDimensionalArrayProperty(singleDimensionalArrayProperty);
            }

            // Is it dictionary?
            var dictionaryProperty = property as DictionaryProperty;
            if (dictionaryProperty != null)
            {
                return createObjectFromDictionaryProperty(dictionaryProperty);
            }

            // Is it collection?
            var collectionProperty = property as CollectionProperty;
            if (collectionProperty != null)
            {
                return createObjectFromCollectionProperty(collectionProperty);
            }

            // Is it complex type? Class? Structure?
            var complexProperty = property as ComplexProperty;
            if (complexProperty != null)
            {
                return createObjectFromComplexProperty(complexProperty);
            }

            // No idea what it is
            throw new InvalidOperationException(string.Format("Unknown Property type: {0}", property.GetType().Name));
        }
开发者ID:karnauhov,项目名称:smart-h,代码行数:67,代码来源:ObjectFactory.cs

示例4: GetPropertyValue

        public static string GetPropertyValue(Property prop, bool textValue)
        {
            Type propertyType = prop.GetType();

            string propertyValue = null;

            if (propertyType == typeof(StringProperty))
            {
                propertyValue = ((StringProperty)prop).Value;
            }
            else if (propertyType == typeof(CrmDateTimeProperty))
            {
                propertyValue = ((CrmDateTimeProperty)prop).Value.Value;
            }
            else if (propertyType == typeof(KeyProperty))
            {
                propertyValue = ((KeyProperty)prop).Value.Value.ToString("D");
            }
            else if (propertyType == typeof(CustomerProperty))
            {
                propertyValue = textValue ? ((CustomerProperty)prop).Value.name : ((CustomerProperty)prop).Value.Value.ToString();
            }
            else if (propertyType == typeof(LookupProperty))
            {
                propertyValue = textValue ? ((LookupProperty)prop).Value.name : ((LookupProperty)prop).Value.Value.ToString("D");
            }
            else if (propertyType == typeof(StateProperty))
            {
                propertyValue = ((StateProperty)prop).Value;
            }
            else if (propertyType == typeof(OwnerProperty))
            {
                propertyValue = textValue ? ((OwnerProperty)prop).Value.name : ((OwnerProperty)prop).Value.Value.ToString("D");
            }
            else if (propertyType == typeof(CrmBooleanProperty))
            {
                propertyValue = ((CrmBooleanProperty)prop).Value.Value.ToString();
            }
            else if (propertyType == typeof(PicklistProperty))
            {
                propertyValue = textValue ? ((PicklistProperty)prop).Value.name : ((PicklistProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture);
            }
            else if (propertyType == typeof(CrmDecimalProperty))
            {
                propertyValue = ((CrmDecimalProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture);
            }
            else if (propertyType == typeof(CrmFloatProperty))
            {
                propertyValue = ((CrmFloatProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture);
            }
            else if (propertyType == typeof(CrmMoneyProperty))
            {
                propertyValue = ((CrmMoneyProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture);
            }
            else if (propertyType == typeof(CrmNumberProperty))
            {
                propertyValue = ((CrmNumberProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture);
            }

            return propertyValue;
        }
开发者ID:ccellar,项目名称:crmaudit,代码行数:61,代码来源:CustomDynamicEntity.cs

示例5: PropertyControlInfo

 private PropertyControlInfo(Property property)
     : base()
 {
     this.property = property;
     PropertyControlType defaultControlType = propertyTypeToDefaultControlType[this.property.GetType()];
     this.controlType = StaticListChoiceProperty.CreateForEnum<PropertyControlType>(ControlInfoPropertyNames.ControlType, defaultControlType, false);
     this.controlType.ValueChanged += new EventHandler(ControlType_ValueChanged);
     this.ControlProperties = controlTypeToProperties[Pair.Create(property.GetType(), (PropertyControlType)this.controlType.Value)].Clone();
 }
开发者ID:herbqiao,项目名称:paint.net,代码行数:9,代码来源:PropertyControlInfo.cs

示例6: ApplyPropertyTemplate

        protected virtual void ApplyPropertyTemplate(Property p)
        {
            if (p is EnumerationProperty)
            {
                if (((EnumerationProperty)p).IsList)
                {
                    ApplyEnumerationListTemplate((EnumerationProperty)p);
                    ApplyListChangedEvent(p);
                }
                else
                {
                    ApplyEnumerationPropertyTemplate((EnumerationProperty)p);
                    ApplyPropertyEvents(p, false);
                }
            }
            else if (p is ObjectReferenceProperty)
            {
                var orp = (ObjectReferenceProperty)p;
                if (orp.IsList())
                {
                    ApplyObjectReferenceListTemplate(orp);
                    ApplyListChangedEvent(p);
                }
                else
                {
                    ApplyObjectReferencePropertyTemplate(orp);
                    ApplyPropertyEvents(p, false);
                }
            }
            else if (p is CalculatedObjectReferenceProperty)
            {
                ApplyCalculatedPropertyTemplate((CalculatedObjectReferenceProperty)p);
                ApplyPropertyEvents(p, true);
            }
            else if (p is CompoundObjectProperty)
            {
                if (((CompoundObjectProperty)p).IsList)
                {
                    ApplyCompoundObjectListTemplate((CompoundObjectProperty)p);
                    ApplyListChangedEvent(p);
                }
                else
                {
                    ApplyCompoundObjectPropertyTemplate((CompoundObjectProperty)p);
                    // no PropertyInvocationsTemplate for CompoundObject
                }
            }
            else if (p is ValueTypeProperty)
            {
                var vtp = (ValueTypeProperty)p;
                if (vtp.IsList)
                {
                    ApplyValueTypeListTemplate(vtp);
                    ApplyListChangedEvent(p);
                }
                else
                {
                    ApplyValueTypePropertyTemplate(vtp);
                    ApplyPropertyEvents(p, false);
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException("p", String.Format("unknown property type '{0}'", p.GetType().ToString()));
            }

            ApplyPropertyIsValidEvent(p);
        }
开发者ID:daszat,项目名称:zetbox,代码行数:68,代码来源:TypeBase.Properties.cs

示例7: PropertyToClrType

 private static string PropertyToClrType(Property prop)
 {
     return prop.GetType().Name;
 }
开发者ID:daszat,项目名称:zetbox,代码行数:4,代码来源:Exceptions.cs

示例8: GetStandInValue

 private static string GetStandInValue(Property p)
 {
     if (p is DecimalProperty)
     {
         return "Decimal.MinValue";
     }
     else if (p is IntProperty)
     {
         return "Int32.MinValue";
     }
     else if (p is DoubleProperty)
     {
         return "Double.MinValue";
     }
     else if (p is StringProperty)
     {
         return "null";
     }
     else if (p is DateTimeProperty)
     {
         return "DateTime.MinValue";
     }
     else if (p is GuidProperty)
     {
         return "Guid.Empty";
     }
     else if (p is BoolProperty)
     {
         return "false";
     }
     else if (p is EnumerationProperty)
     {
         return "-1";
     }
     else if (p is ObjectReferenceProperty)
     {
         return "-1";
     }
     else if (p is CalculatedObjectReferenceProperty)
     {
         return "-1";
     }
     else if (p is CompoundObjectProperty)
     {
         return "null";
     }
     else
     {
         throw new NotSupportedException(string.Format("DynamicOrderByExpression for Property Type {0} are not supported yet", p.GetType().Name));
     }
 }
开发者ID:daszat,项目名称:zetbox,代码行数:51,代码来源:ColumnDisplayModel.cs

示例9: ApplyPropertyTemplate

        protected virtual void ApplyPropertyTemplate(Property p)
        {
            if (p is EnumerationProperty)
            {
                if (((EnumerationProperty)p).IsList)
                {
                    ApplyEnumerationListTemplate((EnumerationProperty)p);
                    ApplyListChangedEvent(p);
                }
                else
                {
                    ApplyEnumerationPropertyTemplate((EnumerationProperty)p);
                    ApplyPropertyEvents(p, false);
                }
            }
            else if (p is ObjectReferenceProperty)
            {
                var orp = (ObjectReferenceProperty)p;
                if (orp.IsList())
                {
                    ApplyObjectReferenceListTemplate(orp);
                    var rel = Zetbox.App.Extensions.RelationExtensions.Lookup(ctx, orp);
                    if (rel.GetRelationType() == API.RelationType.one_n)
                    {
                        // TODO: No idea how to implement this for n:m Relations
                        ApplyListChangedEvent(p);
                    }
                }
                else
                {
                    ApplyObjectReferencePropertyTemplate(orp);
                    ApplyPropertyEvents(p, false);
                }
            }
            else if (p is CalculatedObjectReferenceProperty)
            {
                ApplyCalculatedPropertyTemplate((CalculatedObjectReferenceProperty)p);
                ApplyPropertyEvents(p, true);
            }
            else if (p is CompoundObjectProperty)
            {
                if (((CompoundObjectProperty)p).IsList)
                {
                    ApplyCompoundObjectListTemplate((CompoundObjectProperty)p);
                    ApplyListChangedEvent(p);
                }
                else
                {
                    ApplyCompoundObjectPropertyTemplate((CompoundObjectProperty)p);
                    // no PropertyInvocationsTemplate for CompoundObject
                }
            }
            else if (p is ValueTypeProperty)
            {
                var vtp = (ValueTypeProperty)p;
                if (vtp.IsList)
                {
                    ApplyValueTypeListTemplate(vtp);
                    ApplyListChangedEvent(p);
                }
                else
                {
                    ApplyValueTypePropertyTemplate(vtp);
                    ApplyPropertyEvents(p, false);
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException("p", String.Format("unknown property type '{0}'", p.GetType().ToString()));
            }

            ApplyPropertyIsValidEvent(p);
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:73,代码来源:TypeBase.Properties.cs

示例10: TestGetIntegerPerformance

        public void TestGetIntegerPerformance()
        {
            const int TEST_ITERATIONS = 1000000;
        	Property prop = new Property();
            int test = -1;
            Timer timer = new Timer();

            #region Direct access (fastest)
        	GC.Collect();
            GC.WaitForPendingFinalizers();

            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
                test = prop.Int;
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double directAccessDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            #endregion

            #region IL Property accessor
            GC.Collect();
            GC.WaitForPendingFinalizers();

            IGetAccessorFactory factory = new GetAccessorFactory(true);
            IGetAccessor propertyAccessor = factory.CreateGetAccessor(typeof(Property), "Int");
            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
                test = (int)propertyAccessor.Get(prop);
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double propertyAccessorDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            double propertyAccessorRatio = propertyAccessorDuration / directAccessDuration;
            #endregion

            #region IBatisNet.Common.Utilities.Object.ReflectionInfo
            GC.Collect();
            GC.WaitForPendingFinalizers();

        	ReflectionInfo reflectionInfo = ReflectionInfo.GetInstance(prop.GetType());
            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
            	PropertyInfo propertyInfo = (PropertyInfo)reflectionInfo.GetGetter("Int");
                test = (int)propertyInfo.GetValue(prop, null);
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double reflectionInfoDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            double reflectionInfoRatio = (float)reflectionInfoDuration / directAccessDuration;
            #endregion

            #region Reflection
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Type type = prop.GetType();
            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
                PropertyInfo propertyInfo = type.GetProperty("Int", BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
                test = (int)propertyInfo.GetValue(prop, null);
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double reflectionDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            double reflectionRatio = reflectionDuration / directAccessDuration;
            #endregion

            #region ReflectionInvokeMember (slowest)
            GC.Collect();
            GC.WaitForPendingFinalizers();

            timer.Start();
            for (int i = 0; i < TEST_ITERATIONS; i++)
            {
                test = -1;
                test = (int)type.InvokeMember("Int",
                    BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance,
                    null, prop, null);
                Assert.AreEqual(int.MinValue, test);
            }
            timer.Stop();
            double reflectionInvokeMemberDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS);
            double reflectionInvokeMemberRatio = reflectionInvokeMemberDuration / directAccessDuration;
            #endregion

            // Print results
            Console.WriteLine("{0} property gets on integer...", TEST_ITERATIONS);
            Console.WriteLine("Direct access: \t\t{0} ", directAccessDuration.ToString("F3"));
            Console.WriteLine("IMemberAccessor: \t\t{0} Ratio: {1}", propertyAccessorDuration.ToString("F3"), propertyAccessorRatio.ToString("F3"));
            Console.WriteLine("IBatisNet ReflectionInfo: \t{0} Ratio: {1}", reflectionInfoDuration.ToString("F3"), reflectionInfoRatio.ToString("F3"));
            Console.WriteLine("ReflectionInvokeMember: \t{0} Ratio: {1}", reflectionInvokeMemberDuration.ToString("F3"), reflectionInvokeMemberRatio.ToString("F3"));
//.........这里部分代码省略.........
开发者ID:techvenky,项目名称:mybatisnet,代码行数:101,代码来源:PropertyAccessorPerformance.cs


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