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


C# IData.GetType方法代码示例

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


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

示例1: Process

        public override IData Process(IData data)
        {
            DispatcherHelper.RunAsync(() =>
            {
                if (_dataStats.All(s => s.Type != data.GetType()))
                {
                    var stat = new Stat
                           {
                               Type = data.GetType(),
                               Count = 1
                           };
                    stat.Watch.Start();
                    DataStats.Add(stat);
                }
                else
                {
                    var stat = _dataStats.Single(s => s.Type == data.GetType());
                    stat.Fps = 1000.0 / stat.Watch.ElapsedMilliseconds;
                    stat.Watch.Restart();
                    stat.Count++;
                }
            });

            return data;
        }
开发者ID:AlternateIf,项目名称:huddle-engine,代码行数:25,代码来源:DataViewer.cs

示例2: GetParent

        /// <exclude />
        public IData GetParent(IData data)
        {
            if (data == null) throw new ArgumentNullException("data");

            Entry entry = GetEntry(data.GetType());
            object propertyValue = entry.PropertyValueMethodInfo.Invoke(data, null);

            if (entry.PropertyValueMethodInfo.ReturnType == typeof(Guid))
            {
                if (Equals(propertyValue, Guid.Empty)) return null;
            }
            else
            {
                if (Equals(propertyValue, entry.NullValue)) return null;
            }

            using (DataScope dataScope = new DataScope(data.DataSourceId.DataScopeIdentifier))
            {
                List<object> queryResult = GetQueryResult(entry.ParentDataType, entry.ParentIdPropertyName, propertyValue);

                if (queryResult.Count == 0) throw new InvalidOperationException(string.Format("The parent of the type {0} with the id ({1}) value of {2} was not found", entry.ParentDataType, entry.ParentIdPropertyName, propertyValue));
                if (queryResult.Count > 1) throw new InvalidOperationException(string.Format("More than one parent of the type {0} with the id ({1}) value of {2} was found", entry.ParentDataType, entry.ParentIdPropertyName, propertyValue));

                return (IData)queryResult[0];
            }
        }
开发者ID:DBailey635,项目名称:C1-CMS,代码行数:27,代码来源:PropertyDataAncestorProvider.cs

示例3: GetDataAncestorProvider

        public static IDataAncestorProvider GetDataAncestorProvider(IData data)
        {
            if (data == null) throw new ArgumentNullException("data");

            Type dataType = data.GetType();

            var cache = _dataAncestorProviderCache;

            IDataAncestorProvider dataAncestorProvider = cache[dataType];

            if (dataAncestorProvider != null)
            {
                return dataAncestorProvider;
            }

            lock (_syncRoot)
            {
                dataAncestorProvider = cache[dataType];

                if (dataAncestorProvider != null)
                {
                    return dataAncestorProvider;
                }

                List<DataAncestorProviderAttribute> attributes = dataType.GetCustomInterfaceAttributes<DataAncestorProviderAttribute>().ToList();


                if (attributes.Count == 0) throw new InvalidOperationException(string.Format("Missing {0} attribute on the data type {1}", typeof(DataAncestorProviderAttribute), dataType));
                if (attributes.Count > 1) throw new InvalidOperationException(string.Format("Only one {0} attribute is allowed on the data type {1}", typeof(DataAncestorProviderAttribute), dataType));

                DataAncestorProviderAttribute attribute = attributes[0];

                if (attribute.DataAncestorProviderType == null) throw new InvalidOperationException(string.Format("Data ancestor provider type can not be null on the data type {0}", data));
                if (typeof(IDataAncestorProvider).IsAssignableFrom(attribute.DataAncestorProviderType) == false) throw new InvalidOperationException(string.Format("Data ancestor provider {0} should implement the interface {1}", attribute.DataAncestorProviderType, typeof(IDataAncestorProvider)));

                dataAncestorProvider = (IDataAncestorProvider)Activator.CreateInstance(attribute.DataAncestorProviderType);

                cache.Add(dataType, dataAncestorProvider);

                return dataAncestorProvider;
            }
        }
开发者ID:DBailey635,项目名称:C1-CMS,代码行数:42,代码来源:DataAncestorProviderCache.cs

示例4: CompareTo

        /// <summary>
        /// -99 = null input
        /// -1 = wrong type
        /// 0 = same type, wrong id
        /// 1 = same reference (same id, same type)
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int CompareTo(IData other)
        {
            if (other != null)
            {
                try
                {
                    if (other.GetType() != this.GetType())
                        return -1;

                    if (other.ID.Equals(this.ID))
                        return 1;

                    return 0;
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                }
            }

            return -99;
        }
开发者ID:SwiftAusterity,项目名称:NetMud,代码行数:30,代码来源:BackingDataPartial.cs

示例5: GetInstalledVersionOfPendingType

 private static Type GetInstalledVersionOfPendingType(Type interfaceType, IData data)
 {
     return data.GetType().GetInterfaces().FirstOrDefault(i => i.FullName == interfaceType.FullName);
 }
