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


C# PropertyBag.TryGetProperty方法代码示例

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


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

示例1: ScopeToTimeZone

        /// <summary>
        /// Scopes the date time property to the appropriate time zone, if necessary.
        /// </summary>
        /// <param name="service">The service emitting the request.</param>
        /// <param name="dateTime">The date time.</param>
        /// <param name="propertyBag">The property bag.</param>
        /// <param name="isUpdateOperation">Indicates whether the scoping is to be performed in the context of an update operation.</param>
        /// <returns>The converted DateTime.</returns>
        internal override DateTime ScopeToTimeZone(
            ExchangeServiceBase service,
            DateTime dateTime,
            PropertyBag propertyBag,
            bool isUpdateOperation)
        {
            if (!propertyBag.Owner.GetIsCustomDateTimeScopingRequired())
            {
                // Most item types do not require a custom scoping mechanism. For those item types,
                // use the default scoping mechanism.
                return base.ScopeToTimeZone(
                    service,
                    dateTime,
                    propertyBag,
                    isUpdateOperation);
            }
            else
            {
                // Appointment, however, requires a custom scoping mechanism which is based on an
                // associated time zone property.
                PropertyDefinition timeZoneProperty = this.GetTimeZoneProperty(service.RequestedServerVersion);
                object timeZonePropertyValue = null;

                bool timeZonePropertyIsSet = propertyBag.TryGetProperty(timeZoneProperty, out timeZonePropertyValue);

                if (timeZonePropertyValue != null && propertyBag.IsPropertyUpdated(timeZoneProperty))
                {
                    // If we have the associated time zone property handy and if it has been updated locally,
                    // then we scope the date time to that time zone.
                    try
                    {
                        DateTime convertedDateTime = EwsUtilities.ConvertTime(
                            dateTime,
                            (TimeZoneInfo)timeZonePropertyValue,
                            TimeZoneInfo.Utc);

                        // This is necessary to stamp the date/time with the Local kind.
                        return new DateTime(convertedDateTime.Ticks, DateTimeKind.Utc);
                    }
                    catch (TimeZoneConversionException e)
                    {
                        throw new PropertyException(
                            string.Format(Strings.InvalidDateTime, dateTime),
                            this.Name,
                            e);
                    }
                }
                else
                {
                    if (isUpdateOperation)
                    {
                        // In an update operation, what we do depends on what version of EWS
                        // we are targeting.
                        if (service.RequestedServerVersion == ExchangeVersion.Exchange2007_SP1)
                        {
                            // For Exchange 2007 SP1, we still need to scope to the service's time zone.
                            return base.ScopeToTimeZone(
                                service,
                                dateTime,
                                propertyBag,
                                isUpdateOperation);
                        }
                        else
                        {
                            // Otherwise, we let the server scope to the appropriate time zone.
                            return dateTime;
                        }
                    }
                    else
                    {
                        // In a Create operation, always scope to the service's time zone.
                        return base.ScopeToTimeZone(
                            service,
                            dateTime,
                            propertyBag,
                            isUpdateOperation);
                    }
                }
            }
        }
开发者ID:liliankasem,项目名称:ProjectSpikeAPI,代码行数:88,代码来源:ScopedDateTimePropertyDefinition.cs


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