public IEnumerator <IDuckKeyValue <K, T> > GetEnumerator() { object[] ducktypek = typeof(K).GetCustomAttributes(typeof(DuckTypeAttribute), false); object[] ducktypev = typeof(T).GetCustomAttributes(typeof(DuckTypeAttribute), false); bool isKeyDuck = (ducktypek.Length > 0); bool isValDuck = (ducktypev.Length > 0); while (_en.MoveNext()) { K k; T t; if (isKeyDuck) { k = DuckTyping.Instance.ImplementDuckType <K>(_en.Key); } else { ConvertToClr.ConversionStrictness str; k = ConvertToClr.TryObjectToType <K>(_en.Key, out str); if (str == ConvertToClr.ConversionStrictness.Failed) { throw new InvalidCastException(); } } if (isValDuck) { t = DuckTyping.Instance.ImplementDuckType <T>(_en.Value); } else { ConvertToClr.ConversionStrictness str; t = ConvertToClr.TryObjectToType <T>(_en.Value, out str); if (str == ConvertToClr.ConversionStrictness.Failed) { throw new InvalidCastException(); } } yield return(new DuckKeyValue <K, T>(k, t)); } }
public IEnumerator <T> GetEnumerator() { object[] ducktype = typeof(T).GetCustomAttributes(typeof(DuckTypeAttribute), false); bool isDuck = (ducktype.Length > 0); while (_en.MoveNext()) { if (isDuck) { yield return(DuckTyping.Instance.ImplementDuckType <T>(_en.Value)); } else { ConvertToClr.ConversionStrictness str; T ret = ConvertToClr.TryObjectToType <T>(_en.Value, out str); if (str == ConvertToClr.ConversionStrictness.Failed) { throw new InvalidCastException(); } yield return(ret); } } }