public void can_assign_property_on_alien_type_instance() { var frodoType = _ts.FromClr <Frodo>(); var property = frodoType.FindPropertyByPath("IsEvil"); property.ShouldNotBeNull(); var saruman = new Saruman(); property.TrySetValue(saruman, false).ShouldBeTrue(); saruman.IsEvil.ShouldBeFalse(); }
public static CodecRegistration FromResourceType( Type resourceType, Type codecType, ITypeSystem typeSystem, MediaType mediaType, IEnumerable <string> extensions, object codecConfiguration, bool isSystem) { bool isStrict = false; if (IsStrictRegistration(resourceType)) { resourceType = GetStrictType(resourceType); isStrict = true; } return(new CodecRegistration(codecType, typeSystem.FromClr(resourceType), isStrict, mediaType, extensions, codecConfiguration, isSystem)); }
protected void WhenFindingCodecsFor <TResourceType>(params string[] contentTypes) { ThenTheResult = Codecs.FindMediaTypeWriter(typeSystem.FromClr(typeof(TResourceType)), MediaType.Parse(string.Join(",", contentTypes))) .ToList(); }
public WebFormsDefaultHandler(ICommunicationContext context, ITypeSystem typeSystem, IDependencyResolver resolver) { _context = context; _typeSystem = typeSystem; _resolver = resolver; _pageType = typeSystem.FromClr<Page>(); }
public WebFormsDefaultHandler(ICommunicationContext context, ITypeSystem typeSystem, IDependencyResolver resolver) { _context = context; _typeSystem = typeSystem; _resolver = resolver; _pageType = typeSystem.FromClr <Page>(); }
public BindingResult ConvertValues(IMultipartHttpEntity entity, Type targetType) { object destination; var sourceMediaType = entity.ContentType ?? MediaType.TextPlain; var type = _typeSystem.FromClr(targetType); var mediaTypeReaderReg = _codecs.FindMediaTypeReader(sourceMediaType, new[] { type }, null); if (mediaTypeReaderReg != null) { var mediaTypeReader = (ICodec)_container.Resolve(mediaTypeReaderReg.CodecRegistration.CodecType); if (mediaTypeReader is IMediaTypeReader) { return(BindingResult.Success(((IMediaTypeReader)mediaTypeReader).ReadFrom(entity, type, targetType.Name))); } var binder = BinderLocator.GetBinder(type); if (mediaTypeReader.TryAssignKeyValues(entity, binder)) { return(binder.BuildObject()); } } // if no media type reader was found, try to parse to a string and convert from that. var stringType = _typeSystem.FromClr <string>(); mediaTypeReaderReg = _codecs.FindMediaTypeReader(sourceMediaType, new[] { stringType }, null); if (entity.ContentType == null) { entity.ContentType = MediaType.TextPlain; } // defaults the entity to UTF-8 if none is specified, to account for browsers favouring using the charset of the origin page rather than the standard. Cause RFCs are too difficult to follow uh... if (entity.ContentType.CharSet == null) { entity.ContentType.CharSet = "UTF-8"; } var plainTextReader = (IMediaTypeReader)_container.Resolve(mediaTypeReaderReg.CodecRegistration.CodecType); var targetString = plainTextReader.ReadFrom(entity, stringType, targetType.Name); destination = targetType.CreateInstanceFrom(targetString); return(BindingResult.Success(destination)); }
public void a_clr_type_is_changed_to_an_IType() { given_resource_registration(); when_executing_the_handler(); MetaModel.ResourceRegistrations[0].ResourceKey.ShouldBeAssignableTo <IType>() .CompareTo(TypeSystem.FromClr(typeof(Customer))).ShouldBe(0); }
public static IMethod From(this ITypeSystem typeSystem, MethodInfo method) { return(typeSystem .FromClr(method.DeclaringType) .GetMethods() .First(m => m.Name == method.Name && m.InputMembers.Select(i => i.StaticType) .SequenceEqual( method.GetParameters().Select(p => p.ParameterType)))); }
public override void PreProcess(IMetaModelRepository repository) { foreach (var resource in repository.ResourceRegistrations) { if (resource.ResourceKey is Type) { resource.ResourceKey = _typeSystem.FromClr((Type)resource.ResourceKey); } } }
public static IEnumerable <CodecRegistration> FromCodecType(Type codecType, ITypeSystem typeSystem) { var resourceTypeAttributes = codecType.GetCustomAttributes(typeof(SupportedTypeAttribute), true).Cast <SupportedTypeAttribute>(); var mediaTypeAttributes = codecType.GetCustomAttributes(typeof(MediaTypeAttribute), true).Cast <MediaTypeAttribute>(); return(from resourceTypeAttribute in resourceTypeAttributes from mediaType in mediaTypeAttributes let isStrictRegistration = IsStrictRegistration(resourceTypeAttribute.Type) let resourceType = isStrictRegistration ? GetStrictType(resourceTypeAttribute.Type) : resourceTypeAttribute.Type select new CodecRegistration( codecType, typeSystem.FromClr(resourceType), isStrictRegistration, mediaType.MediaType, mediaType.Extensions, null, true)); }
public OperationResult Get() { var resourceKey = _context.PipelineData.ResourceKey as IType; if (resourceKey == null && _context.PipelineData.ResourceKey is string) { try { resourceKey = _typeSystem.FromClr(BuildManager.GetCompiledType((string)_context.PipelineData.ResourceKey)); } catch { } } if (resourceKey != null && resourceKey.CompareTo(_pageType) >= 0) { return(new OperationResult.OK { ResponseResource = resourceKey.CreateInstance(_resolver) }); } return(new OperationResult.NotFound()); }
public void the_type_cannot_be_null() { Executing(() => TypeSystem.FromClr(null)) .ShouldThrow <ArgumentNullException>(); }
public IHandlerForResourceWithUriDefinition HandledBy <T>() { return(HandledBy(_typeSystem.FromClr(typeof(T)))); }
protected void given_builder() { builder = TypeSystem.FromClr <T>().CreateBuilder(); }
protected void given_uri_mapping(string uri, Type type, CultureInfo cultureInfo, string alias) { Resolver.Add(new UriRegistration(uri, TypeSystem.FromClr(type), alias, cultureInfo)); }
public static IType FromClr <T>(this ITypeSystem typeSystem) { return(typeSystem.FromClr(typeof(T))); }
/// <summary> /// Gets the binder used to build the changeset. /// </summary> /// <param name="typeSystem"></param> /// <param name="member"></param> /// <returns></returns> public static IObjectBinder GetBinder(ITypeSystem typeSystem, IMember member) { var innerMember = typeSystem.FromClr <T>(); return(new ChangeSetBinder <T>(innerMember.Type, member.Name)); }
protected IType TypeForClr <TTarget>() { return(_typeSystem.FromClr(typeof(TTarget))); }
protected void WhenFindingCodec(string contentType, params Type[] resourcetypes) { ThenTheResult = null; ThenTheResultScoring = null; ThenTheResultScoring = Codecs.FindMediaTypeReader(new MediaType(contentType), resourcetypes.Select(x => (IMember)TypeSystem.FromClr(x)), null); if (ThenTheResultScoring == null) { return; } ThenTheResult = ThenTheResultScoring.CodecRegistration; }
// ITypeSystem _typeSystem = new public void given_builder_for <T1>() { TypeBuilder = _ts.FromClr(typeof(T1)).CreateBuilder(); }
public void given_uri_registration <T>(string uri, string uriName = null) { UriResolver.Add(new UriRegistration(uri, TypeSystem.FromClr(typeof(T)), uriName, CultureInfo.CurrentCulture)); }