/// <summary> /// Creates and wraps the entity instance for a given CLR type. /// </summary> /// <param name="wrapperScope">The wrapper scope.</param> /// <param name="entityClrType">Type of the entity CLR.</param> /// <returns>Wrapper for newly created entity instance.</returns> public static WrappedEntityInstance CreateEntityInstance(this IWrapperScope wrapperScope, Type entityClrType) { ExceptionUtilities.CheckArgumentNotNull(wrapperScope, "wrapperScope"); ExceptionUtilities.CheckArgumentNotNull(entityClrType, "entityClrType"); object entityInstance = Activator.CreateInstance(entityClrType); return(wrapperScope.Wrap <WrappedEntityInstance>(entityInstance)); }
/// <summary> /// Creates a wrapped data service request /// </summary> /// <typeparam name="TElement">The wrapped element type</typeparam> /// <param name="wrapperScope">The wrapper scope</param> /// <param name="elementType">The actual element type</param> /// <param name="requestUri">The request uri</param> /// <returns>The wrapped data service request</returns> public static WrappedDataServiceRequest <TElement> CreateDataServiceRequest <TElement>(this IWrapperScope wrapperScope, Type elementType, Uri requestUri) where TElement : WrappedObject { ExceptionUtilities.CheckArgumentNotNull(wrapperScope, "wrapperScope"); ExceptionUtilities.CheckArgumentNotNull(elementType, "elementType"); var request = Activator.CreateInstance(typeof(DSClient.DataServiceRequest <>).MakeGenericType(elementType), requestUri); return(wrapperScope.Wrap <WrappedDataServiceRequest <TElement> >(request)); }
public static WrappedDataServiceCollection <TElement> CreateDataServiceCollection <TElement>(this IWrapperScope wrapperScope, Type clrType, WrappedDataServiceContext context, string entitySetName, Func <DSClient.EntityChangedParams, bool> entityChangedCallback, Func <DSClient.EntityCollectionChangedParams, bool> collectionChangedCallback) where TElement : WrappedObject { ExceptionUtilities.CheckArgumentNotNull(wrapperScope, "wrapperScope"); ExceptionUtilities.CheckArgumentNotNull(context, "context"); ExceptionUtilities.CheckArgumentNotNull(entitySetName, "entitySetName"); Type dataServiceCollectionType = typeof(DSClient.DataServiceCollection <>).MakeGenericType(clrType); ConstructorInfo constructorWithContext = dataServiceCollectionType.GetInstanceConstructor(true, new Type[] { typeof(DSClient.DataServiceContext), typeof(string), typeof(Func <DSClient.EntityChangedParams, bool>), typeof(Func <DSClient.EntityCollectionChangedParams, bool>) }); ExceptionUtilities.CheckObjectNotNull(constructorWithContext, "Could not find constructor"); var collection = constructorWithContext.Invoke(new object[] { context.Product, entitySetName, entityChangedCallback, collectionChangedCallback }); return(wrapperScope.Wrap <WrappedDataServiceCollection <TElement> >(collection)); }
/// <summary> /// Creates the data service context instance for a given type and URI and wraps it. /// </summary> /// <param name="wrapperScope">The wrapper scope.</param> /// <param name="contextType">Type of the context.</param> /// <param name="serviceUri">The service URI.</param> /// <param name="maxProtocolVersion">max protocol version that the client understands.</param> /// <returns>Wrapped object context object.</returns> public static WrappedDataServiceContext CreateDataServiceContext(this IWrapperScope wrapperScope, Type contextType, Uri serviceUri, DataServiceProtocolVersion maxProtocolVersion) { ExceptionUtilities.CheckArgumentNotNull(wrapperScope, "wrapperScope"); ExceptionUtilities.CheckArgumentNotNull(contextType, "contextType"); object dataServiceContext = null; if (maxProtocolVersion != DataServiceProtocolVersion.Unspecified) { dataServiceContext = Activator.CreateInstance(contextType, serviceUri, maxProtocolVersion.ToProductEnum()); } else { dataServiceContext = Activator.CreateInstance(contextType, serviceUri); } return(wrapperScope.Wrap <WrappedDataServiceContext>(dataServiceContext)); }
/// <summary> /// Creates the data service context instance for a given type and URI and wraps it. /// </summary> /// <param name="wrapperScope">The wrapper scope.</param> /// <param name="contextType">Type of the context.</param> /// <param name="serviceUri">The service URI.</param> /// <param name="maxProtocolVersion">max protocol version that the client understands.</param> /// <returns>Wrapped object context object.</returns> public static WrappedDataServiceContext CreateDataServiceContext(this IWrapperScope wrapperScope, Type contextType, Uri serviceUri, DataServiceProtocolVersion maxProtocolVersion) { ExceptionUtilities.CheckArgumentNotNull(wrapperScope, "wrapperScope"); ExceptionUtilities.CheckArgumentNotNull(contextType, "contextType"); object dataServiceContext = null; #if !WINDOWS_PHONE && !WIN8 if (maxProtocolVersion != DataServiceProtocolVersion.Unspecified) { dataServiceContext = Activator.CreateInstance(contextType, serviceUri, maxProtocolVersion.ToProductEnum()); } else #endif { #if WIN8 // In win8 CreateInstance fails to find container constructor taking serviceRoot and DataServiceProtocolVersion, add this to ensure that the tests that need to specify non-V3 version work around the issue ExceptionUtilities.Assert(maxProtocolVersion == DataServiceProtocolVersion.V4, "Win8 DataServiceProtocolVersion"); #endif dataServiceContext = Activator.CreateInstance(contextType, serviceUri); } return(wrapperScope.Wrap <WrappedDataServiceContext>(dataServiceContext)); }