Exemplo n.º 1
0
        public void InjectTo(object o)
        {
            ITypeBlueprint blueprint = DIBlueprintRepository.Get(o.GetType());

            ITypeElement typeElement = FindElementByType(blueprint, targetValue.GetType());

            RaiseException.WhenTrue(typeElement == null, "Blueprint '{0}' has no AutoInject field/property assignable from '{1}'!", blueprint.Type, targetValue.GetType());

            typeElement.SetValue(o, targetValue);
        }
Exemplo n.º 2
0
        public void InjectTo(object o)
        {
            ITypeBlueprint blueprint = DIBlueprintRepository.Get(o.GetType());

            ITypeElement typeElement = FindElementByName(blueprint);

            RaiseException.WhenTrue(typeElement == null, "Blueprint '{0}' has no AutoInject field/property with name '{1}'!", blueprint.Type, name);
            RaiseException.WhenFalse(targetValue == null || typeElement.ElementType.IsAssignableFrom(targetValue.GetType()), "Element '{0}' in blueprint '{1}' is not assignable from {2}", name, blueprint.Type, targetValue.GetType());

            typeElement.SetValue(o, targetValue);
        }
Exemplo n.º 3
0
        public static object Decode(PacketDataset dataset, Type t)
        {
            object         result    = Activator.CreateInstance(t);
            ITypeBlueprint blueprint = DecodeBlueprintRepository.Get(t);

            foreach (ITypeElement typeElement in blueprint.AllElements)
            {
                Packet p = dataset[typeElement.Name];

                object decodedValue = Decoder.Decode(p, typeElement.ElementType);

                typeElement.SetValue(result, decodedValue);
            }

            return(result);
        }
Exemplo n.º 4
0
 private ITypeElement FindElementByType(ITypeBlueprint blueprint, Type valueType)
 {
     return(blueprint.AllElements.FirstOrDefault(te => te.ElementType.IsAssignableFrom(valueType)));
 }
Exemplo n.º 5
0
 private ITypeElement FindElementByName(ITypeBlueprint blueprint)
 {
     return(blueprint.AllElements.FirstOrDefault(te => te.Name == name));
 }