开发者ID:Rogn,项目名称:C1-CMS,代码行数:4,代码来源:DataPackageFragmentInstaller.cs

示例6: ObjectToBindings

        /// <exclude />
        public Dictionary<string, string> ObjectToBindings(IData dataObject, Dictionary<string, object> bindings)
        {
            var errorMessages = new Dictionary<string, string>();

            foreach (var fieldDescriptor in _dataTypeDescriptor.Fields)
            {
                var bindingName = GetBindingName(fieldDescriptor);

                if (bindings.ContainsKey(bindingName))
                {
                    var propertyInfo = dataObject.GetType().GetProperty(fieldDescriptor.Name);

                    Verify.IsNotNull(propertyInfo, "Missing property type '{0}' does not contain property '{1}'", dataObject.GetType(), fieldDescriptor.Name);

                    if (propertyInfo.CanRead)
                    {
                        var newValue = propertyInfo.GetValue(dataObject, null);

                        if (newValue == null && !fieldDescriptor.IsNullable)
                        {
                            var fieldType = fieldDescriptor.InstanceType;

                            if (fieldType == typeof(string) && fieldDescriptor.ForeignKeyReferenceTypeName == null)
                            {
                                newValue = "";
                            }
                            else
                            {
                                newValue = GetDefaultValue(fieldType);
                            }
                        }

                        try
                        {
                            bindings[bindingName] = newValue;
                        }
                        catch (Exception ex)
                        {
                            errorMessages.Add(bindingName, ex.Message);
                        }
                    }
                }
            }

            if (_showPublicationStatusSelector &&
                _dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
            {
                var publishControlled = dataObject as IPublishControlled;

                bindings[PublicationStatusBindingName] = publishControlled.PublicationStatus;
            }

            return errorMessages.Count > 0 ? errorMessages : null;
        }
开发者ID:Orckestra,项目名称:C1-CMS,代码行数:55,代码来源:DataTypeDescriptorFormsHelper.cs

示例7: BindingsToObject

        /// <exclude />
        public Dictionary<string, string> BindingsToObject(Dictionary<string, object> bindings, IData dataObject)
        {
            var errorMessages = new Dictionary<string, string>();

            foreach (var fieldDescriptor in _dataTypeDescriptor.Fields)
            {
                if (_readOnlyFields.Contains(fieldDescriptor.Name))
                {
                    continue;
                }

                var bindingName = GetBindingName(fieldDescriptor);

                if (!bindings.ContainsKey(bindingName))
                {
                    Verify.That(fieldDescriptor.IsNullable, "Missing value for field '{0}'", fieldDescriptor.Name);
                    continue;
                }

                var propertyInfo = dataObject.GetType().GetProperty(fieldDescriptor.Name);

                if (propertyInfo.CanWrite)
                {
                    var newValue = bindings[bindingName];

                    if (newValue is string && (newValue as string) == "" && IsNullableStringReference(propertyInfo))
                    {
                        newValue = null;
                    }

                    try
                    {
                        newValue = ValueTypeConverter.Convert(newValue, propertyInfo.PropertyType);

                        propertyInfo.GetSetMethod().Invoke(dataObject, new[] { newValue });
                    }
                    catch (Exception ex)
                    {
                        errorMessages.Add(bindingName, ex.Message);
                    }
                }
            }

            if (_showPublicationStatusSelector &&
                _dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
            {
                var publishControlled = dataObject as IPublishControlled;

                publishControlled.PublicationStatus = (string)bindings[PublicationStatusBindingName];
            }

            if (errorMessages.Count > 0)
            {
                return errorMessages;
            }

            return null;
        }
开发者ID:Orckestra,项目名称:C1-CMS,代码行数:59,代码来源:DataTypeDescriptorFormsHelper.cs

示例8: GetBindings

        /// <exclude />
        public Dictionary<string, object> GetBindings(IData dataObject, bool allowMandatoryNonDefaultingProperties)
        {
            if (dataObject == null) throw new ArgumentNullException("dataObject");

            var bindings = new Dictionary<string, object>();

            foreach (var fieldDescriptor in _dataTypeDescriptor.Fields)
            {
                var propertyInfo = dataObject.GetType().GetProperty(fieldDescriptor.Name);

                if (propertyInfo.CanRead)
                {
                    var value = propertyInfo.GetGetMethod().Invoke(dataObject, null);

                    if (value == null && !fieldDescriptor.IsNullable)
                    {
                        if (fieldDescriptor.IsNullable)
                        {
                            // Ignore, null is allowed
                        }
                        else if (fieldDescriptor.InstanceType.IsGenericType
                                 && fieldDescriptor.InstanceType.GetGenericTypeDefinition() == typeof(Nullable<>))
                        {
                            // Ignore, null is allowed
                        }
                        else if (allowMandatoryNonDefaultingProperties)
                        {
                            if (propertyInfo.PropertyType == typeof(string) && fieldDescriptor.ForeignKeyReferenceTypeName == null) //FK fields stay NULL
                            {
                                value = "";
                            }
                            else
                            {
                                value = GetDefaultValue(propertyInfo.PropertyType);
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(string.Format("Field '{0}' on type '{1}' is null, does not allow null and does not have a default value", fieldDescriptor.Name, _dataTypeDescriptor.TypeManagerTypeName));
                        }
                    }

                    bindings.Add(GetBindingName(fieldDescriptor), value);
                }
            }

            if (_showPublicationStatusSelector &&
                _dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
            {
                bindings[PublicationStatusBindingName] = ((IPublishControlled)dataObject).PublicationStatus;
                bindings.Add(PublicationStatusOptionsBindingName, GetAvailablePublishingFlowTransitions(EntityToken));

                var interfaceType = dataObject.DataSourceId.InterfaceType;
                var stringKey = dataObject.GetUniqueKey().ToString();
                var locale = dataObject.DataSourceId.LocaleScope.Name;

                var existingPublishSchedule = PublishScheduleHelper.GetPublishSchedule(interfaceType, stringKey, locale);
                bindings.Add("PublishDate", existingPublishSchedule?.PublishDate);

                var existingUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(interfaceType, stringKey, locale);
                bindings.Add("UnpublishDate", existingUnpublishSchedule?.UnpublishDate);
            }

            return bindings;
        }
开发者ID:Orckestra,项目名称:C1-CMS,代码行数:66,代码来源:DataTypeDescriptorFormsHelper.cs

示例9: Equals

        /// <summary>
        /// Compares this object to another one to see if they are the same object
        /// </summary>
        /// <param name="other">the object to compare to</param>
        /// <returns>true if the same object</returns>
        public bool Equals(IData other)
        {
            if (other != default(IData))
            {
                try
                {
                    return other.GetType() == this.GetType() && other.ID.Equals(this.ID);
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                }
            }

            return false;
        }
开发者ID:SwiftAusterity,项目名称:NetMud,代码行数:21,代码来源:BackingDataPartial.cs

示例10: SetNewIdFieldValue

        /// <exclude />
        public static void SetNewIdFieldValue(IData data)
        {
            Verify.ArgumentNotNull(data, "data");

            var keyProperties = data.GetType().GetKeyProperties();

            foreach (var keyProperty in keyProperties)
            {
                bool hasDefaultFieldValueAttribute = keyProperty.GetCustomAttributesRecursively<DefaultFieldValueAttribute>().Any();
                bool hasNewInstanceDefaultFieldValueAttribute = keyProperty.GetCustomAttributesRecursively<NewInstanceDefaultFieldValueAttribute>().Any();

                if (!hasDefaultFieldValueAttribute && !hasNewInstanceDefaultFieldValueAttribute)
                {
                    if (keyProperty.PropertyType == typeof(Guid))
                    {
                        // Assigning a guid key a value because its not part of the generated UI
                        keyProperty.SetValue(data, Guid.NewGuid(), null);
                    }
                    else
                    {
                        // For now, do nothing. This would fix auto increment issue for int key properties
                        // throw new InvalidOperationException(string.Format("The property '{0}' on the data interface '{1}' does not a DefaultFieldValueAttribute or NewInstanceDefaultFieldValueAttribute and no default value could be created", propertyInfo.Name, data.GetType());
                    }
                }
            }
        }
开发者ID:DBailey635,项目名称:C1-CMS,代码行数:27,代码来源:GeneratedTypesHelper.cs

示例11: Send

        /// <summary>
        /// Sends data to the client. The data is serialized with JsonConvert and wrapped into a proper
        /// Huddle message format.
        /// 
        /// {"Type":"[DataType]","Data":[Data]}
        /// </summary>
        /// <param name="data">The data object (it must be serializable with Newtonsoft JsonConvert)</param>
        public void Send(IData data)
        {
            if (data is Proximity)
            {
                var proximity = data as Proximity;
                var x = proximity.Location.X;
                var y = proximity.Location.Y;
                var z = proximity.Location.Z;
                var angle = proximity.Orientation;

                var rx = Math.Round(x, 5);
                var ry = Math.Round(y, 5);
                var rz = Math.Round(z, 5);
                var rangle = Math.Round(angle, 5);

                proximity.Location = new Point3D(rx, ry, rz);
                proximity.Orientation = rangle;

                data = proximity;

                // do not send if proximity did not change.
                if (Equals(_previousProximity, proximity)) return;

                _previousProximity = proximity.Copy() as Proximity;
            }

            var dataSerial = JsonConvert.SerializeObject(data);

            // inject the data type into the message
            var serial = string.Format(Resources.TemplateDataMessage, data.GetType().Name, dataSerial);

            Send(serial);
        }
开发者ID:AlternateIf,项目名称:huddle-engine,代码行数:40,代码来源:Client.cs


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