• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# DataContract类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中DataContract的典型用法代码示例。如果您正苦于以下问题:C# DataContract类的具体用法?C# DataContract怎么用?C# DataContract使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DataContract类属于命名空间,在下文中一共展示了DataContract类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AddRemark

        public DataContract.RemarkResponse AddRemark(string employeeId, DataContract.Remark remark)
        {
            RemarkResponse response = new RemarkResponse();
            try
            {
                var result = _manager.AddRemark(employeeId, remark.ToDomainModel());
                if (result == null)
                {
                    response.Status.StatusCode = "500";
                    response.Status.Message = "Error in creating employee";

                    return response;
                }
                response.Remark = result.ToDataContract();
                return response;
            }
            catch (Exception ex)
            {

                ExceptionPolicy.HandleException("service.policy", ex);
                response.Status.StatusCode = "500";
                response.Status.Message = "Error in creating Employee";
                return response;
            }
        }
开发者ID:tavisca-dhruvas,项目名称:Training,代码行数:25,代码来源:EmployeeManagementService.cs


示例2: ListLugares

 public ResultadoMapa ListLugares(DataContract.PointDC tl, DataContract.PointDC br, byte zoom, FiltroMapa filtro)
 {
     if (zoom >= 8)
     {
         PersistenceManager persistence = new PersistenceManager();
         ICriteria criteria = persistence.CreateCriteria<Lugar>();
         List<Coordinate> coordenadas = new List<Coordinate>();
         coordenadas.Add(new Coordinate(tl.Longitud, tl.Latitud));
         coordenadas.Add(new Coordinate(br.Longitud, tl.Latitud));
         coordenadas.Add(new Coordinate(br.Longitud, br.Latitud));
         coordenadas.Add(new Coordinate(tl.Longitud, br.Latitud));
         coordenadas.Add(new Coordinate(tl.Longitud, tl.Latitud));
         Polygon p = new Polygon(new LinearRing(coordenadas.ToArray()));
         criteria.SetProjection(Projections.ProjectionList()
             .Add(Projections.Property<Lugar>(l => l.ID), "ID")
             .Add(Projections.Property<Lugar>(l => l.Posicion), "Point")
             .Add(Projections.Property<Lugar>(l => l.Nombre), "Nombre")
             );
         criteria.Add(SpatialRestrictions.Within("Posicion", p));
         criteria.SetResultTransformer(Transformers.AliasToBean<ItemLugar>());
         criteria.AddOrder(new Order(Projections.Property<Lugar>(l => l.Nombre), true));
         var list = criteria.List<ItemLugar>().ToList();
         HttpContext.Current.Session["Colegios"] = list;
         return new ResultadoMapa() { Items = list };
     }
     return new ResultadoMapa() { Items = new List<ItemLugar>() };
 }
开发者ID:desarrollandoAmericaLatina,项目名称:Taem,代码行数:27,代码来源:APIService.cs


示例3: Create

        public DataContract.EmployeeResponse Create(DataContract.Employee employee)
        {
            EmployeeResponse response = new EmployeeResponse();
            try
            {
                employee.JoiningDate = DateTime.UtcNow;
                var result = _manager.Create(employee.ToDomainModel());
                if (result == null)
                {
                    response.Status.StatusCode = "500";
                    response.Status.Message = "Error in creating employee";

                    return response;
                }
                response.Employee = result.ToDataContract();
                return response;
            }
            catch (Exception ex)
            {

                ExceptionPolicy.HandleException("service.policy", ex);
                response.Status.StatusCode = "500";
                response.Status.Message = "Error in creating Employee";
                return response;
            }
        }
开发者ID:tavisca-dhruvas,项目名称:Training,代码行数:26,代码来源:EmployeeManagementService.cs


示例4: XmlObjectSerializerWriteContextComplexJson

        public XmlObjectSerializerWriteContextComplexJson(DataContractJsonSerializer serializer, DataContract rootTypeDataContract)
            : base(null, int.MaxValue, new StreamingContext(), true)

        {
            _jsonSerializer = serializer;
            this.rootTypeDataContract = rootTypeDataContract;
            this.serializerKnownTypeList = serializer.knownTypeList;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:XmlObjectSerializerWriteContextComplexJson.cs


示例5: Random

        int IBlogService.CreateEntry(DataContract.Entry entry)
        {
			var entity = new Entity.Entry()
			{
				Content = entry.Content,
				Name = entry.Title,
				Id = new Random().Next(1000)
			};
			return entity.Id;
        }
开发者ID:thebeekeeper,项目名称:Laurus.Blog,代码行数:10,代码来源:BlogService.cs


示例6: XmlObjectSerializerReadContextComplexJson

 public XmlObjectSerializerReadContextComplexJson(DataContractJsonSerializer serializer, DataContract rootTypeDataContract)
     : base(serializer, serializer.MaxItemsInObjectGraph,
         new StreamingContext(StreamingContextStates.All),
         serializer.IgnoreExtensionDataObject)
 {
     this.rootTypeDataContract = rootTypeDataContract;
     this.serializerKnownTypeList = serializer.knownTypeList;
     this.dataContractSurrogate = serializer.DataContractSurrogate;
     this.dateTimeFormat = serializer.DateTimeFormat;
     this.useSimpleDictionaryFormat = serializer.UseSimpleDictionaryFormat;
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:11,代码来源:XmlObjectSerializerReadContextComplexJson.cs


示例7:

		void IBlogService.AddEntry(int blogId, DataContract.Entry entry)
		{
			var entryEntity = new Entity.Entry()
			{
				Name = entry.Title,
				Content = entry.Content,
				//BlogId = blogId
			};
			if (_repository.Query<Entity.Blog>().Where(x => x.Id == blogId).Any())
			{
				_repository.Persist(entryEntity);
			}
		}
开发者ID:thebeekeeper,项目名称:Laurus.Blog,代码行数:13,代码来源:BlogService.cs


示例8: Translate

        public static void Translate(Repository.Item dbItem, DataContract.Item item)
        {
            dbItem.ItemAbstract = item.ItemAbstract;
            dbItem.ItemTitle = item.ItemTitle;
            dbItem.LastUpdated = DateTime.Now;

            if (item.Content != null)
            {
                dbItem.InternalUrl = item.Content.InternalUrl;
                dbItem.ExternalUrl = item.Content.ExternalUrl;
                dbItem.ItemText = item.Content.ItemText;
            }
        }
开发者ID:sirtristancomtedeartois,项目名称:note,代码行数:13,代码来源:ItemTranslator.cs


示例9: ChangePassword

 public bool ChangePassword(DataContract.ChangePasswordRequest request)
 {
     try
     {
         return _manager.ChangePassword(request.Email, request.OldPassword, request.NewPassword);
     }
     catch (Exception ex)
     {
         Exception newEx;
         var rethrow = ExceptionPolicy.HandleException("service.policy", ex, out newEx);
         return false;
     }
 }
开发者ID:ytokas,项目名称:Tavisca-Training-WCF-EMS,代码行数:13,代码来源:IdentityService.cs


示例10: Authenticate

        public DataContract.EmployeeResponse Authenticate(DataContract.Credentials credentials)
        {
            EmployeeResponse response = new EmployeeResponse();
            var result = _manager.Authenticate(credentials.EmailId, credentials.Password);
            if (result == null)
            {
                response.Status.StatusCode = "500";
                response.Status.Message = "Error in creating employee";

                return response;
            }
            response.Employee = result.ToDataContract();
            return response;
        }
开发者ID:tavisca-dhruvas,项目名称:Training,代码行数:14,代码来源:EmployeeManagementService.cs


示例11: Authenticate

 public DataContract.Employee Authenticate(DataContract.Credential credential)
 {
     try
     {
         var result = _manager.Authenticate(credential.ToDomainModel());
         if (result == null) return null;
         return result.ToDataContract();
     }
     catch (Exception ex)
     {
         var rethrow = ExceptionPolicy.HandleException("service.policy", ex);
         if (rethrow) throw;
         return null;
     }
 }
开发者ID:ytokas,项目名称:Tavisca-Training-WCF-EMS,代码行数:15,代码来源:IdentityService.cs


示例12: Create

 public DataContract.Employee Create(DataContract.Employee employee)
 {
     try
     {
         var result = _manager.Create(employee.ToDomainModel());
         if (result == null) return null;
         return result.ToDataContract();
     }
     catch (Exception ex)
     {
         Exception newEx;
         var rethrow = ExceptionPolicy.HandleException("service.policy", ex, out newEx);
         throw newEx;
     }
 }
开发者ID:ytokas,项目名称:Tavisca-Training-WCF-EMS,代码行数:15,代码来源:EmployeeManagementService.cs


示例13: AddRemark

 public DataContract.Remark AddRemark(string employeeId, DataContract.Remark remark)
 {
     try
     {
         var result = _manager.AddRemark(employeeId, remark.ToDomainModel());
         if (result == null) return null;
         return result.ToDataContract();
     }
     catch (Exception ex)
     {
         Exception newEx;
         var rethrow = ExceptionPolicy.HandleException("service.policy", ex, out newEx);
         throw newEx;
     }
 }
开发者ID:ytokas,项目名称:Tavisca-Training-WCF-EMS,代码行数:15,代码来源:EmployeeManagementService.cs


示例14: WriteCollectionToJson

		public void WriteCollectionToJson (XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, CollectionDataContract dataContract)
		{
			this.writer = xmlWriter;
			this.obj = obj;
			this.context = context;
			this.dataContract = dataContract;

			InitArgs (collectionContract.UnderlyingType);			

			// DemandMemberAccessPermission(memberAccessFlag);
			if (collectionContract.IsReadOnlyContract)
			{
				DataContract.ThrowInvalidDataContractException (collectionContract.SerializationExceptionMessage, null);
			}

			WriteCollection (collectionContract);
		}
开发者ID:psni,项目名称:mono,代码行数:17,代码来源:JsonFormatWriterGenerator_static.cs


示例15: WriteToJson

		public void WriteToJson (XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, ClassDataContract dataContract, XmlDictionaryString [] memberNames)
		{
			this.writer = xmlWriter;
			this.obj = obj;
			this.context = context;
			this.dataContract = dataContract;
			this.memberNames = memberNames;

			InitArgs (classContract.UnderlyingType);

			// DemandSerializationFormatterPermission (classContract) - irrelevant
			// DemandMemberAccessPermission (memberAccessFlag) - irrelevant

			if (classContract.IsReadOnlyContract)
			{
				DataContract.ThrowInvalidDataContractException (classContract.SerializationExceptionMessage, null);
			}

			WriteClass (classContract);
		}
开发者ID:psni,项目名称:mono,代码行数:20,代码来源:JsonFormatWriterGenerator_static.cs


示例16: PutItem

        public int PutItem(DataContract.Item Item)
        {
            // Owner
            // UriTemplate = "PutItem/{Item}",
            int itemsChanged = 0;
            Notenet.Content.Data.Repository.Item dbItem = this.content.Items.Where(i => i.ItemID == Item.ItemID).Single();
            try
            {
                ItemTranslator.Translate(dbItem, Item);
                itemsChanged = this.content.SaveChanges();
            }
            catch (OptimisticConcurrencyException e)
            {
                this.content.Refresh(RefreshMode.ClientWins, dbItem);
                itemsChanged = this.content.SaveChanges();
                // log exception after operation called by some attributes?
            }

            // this.content.PutItem();

            return itemsChanged;
        }
开发者ID:sirtristancomtedeartois,项目名称:note,代码行数:22,代码来源:Content.svc.cs


示例17: InsertKeyOperationHistories

 public void InsertKeyOperationHistories(List<KeyInfo> keys, DataContract.KeyState targetKeyState, string @operator, string message)
 {
     using (var context = GetContext())
     {
         foreach (var keyInfo in keys)
         {
             KeyOperationHistory koh = new KeyOperationHistory()
             {
                 KeyId = keyInfo.KeyId,
                 ProductKey = keyInfo.ProductKey,
                 HardwareHash = keyInfo.HardwareHash,
                 KeyStateFrom = (byte)keyInfo.KeyState,
                 KeyStateTo = (byte)targetKeyState,
                 Message = message,
                 Operator = @operator,
                 CreatedDate = DateTime.UtcNow
             };
             context.KeyOperationHistories.Add(koh);
         }
         context.SaveChanges();
     }
 }
开发者ID:barbarossia,项目名称:DIS,代码行数:22,代码来源:MiscRepository.cs


示例18: RequiresJsonTypeInfo

 private static bool RequiresJsonTypeInfo(DataContract contract)
 {
     return (contract is ClassDataContract);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:4,代码来源:XmlObjectSerializerWriteContextComplexJson.cs


示例19: WriteClrTypeInfo

 internal override bool WriteClrTypeInfo(XmlWriterDelegator xmlWriter, DataContract dataContract)
 {
     return false;
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:4,代码来源:XmlObjectSerializerWriteContextComplexJson.cs


示例20: WriteTypeInfo

        protected override bool WriteTypeInfo(XmlWriterDelegator writer, DataContract contract, DataContract declaredContract)
        {
            if (!((object.ReferenceEquals(contract.Name, declaredContract.Name) &&
                   object.ReferenceEquals(contract.Namespace, declaredContract.Namespace)) ||
                 (contract.Name.Value == declaredContract.Name.Value &&
                 contract.Namespace.Value == declaredContract.Namespace.Value)) &&
                 (contract.UnderlyingType != Globals.TypeOfObjectArray) && 
                 (_emitXsiType != EmitTypeInformation.Never))
            {
                // We always deserialize collections assigned to System.Object as object[]
                // Because of its common and JSON-specific nature, 
                //    we don't want to validate known type information for object[]

                // Don't validate known type information when emitXsiType == Never because
                // known types are not used without type information in the JSON

                if (RequiresJsonTypeInfo(contract))
                {
                    _perCallXsiTypeAlreadyEmitted = true;
                    WriteTypeInfo(writer, contract.Name.Value, contract.Namespace.Value);
                }
                else
                {
                    // check if the declared type is System.Enum and throw because
                    // __type information cannot be written for enums since it results in invalid JSON.
                    // Without __type, the resulting JSON cannot be deserialized since a number cannot be directly assigned to System.Enum.
                    if (declaredContract.UnderlyingType == typeof(Enum))
                    {
                        throw new SerializationException(SR.Format(SR.EnumTypeNotSupportedByDataContractJsonSerializer, declaredContract.UnderlyingType));
                    }
                }

                // Return true regardless of whether we actually wrote __type information
                // E.g. We don't write __type information for enums, but we still want verifyKnownType
                //      to be true for them.
                return true;
            }
            return false;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:39,代码来源:XmlObjectSerializerWriteContextComplexJson.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DataControlRowState类代码示例发布时间:2022-05-24
下一篇:
C# DataContextChangedEventArgs类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap